Add compatibility functions to AtomicValue/Topic

Change-Id: I4a597cfa3effe0a62714ab12440a2fc41ac58aa9
diff --git a/core/api/src/main/java/org/onosproject/store/service/AtomicValueOptions.java b/core/api/src/main/java/org/onosproject/store/service/AtomicValueOptions.java
index b00a7af..b42e5f3 100644
--- a/core/api/src/main/java/org/onosproject/store/service/AtomicValueOptions.java
+++ b/core/api/src/main/java/org/onosproject/store/service/AtomicValueOptions.java
@@ -15,6 +15,8 @@
  */
 package org.onosproject.store.service;
 
+import java.util.function.BiFunction;
+
 import org.onosproject.store.primitives.DistributedPrimitiveOptions;
 
 /**
@@ -23,7 +25,22 @@
  * @param <V> atomic value type
  */
 public abstract class AtomicValueOptions<O extends AtomicValueOptions<O, V>, V> extends DistributedPrimitiveOptions<O> {
+    protected BiFunction<V, org.onosproject.core.Version, V> compatibilityFunction;
+
     public AtomicValueOptions() {
         super(DistributedPrimitive.Type.VALUE);
     }
+
+    /**
+     * Sets a compatibility function on the map.
+     *
+     * @param compatibilityFunction the compatibility function
+     * @return the consistent map builder
+     */
+    @SuppressWarnings("unchecked")
+    public O withCompatibilityFunction(
+        BiFunction<V, org.onosproject.core.Version, V> compatibilityFunction) {
+        this.compatibilityFunction = compatibilityFunction;
+        return (O) this;
+    }
 }
diff --git a/core/api/src/main/java/org/onosproject/store/service/PrimitiveService.java b/core/api/src/main/java/org/onosproject/store/service/PrimitiveService.java
index 7be0480..cc77393 100644
--- a/core/api/src/main/java/org/onosproject/store/service/PrimitiveService.java
+++ b/core/api/src/main/java/org/onosproject/store/service/PrimitiveService.java
@@ -114,6 +114,14 @@
     LeaderElectorBuilder leaderElectorBuilder();
 
     /**
+     * Creates a new TopicBuilder.
+     *
+     * @param <T> topic value type
+     * @return topic builder
+     */
+    <T> TopicBuilder<T> topicBuilder();
+
+    /**
      * Creates a new transaction context builder.
      *
      * @return a builder for a transaction context.
diff --git a/core/api/src/main/java/org/onosproject/store/service/StorageService.java b/core/api/src/main/java/org/onosproject/store/service/StorageService.java
index 2dd42fa..aa2e890 100644
--- a/core/api/src/main/java/org/onosproject/store/service/StorageService.java
+++ b/core/api/src/main/java/org/onosproject/store/service/StorageService.java
@@ -121,6 +121,14 @@
     LeaderElectorBuilder leaderElectorBuilder();
 
     /**
+     * Creates a new TopicBuilder.
+     *
+     * @param <T> topic value type
+     * @return topic builder
+     */
+    <T> TopicBuilder<T> topicBuilder();
+
+    /**
      * Creates a new transaction context builder.
      *
      * @return a builder for a transaction context.
diff --git a/core/api/src/main/java/org/onosproject/store/service/TopicBuilder.java b/core/api/src/main/java/org/onosproject/store/service/TopicBuilder.java
new file mode 100644
index 0000000..5943432
--- /dev/null
+++ b/core/api/src/main/java/org/onosproject/store/service/TopicBuilder.java
@@ -0,0 +1,28 @@
+/*
+ * Copyright 2018-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.store.service;
+
+import org.onosproject.store.primitives.DistributedPrimitiveBuilder;
+
+/**
+ * Builder for {@link Topic} instances.
+ *
+ * @param <T> type for topic value
+ */
+public abstract class TopicBuilder<T>
+    extends TopicOptions<TopicBuilder<T>, T>
+    implements DistributedPrimitiveBuilder<Topic<T>> {
+}
diff --git a/core/api/src/main/java/org/onosproject/store/service/TopicOptions.java b/core/api/src/main/java/org/onosproject/store/service/TopicOptions.java
new file mode 100644
index 0000000..7845b56
--- /dev/null
+++ b/core/api/src/main/java/org/onosproject/store/service/TopicOptions.java
@@ -0,0 +1,49 @@
+/*
+ * Copyright 2018-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.store.service;
+
+import java.util.function.BiFunction;
+
+import org.onosproject.store.primitives.DistributedPrimitiveOptions;
+
+/**
+ * Builder for {@link Topic} instances.
+ *
+ * @param <T> type for topic value
+ */
+public abstract class TopicOptions<O extends TopicOptions<O, T>, T>
+    extends DistributedPrimitiveOptions<O> {
+
+    protected BiFunction<T, org.onosproject.core.Version, T> compatibilityFunction;
+
+    public TopicOptions() {
+        super(DistributedPrimitive.Type.TOPIC);
+    }
+
+    /**
+     * Sets a compatibility function on the map.
+     *
+     * @param compatibilityFunction the compatibility function
+     * @return the consistent map builder
+     */
+    @SuppressWarnings("unchecked")
+    public O withCompatibilityFunction(
+        BiFunction<T, org.onosproject.core.Version, T> compatibilityFunction) {
+        this.compatibilityFunction = compatibilityFunction;
+        return (O) this;
+    }
+
+}