* identify concepts -- such as names, addresses, classes, etc. We do not
* require too much, just that the identifiers are serializable (and this
* transferable).
+ *
+ * Implementations are expected to implement hashCode() and equals() methods
+ * in a way, which ensures that objects before and after serialization are
+ * considered equal.
+ *
+ * Implementations are advised to use the Externalizable Proxy pattern to
+ * allow future evolution of their serialization format.
*/
public interface Identifier extends Serializable, Immutable {
+ @Override
+ boolean equals(Object o);
+
+ @Override
+ int hashCode();
+ @Override
+ String toString();
}
--- /dev/null
+/*
+ * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.yangtools.util;
+
+import com.google.common.annotations.Beta;
+import com.google.common.base.MoreObjects;
+import com.google.common.base.Preconditions;
+import org.opendaylight.yangtools.concepts.Identifier;
+
+/**
+ * Utility {@link Identifier} backed by a {@link String}.
+ */
+@Beta
+public final class StringIdentifier implements Identifier, Comparable<StringIdentifier> {
+ private static final long serialVersionUID = 1L;
+ private final String string;
+
+ public StringIdentifier(final String string) {
+ this.string = Preconditions.checkNotNull(string);
+ }
+
+ public String getString() {
+ return string;
+ }
+
+ @Override
+ public int hashCode() {
+ return string.hashCode();
+ }
+
+ @Override
+ public boolean equals(final Object o) {
+ return this == o || (o instanceof StringIdentifier && string.equals(((StringIdentifier)o).string));
+ }
+
+ @Override
+ public String toString() {
+ return MoreObjects.toStringHelper(StringIdentifier.class).add("string", string).toString();
+ }
+
+ @Override
+ public int compareTo(final StringIdentifier o) {
+ return string.compareTo(o.string);
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.yangtools.util;
+
+import com.google.common.annotations.Beta;
+import com.google.common.base.MoreObjects;
+import com.google.common.base.Preconditions;
+import java.util.UUID;
+import org.opendaylight.yangtools.concepts.Identifier;
+
+/**
+ * Utility {@link Identifier} backed by a {@link UUID}.
+ */
+@Beta
+public final class UUIDIdentifier implements Identifier, Comparable<UUIDIdentifier> {
+ private static final long serialVersionUID = 1L;
+ private final UUID uuid;
+
+ public UUIDIdentifier(final UUID uuid) {
+ this.uuid = Preconditions.checkNotNull(uuid);
+ }
+
+ public UUID getUuid() {
+ return uuid;
+ }
+
+ @Override
+ public int hashCode() {
+ return uuid.hashCode();
+ }
+
+ @Override
+ public boolean equals(final Object o) {
+ return this == o || (o instanceof UUIDIdentifier && uuid.equals(((UUIDIdentifier)o).uuid));
+ }
+
+ @Override
+ public String toString() {
+ return MoreObjects.toStringHelper(UUIDIdentifier.class).add("uuid", uuid).toString();
+ }
+
+ @Override
+ public int compareTo(final UUIDIdentifier o) {
+ return uuid.compareTo(o.uuid);
+ }
+}