More cds-access-api cleanup
[controller.git] / opendaylight / md-sal / cds-access-api / src / main / java / org / opendaylight / controller / cluster / access / concepts / ClientIdentifier.java
index e97626b7ebcb607d1780795d1c70fd4da41cc411..d62b59384562e85b9bc9bdbb8db5b1976aae15e6 100644 (file)
@@ -9,7 +9,6 @@ package org.opendaylight.controller.cluster.access.concepts;
 
 import static java.util.Objects.requireNonNull;
 
-import com.google.common.annotations.Beta;
 import com.google.common.base.MoreObjects;
 import java.io.DataInput;
 import java.io.DataOutput;
@@ -17,8 +16,12 @@ import java.io.Externalizable;
 import java.io.IOException;
 import java.io.ObjectInput;
 import java.io.ObjectOutput;
+import java.io.Serial;
+import org.eclipse.jdt.annotation.NonNull;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.cds.types.rev191024.ClientGeneration;
 import org.opendaylight.yangtools.concepts.WritableIdentifier;
 import org.opendaylight.yangtools.concepts.WritableObjects;
+import org.opendaylight.yangtools.yang.common.Uint64;
 
 /**
  * A cluster-wide unique identifier of a frontend instance. This identifier discerns between individual incarnations
@@ -26,10 +29,11 @@ import org.opendaylight.yangtools.concepts.WritableObjects;
  *
  * @author Robert Varga
  */
-@Beta
 public final class ClientIdentifier implements WritableIdentifier {
     private static final class Proxy implements Externalizable {
+        @Serial
         private static final long serialVersionUID = 1L;
+
         private FrontendIdentifier frontendId;
         private long generation;
 
@@ -57,13 +61,16 @@ public final class ClientIdentifier implements WritableIdentifier {
             generation = WritableObjects.readLong(in);
         }
 
+        @Serial
         private Object readResolve() {
             return new ClientIdentifier(frontendId, generation);
         }
     }
 
+    @Serial
     private static final long serialVersionUID = 1L;
-    private final FrontendIdentifier frontendId;
+
+    private final @NonNull FrontendIdentifier frontendId;
     private final long generation;
 
     ClientIdentifier(final FrontendIdentifier frontendId, final long generation) {
@@ -71,12 +78,12 @@ public final class ClientIdentifier implements WritableIdentifier {
         this.generation = generation;
     }
 
-    public static ClientIdentifier create(final FrontendIdentifier frontendId,
+    public static @NonNull ClientIdentifier create(final FrontendIdentifier frontendId,
             final long generation) {
         return new ClientIdentifier(frontendId, generation);
     }
 
-    public static ClientIdentifier readFrom(final DataInput in) throws IOException {
+    public static @NonNull ClientIdentifier readFrom(final DataInput in) throws IOException {
         final FrontendIdentifier frontendId = FrontendIdentifier.readFrom(in);
         return new ClientIdentifier(frontendId, WritableObjects.readLong(in));
     }
@@ -87,7 +94,7 @@ public final class ClientIdentifier implements WritableIdentifier {
         WritableObjects.writeLong(out, generation);
     }
 
-    public FrontendIdentifier getFrontendId() {
+    public @NonNull FrontendIdentifier getFrontendId() {
         return frontendId;
     }
 
@@ -95,6 +102,10 @@ public final class ClientIdentifier implements WritableIdentifier {
         return generation;
     }
 
+    public @NonNull ClientGeneration getYangGeneration() {
+        return new ClientGeneration(Uint64.fromLongBits(generation));
+    }
+
     @Override
     public int hashCode() {
         return frontendId.hashCode() * 31 + Long.hashCode(generation);
@@ -102,23 +113,19 @@ public final class ClientIdentifier implements WritableIdentifier {
 
     @Override
     public boolean equals(final Object obj) {
-        if (this == obj) {
-            return true;
-        }
-        if (!(obj instanceof ClientIdentifier)) {
-            return false;
-        }
-
-        final ClientIdentifier other = (ClientIdentifier) obj;
-        return generation == other.generation && frontendId.equals(other.frontendId);
+        return this == obj || obj instanceof ClientIdentifier other && generation == other.generation
+            && frontendId.equals(other.frontendId);
     }
 
     @Override
     public String toString() {
-        return MoreObjects.toStringHelper(ClientIdentifier.class).add("frontend", frontendId)
-                .add("generation", Long.toUnsignedString(generation)).toString();
+        return MoreObjects.toStringHelper(ClientIdentifier.class)
+            .add("frontend", frontendId)
+            .add("generation", Long.toUnsignedString(generation))
+            .toString();
     }
 
+    @Serial
     private Object writeReplace() {
         return new Proxy(frontendId, generation);
     }