Line data Source code
1 : // Copyright (C) 2012 The Android Open Source Project 2 : // 3 : // Licensed under the Apache License, Version 2.0 (the "License"); 4 : // you may not use this file except in compliance with the License. 5 : // You may obtain a copy of the License at 6 : // 7 : // http://www.apache.org/licenses/LICENSE-2.0 8 : // 9 : // Unless required by applicable law or agreed to in writing, software 10 : // distributed under the License is distributed on an "AS IS" BASIS, 11 : // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 : // See the License for the specific language governing permissions and 13 : // limitations under the License. 14 : 15 : package com.google.gerrit.server.account; 16 : 17 : import com.google.common.collect.ImmutableSet; 18 : import com.google.common.collect.Sets; 19 : import com.google.gerrit.entities.AccountGroup; 20 : import java.util.Set; 21 : 22 : /** GroupMembership over an explicit list. */ 23 : public class ListGroupMembership implements GroupMembership { 24 : private final Set<AccountGroup.UUID> groups; 25 : 26 152 : public ListGroupMembership(Iterable<AccountGroup.UUID> groupIds) { 27 152 : this.groups = ImmutableSet.copyOf(groupIds); 28 152 : } 29 : 30 : @Override 31 : public boolean contains(AccountGroup.UUID groupId) { 32 148 : return groups.contains(groupId); 33 : } 34 : 35 : @Override 36 : public boolean containsAnyOf(Iterable<AccountGroup.UUID> groupIds) { 37 25 : for (AccountGroup.UUID groupId : groupIds) { 38 23 : if (contains(groupId)) { 39 2 : return true; 40 : } 41 22 : } 42 24 : return false; 43 : } 44 : 45 : @Override 46 : public Set<AccountGroup.UUID> intersection(Iterable<AccountGroup.UUID> groupIds) { 47 1 : return Sets.intersection(ImmutableSet.copyOf(groupIds), groups); 48 : } 49 : 50 : @Override 51 : public Set<AccountGroup.UUID> getKnownGroups() { 52 27 : return Sets.newHashSet(groups); 53 : } 54 : }