.map(entry -> Pair.of(entry.getKey(), entry.getKey().equals(key) ? replacement : entry.getValue())) .filter(pair -> pair.getValue() != null && !pair.getValue().isEmpty()) .collect(Guavate.toImmutableMap(Pair::getKey, Pair::getValue))); } else { return Optional.ofNullable(replacement) .filter(rights -> !rights.isEmpty()) .map(replacementValue -> new MailboxACL( ImmutableMap.<EntryKey, Rfc4314Rights>builder()
/** * Performs the set theoretic operation of relative complement of toRemove * {@link MailboxACL} in this {@link MailboxACL}. * * A schematic example: "user1:lr;user2:lrwt".except("user1:w;user2:t") * returns "user1:lr;user2:lrw". * * Implementations must return a new unmodifiable instance of * {@link MailboxACL}. However, implementations may decide to return this or * toRemove parameter value in case the result would be equal to the * respective one of those. * * Implementations must ensure that the result does not contain entries with * empty rigths. E.g. "user1:lr;user2:lrwt".except("user1:lr") should return * "user2:lrwt" rather than "user1:;user2:lrwt" */ public MailboxACL except(MailboxACL other) throws UnsupportedRightException { return new MailboxACL(entries.entrySet() .stream() .map(entry -> Pair.of( entry.getKey(), except(entry.getValue(), other.getEntries().get(entry.getKey())))) .filter(pair -> !pair.getValue().isEmpty()) .collect(Guavate.toImmutableMap(Map.Entry::getKey, Map.Entry::getValue))); }