*/
package org.opendaylight.yangtools.util;
+import static java.util.Objects.requireNonNull;
+
import com.google.common.base.MoreObjects;
-import com.google.common.base.Preconditions;
+import org.eclipse.jdt.annotation.NonNull;
import org.opendaylight.yangtools.concepts.Identifier;
/**
* An abstract {@link Identifier} backed by an immutable object. Subclasses have no control over {@link #hashCode()}
* and {@link #equals(Object)}, hence they should not add any fields.
*
- * @author Robert Varga
- *
* @param <T> Object type
*/
public abstract class AbstractIdentifier<T> implements Identifier {
+ @java.io.Serial
private static final long serialVersionUID = 1L;
- private final T value;
+ private final @NonNull T value;
- public AbstractIdentifier(final T value) {
- this.value = Preconditions.checkNotNull(value);
+ public AbstractIdentifier(final @NonNull T value) {
+ this.value = requireNonNull(value);
}
- public final T getValue() {
+ protected final @NonNull T getValue() {
return value;
}
}
@Override
- public final boolean equals(final Object o) {
- if (this == o) {
+ public final boolean equals(final Object obj) {
+ if (this == obj) {
return true;
}
- if (o == null) {
- return false;
- }
-
- return getClass().equals(o.getClass()) && value.equals(((AbstractIdentifier<?>)o).value);
+ return obj != null && getClass().equals(obj.getClass()) && value.equals(((AbstractIdentifier<?>)obj).value);
}
@Override
- public final String toString() {
+ public final @NonNull String toString() {
return MoreObjects.toStringHelper(this).add("value", value).toString();
}
}