Mark Project.NameKey as immutable and thread-safe

This class can't be an AutoValue because it gets
subclassed. It's trivial enough so that we can just
mark it as immutable and thread-safe.

Change-Id: I519243838b5b4700e6aa2f28916a4b76b07382c4
This commit is contained in:
Patrick Hiesel
2020-06-22 15:29:24 +02:00
parent 52633ac237
commit 7f5182251e
3 changed files with 22 additions and 6 deletions

View File

@@ -16,6 +16,7 @@ package com.google.gerrit.entities;
import static java.util.Objects.requireNonNull;
import com.google.errorprone.annotations.Immutable;
import com.google.gerrit.extensions.client.InheritableBoolean;
import com.google.gerrit.extensions.client.ProjectState;
import com.google.gerrit.extensions.client.SubmitType;
@@ -47,7 +48,10 @@ public final class Project {
* <p>Because of this unusual subclassing behavior, this class is not an {@code @AutoValue},
* unlike other key types in this package. However, this is strictly an implementation detail; its
* interface and semantics are otherwise analogous to the {@code @AutoValue} types.
*
* <p>This class is immutable and thread safe.
*/
@Immutable
public static class NameKey implements Serializable, Comparable<NameKey> {
private static final long serialVersionUID = 1L;
@@ -72,25 +76,25 @@ public final class Project {
@Override
public final int hashCode() {
return get().hashCode();
return name.hashCode();
}
@Override
public final boolean equals(Object b) {
if (b instanceof NameKey) {
return get().equals(((NameKey) b).get());
return name.equals(((NameKey) b).get());
}
return false;
}
@Override
public final int compareTo(NameKey o) {
return get().compareTo(o.get());
return name.compareTo(o.get());
}
@Override
public final String toString() {
return KeyUtil.encode(get());
return KeyUtil.encode(name);
}
}

View File

@@ -14,9 +14,15 @@
package com.google.gerrit.server.config;
import com.google.errorprone.annotations.Immutable;
import com.google.gerrit.entities.Project;
/** Special name of the project that all projects derive from. */
/**
* Special name of the project that all projects derive from.
*
* <p>This class is immutable and thread safe.
*/
@Immutable
public class AllProjectsName extends Project.NameKey {
private static final long serialVersionUID = 1L;

View File

@@ -14,9 +14,15 @@
package com.google.gerrit.server.config;
import com.google.errorprone.annotations.Immutable;
import com.google.gerrit.entities.Project;
/** Special name of the project in which meta data for all users is stored. */
/**
* Special name of the project in which meta data for all users is stored.
*
* <p>This class is immutable and thread safe.
*/
@Immutable
public class AllUsersName extends Project.NameKey {
private static final long serialVersionUID = 1L;