Expose uuid/instant from CommitInfo 61/109761/2
authorRobert Varga <robert.varga@pantheon.tech>
Sat, 13 Jan 2024 18:35:55 +0000 (19:35 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Sat, 13 Jan 2024 20:05:23 +0000 (21:05 +0100)
A particular commit can have an UUID or an Instant when it occurred, or
both. Also this information is something we would like to include in
Serializable contexts -- and therefore we promote CommitInfo to a
non-Beta Serializable.

JIRA: YANGTOOLS-1559
Change-Id: I1a2eb7f41484c4088e6ce310b3ab78a26022ad40
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
common/mdsal-common-api/src/main/java/org/opendaylight/mdsal/common/api/CI.java
common/mdsal-common-api/src/main/java/org/opendaylight/mdsal/common/api/CommitInfo.java

index 7736b9e356729acfc3a1e36f7a1055cfd218c711..801235d60a41078461979a480b7f8c6db0a4a9c5 100644 (file)
@@ -12,7 +12,6 @@ import com.google.common.base.MoreObjects;
 import com.google.common.util.concurrent.FluentFuture;
 import com.google.common.util.concurrent.Futures;
 import java.io.ObjectStreamException;
-import java.io.Serializable;
 import java.time.Instant;
 import java.util.UUID;
 import org.eclipse.jdt.annotation.NonNull;
@@ -20,7 +19,7 @@ import org.eclipse.jdt.annotation.NonNull;
 /**
  * Default {@link CommitInfo} implementation.
  */
-record CI(UUID uuid, Instant instant) implements CommitInfo, Serializable {
+record CI(UUID uuid, Instant instant) implements CommitInfo {
     @java.io.Serial
     private static final long serialVersionUID = 0L;
 
index 08a409c4063c0c03b169f70fe838ce23c0acb74d..06c45f2b8e97cbbc76c57a22534f5716cbe75f2c 100644 (file)
@@ -7,18 +7,36 @@
  */
 package org.opendaylight.mdsal.common.api;
 
-import com.google.common.annotations.Beta;
+import static java.util.Objects.requireNonNull;
+
 import com.google.common.util.concurrent.FluentFuture;
+import java.io.Serializable;
+import java.time.Instant;
+import java.util.UUID;
 import org.eclipse.jdt.annotation.NonNullByDefault;
+import org.eclipse.jdt.annotation.Nullable;
 
 /**
  * Base interface for tagging information about a successful commit. This can include various ways of identifying
  * the resulting changeset, timing information or any other piece of data about the commit itself the implementation
  * deems interesting to the client.
  */
-@Beta
 @NonNullByDefault
-public interface CommitInfo {
+public interface CommitInfo extends Serializable {
+    /**
+     * The {@link UUID} of the commit.
+     *
+     * @return the {@link UUID} of this commit
+     */
+    @Nullable UUID uuid();
+
+    /**
+     * The {@link Instant} when the commit occurred.
+     *
+     * @return the {@link Instant} when the commit occurred
+     */
+    @Nullable Instant instant();
+
     /**
      * Return an empty {@link CommitInfo}.
      *
@@ -36,4 +54,49 @@ public interface CommitInfo {
     static FluentFuture<CommitInfo> emptyFluentFuture() {
         return CI.EMPTY_FUTURE;
     }
+
+    /**
+     * Return a {@link CommitInfo} reporting specified {@link UUID}.
+     *
+     * @param uuid UUID to report
+     * @return a {@link CommitInfo} reporting specified {@link UUID}
+     * @throws NullPointerException if {@code uuid} is {@code null}
+     */
+    static CommitInfo of(final UUID uuid) {
+        return new CI(requireNonNull(uuid), null);
+    }
+
+    /**
+     * Return a {@link CommitInfo} reporting specified {@link Instant}.
+     *
+     * @param instant Instant to report
+     * @return a {@link CommitInfo} reporting specified {@link Instant}
+     * @throws NullPointerException if {@code instant} is {@code null}
+     */
+    static CommitInfo of(final Instant instant) {
+        return new CI(null, requireNonNull(instant));
+    }
+
+    /**
+     * Return a {@link CommitInfo} reporting specified {@link UUID} and {@link Instant}.
+     *
+     * @param uuid UUID to report
+     * @param instant Instant to report
+     * @return a {@link CommitInfo} reporting specified {@link UUID} and {@link Instant}
+     * @throws NullPointerException if any argument is {@code null}
+     */
+    static CommitInfo of(final UUID uuid, final Instant instant) {
+        return new CI(requireNonNull(uuid), requireNonNull(instant));
+    }
+
+    /**
+     * Return a {@link CommitInfo} reporting optional {@link UUID} and  {@link Instant}.
+     *
+     * @param uuid UUID to report
+     * @param instant Instant to report
+     * @return a {@link CommitInfo} reporting optional {@link UUID} and  {@link Instant}
+     */
+    static CommitInfo ofNullable(final @Nullable UUID uuid, final @Nullable Instant instant) {
+        return CI.of(uuid, instant);
+    }
 }