Expose uuid/instant from CommitInfo
[mdsal.git] / common / mdsal-common-api / src / main / java / org / opendaylight / mdsal / common / api / CommitInfo.java
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);
+    }
 }