Adding atomic countetr compare and set method

Change-Id: I5cf459e9e09ab1a84ced8160ef61d6a52ea4bea4
diff --git a/core/api/src/main/java/org/onosproject/store/service/AsyncAtomicCounter.java b/core/api/src/main/java/org/onosproject/store/service/AsyncAtomicCounter.java
index 92efd39..c0df713 100644
--- a/core/api/src/main/java/org/onosproject/store/service/AsyncAtomicCounter.java
+++ b/core/api/src/main/java/org/onosproject/store/service/AsyncAtomicCounter.java
@@ -66,4 +66,13 @@
      * @return future void
      */
     CompletableFuture<Void> set(long value);
+
+    /**
+     * Atomically sets the given counter to the updated value if the current value is the expected value, otherwise
+     * no change occurs.
+     * @param expectedValue the expected current value of the counter
+     * @param updateValue the new value to be set
+     * @return true if the update occurred and the expected value was equal to the current value, false otherwise
+     */
+    CompletableFuture<Boolean> compareAndSet(long expectedValue, long updateValue);
 }
diff --git a/core/api/src/main/java/org/onosproject/store/service/AtomicCounter.java b/core/api/src/main/java/org/onosproject/store/service/AtomicCounter.java
index 051838a..3c9e02c 100644
--- a/core/api/src/main/java/org/onosproject/store/service/AtomicCounter.java
+++ b/core/api/src/main/java/org/onosproject/store/service/AtomicCounter.java
@@ -57,6 +57,14 @@
      */
     void set(long value);
 
+    /**
+     * Atomically sets the given counter to the updated value if the current value is the expected value, otherwise
+     * no change occurs.
+     * @param expectedValue the expected current value of the counter
+     * @param updateValue the new value to be set
+     * @return true if the update occurred and the expected value was equal to the current value, false otherwise
+     */
+    boolean compareAndSet(long expectedValue, long updateValue);
 
     /**
      * Returns the current value of the counter without modifying it.
diff --git a/core/api/src/test/java/org/onosproject/store/service/TestAtomicCounter.java b/core/api/src/test/java/org/onosproject/store/service/TestAtomicCounter.java
index 26a5040..8c577df 100644
--- a/core/api/src/test/java/org/onosproject/store/service/TestAtomicCounter.java
+++ b/core/api/src/test/java/org/onosproject/store/service/TestAtomicCounter.java
@@ -53,6 +53,11 @@
     }
 
     @Override
+    public boolean compareAndSet(long expectedValue, long updateValue) {
+        return value.compareAndSet(expectedValue, updateValue);
+    }
+
+    @Override
     public long get() {
         return value.get();
     }