diff options
Diffstat (limited to 'gerrit-common/src/main/java/com/google/gerrit/common/data/GroupReference.java')
-rw-r--r-- | gerrit-common/src/main/java/com/google/gerrit/common/data/GroupReference.java | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/gerrit-common/src/main/java/com/google/gerrit/common/data/GroupReference.java b/gerrit-common/src/main/java/com/google/gerrit/common/data/GroupReference.java new file mode 100644 index 0000000000..f05d1b9007 --- /dev/null +++ b/gerrit-common/src/main/java/com/google/gerrit/common/data/GroupReference.java @@ -0,0 +1,76 @@ +// Copyright (C) 2010 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.common.data; + +import com.google.gerrit.reviewdb.client.AccountGroup; + +/** Describes a group within a projects {@link AccessSection}s. */ +public class GroupReference implements Comparable<GroupReference> { + /** @return a new reference to the given group description. */ + public static GroupReference forGroup(AccountGroup group) { + return new GroupReference(group.getGroupUUID(), group.getName()); + } + + protected String uuid; + protected String name; + + protected GroupReference() { + } + + public GroupReference(AccountGroup.UUID uuid, String name) { + setUUID(uuid); + setName(name); + } + + public AccountGroup.UUID getUUID() { + return uuid != null ? new AccountGroup.UUID(uuid) : null; + } + + public void setUUID(AccountGroup.UUID newUUID) { + uuid = newUUID != null ? newUUID.get() : null; + } + + public String getName() { + return name; + } + + public void setName(String newName) { + this.name = newName; + } + + @Override + public int compareTo(GroupReference o) { + return uuid(this).compareTo(uuid(o)); + } + + private static String uuid(GroupReference a) { + return a.getUUID() != null ? a.getUUID().get() : "?"; + } + + @Override + public int hashCode() { + return uuid(this).hashCode(); + } + + @Override + public boolean equals(Object o) { + return o instanceof GroupReference && compareTo((GroupReference) o) == 0; + } + + @Override + public String toString() { + return "Group[" + getName() + " / " + getUUID() + "]"; + } +} |