summaryrefslogtreecommitdiffstats
path: root/java/com/google/gerrit/server/account/GroupMembership.java
blob: cc73222f4b4a51221df1283ebea0b80d9248baaa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// Copyright (C) 2012 The Android Open Source Project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package com.google.gerrit.server.account;

import com.google.gerrit.reviewdb.client.AccountGroup;
import java.util.Collections;
import java.util.Set;

/**
 * Represents the set of groups that a single user is part of.
 *
 * <p>Different accounts systems (eg. LDAP, gerrit groups) provide concrete implementations.
 */
public interface GroupMembership {
  GroupMembership EMPTY = new ListGroupMembership(Collections.<AccountGroup.UUID>emptySet());

  /**
   * Returns {@code true} when the user this object was created for is a member of the specified
   * group.
   */
  boolean contains(AccountGroup.UUID groupId);

  /**
   * Returns {@code true} when the user this object was created for is a member of any of the
   * specified group.
   */
  boolean containsAnyOf(Iterable<AccountGroup.UUID> groupIds);

  /**
   * Returns a set containing an input member of {@code contains(id)} is true.
   *
   * <p>This is batch form of contains that returns specific group information. Implementors may
   * implement the method as:
   *
   * <pre>
   * Set&lt;AccountGroup.UUID&gt; r = new HashSet&lt;&gt;();
   * for (AccountGroup.UUID id : groupIds)
   *   if (contains(id)) r.add(id);
   * </pre>
   */
  Set<AccountGroup.UUID> intersection(Iterable<AccountGroup.UUID> groupIds);

  /**
   * Returns the set of groups that can be determined by the implementation. This may not return all
   * groups the {@link #contains(AccountGroup.UUID)} would return {@code true} for, but will at
   * least contain all top level groups. This restriction stems from the API of some group systems,
   * which make it expensive to enumerate the members of a group.
   */
  Set<AccountGroup.UUID> getKnownGroups();
}