MAILBOX-307 Extract big lambdas in MailboxACL
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/c2a671c9 Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/c2a671c9 Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/c2a671c9 Branch: refs/heads/master Commit: c2a671c9b55eb51d54a0389ab0d9e2541b70fd5b Parents: 06b06b6 Author: benwa <btell...@linagora.com> Authored: Wed Sep 27 16:58:20 2017 +0700 Committer: Matthieu Baechler <matth...@apache.org> Committed: Fri Sep 29 09:20:40 2017 +0200 ---------------------------------------------------------------------- .../apache/james/mailbox/model/MailboxACL.java | 29 ++++++++++++-------- 1 file changed, 17 insertions(+), 12 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/james-project/blob/c2a671c9/mailbox/api/src/main/java/org/apache/james/mailbox/model/MailboxACL.java ---------------------------------------------------------------------- diff --git a/mailbox/api/src/main/java/org/apache/james/mailbox/model/MailboxACL.java b/mailbox/api/src/main/java/org/apache/james/mailbox/model/MailboxACL.java index f93a5ef..b4c9d2e 100644 --- a/mailbox/api/src/main/java/org/apache/james/mailbox/model/MailboxACL.java +++ b/mailbox/api/src/main/java/org/apache/james/mailbox/model/MailboxACL.java @@ -685,14 +685,19 @@ public class MailboxACL { public MailboxACL except(MailboxACL other) throws UnsupportedRightException { return new MailboxACL(entries.entrySet() .stream() - .map(entry -> Pair.of(entry.getKey(), - Optional.ofNullable(other.getEntries().get(entry.getKey())) - .map(Throwing.function(exceptValue -> entry.getValue().except(exceptValue))) - .orElse(entry.getValue()))) + .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))); } + private Rfc4314Rights except(Rfc4314Rights thisRight, Rfc4314Rights exceptRights) { + return Optional.ofNullable(exceptRights) + .map(Throwing.function(thisRight::except)) + .orElse(thisRight); + } + public MailboxACL except(EntryKey key, Rfc4314Rights mailboxACLRights) throws UnsupportedRightException { return except(new MailboxACL(new Entry(key, mailboxACLRights))); } @@ -776,15 +781,15 @@ public class MailboxACL { .asMap() .entrySet() .stream() - .map(entry -> Pair.of(entry.getKey(), - entry.getValue() - .stream() - .reduce( - new Rfc4314Rights(), - Throwing.binaryOperator(Rfc4314Rights::union)))) - .collect(Guavate.toImmutableMap(Pair::getKey, Pair::getValue))); + .collect(Guavate.toImmutableMap(Map.Entry::getKey, e -> union(e.getValue())))); + } + + private Rfc4314Rights union(Collection<Rfc4314Rights> rights) { + return rights.stream() + .reduce( + new Rfc4314Rights(), + Throwing.binaryOperator(Rfc4314Rights::union)); } - public MailboxACL union(EntryKey key, Rfc4314Rights mailboxACLRights) throws UnsupportedRightException { return union(new MailboxACL(new Entry(key, mailboxACLRights))); --------------------------------------------------------------------- To unsubscribe, e-mail: server-dev-unsubscr...@james.apache.org For additional commands, e-mail: server-dev-h...@james.apache.org