[ONOS-3114] Changes on Flow Classifier Manager

Change-Id: I5cdbe2c0c9769d16381322bb6c952cdc37ecccfc
diff --git a/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/flowclassifier/FlowClassifierService.java b/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/flowclassifier/FlowClassifierService.java
index c160d22..c5911ff 100644
--- a/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/flowclassifier/FlowClassifierService.java
+++ b/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/flowclassifier/FlowClassifierService.java
@@ -24,49 +24,59 @@
 public interface FlowClassifierService {
 
     /**
+     * Check whether Flow Classifier is present based on given Flow Classifier
+     * Id.
+     *
+     * @param id flow classifier identifier
+     * @return true if flow classifier is present otherwise return false
+     */
+    boolean exists(FlowClassifierId id);
+
+    /**
+     * Returns the number of flow classifiers known to the system.
+     *
+     * @return number of flow classifiers
+     */
+    int getFlowClassifierCount();
+
+    /**
      * Store Flow Classifier.
      *
-     * @param flowClassifier Flow Classifier
-     * @return true if adding Flow Classifier into store is success otherwise return false.
+     * @param flowClassifier flow classifier
+     * @return true if adding flow classifier into store is success otherwise
+     *         return false
      */
     boolean createFlowClassifier(FlowClassifier flowClassifier);
 
     /**
      * Return the existing collection of Flow Classifier.
      *
-     * @return Flow Classifier collections.
+     * @return flow classifier collections
      */
     Iterable<FlowClassifier> getFlowClassifiers();
 
     /**
-     * Check whether Flow Classifier is present based on given Flow Classifier Id.
-     *
-     * @param id Flow Classifier.
-     * @return true if Flow Classifier is present otherwise return false.
-     */
-    boolean hasFlowClassifier(FlowClassifierId id);
-
-    /**
      * Retrieve the Flow Classifier based on given Flow Classifier id.
      *
-     * @param id Flow Classifier Id.
-     * @return Flow Classifier if present otherwise returns null.
+     * @param id flow classifier identifier
+     * @return flow classifier if present otherwise returns null
      */
     FlowClassifier getFlowClassifier(FlowClassifierId id);
 
     /**
      * Update Flow Classifier based on given Flow Classifier Id.
      *
-     * @param flowClassifier Flow Classifier.
-     * @return true if update is success otherwise return false.
+     * @param flowClassifier flow classifier
+     * @return true if flow classifier update is success otherwise return false
      */
     boolean updateFlowClassifier(FlowClassifier flowClassifier);
 
     /**
      * Remove Flow Classifier from store based on given Flow Classifier Id.
      *
-     * @param id Flow Classifier Id.
-     * @return true if Flow Classifier removal is success otherwise return false.
+     * @param id flow classifier identifier
+     * @return true if flow classifier removal is success otherwise return
+     *         false
      */
     boolean removeFlowClassifier(FlowClassifierId id);
 }
diff --git a/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/flowclassifier/impl/FlowClassifierManager.java b/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/flowclassifier/impl/FlowClassifierManager.java
index 015163d..4a60cd3 100644
--- a/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/flowclassifier/impl/FlowClassifierManager.java
+++ b/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/flowclassifier/impl/FlowClassifierManager.java
@@ -73,6 +73,28 @@
     }
 
     @Override
+    public boolean exists(FlowClassifierId id) {
+        checkNotNull(id, FLOW_CLASSIFIER_ID_NOT_NULL);
+        return flowClassifierStore.containsKey(id);
+    }
+
+    @Override
+    public int getFlowClassifierCount() {
+        return flowClassifierStore.size();
+    }
+
+    @Override
+    public Iterable<FlowClassifier> getFlowClassifiers() {
+        return ImmutableList.copyOf(flowClassifierStore.values());
+    }
+
+    @Override
+    public FlowClassifier getFlowClassifier(FlowClassifierId id) {
+        checkNotNull(id, FLOW_CLASSIFIER_ID_NOT_NULL);
+        return flowClassifierStore.get(id);
+    }
+
+    @Override
     public boolean createFlowClassifier(FlowClassifier flowClassifier) {
         log.debug("createFlowClassifier");
         checkNotNull(flowClassifier, FLOW_CLASSIFIER_NOT_NULL);
@@ -87,27 +109,22 @@
     }
 
     @Override
-    public Iterable<FlowClassifier> getFlowClassifiers() {
-        return ImmutableList.copyOf(flowClassifierStore.values());
-    }
-
-    @Override
-    public boolean hasFlowClassifier(FlowClassifierId id) {
-        checkNotNull(id, FLOW_CLASSIFIER_ID_NOT_NULL);
-        return flowClassifierStore.containsKey(id);
-    }
-
-    @Override
-    public FlowClassifier getFlowClassifier(FlowClassifierId id) {
-        checkNotNull(id, FLOW_CLASSIFIER_ID_NOT_NULL);
-        return flowClassifierStore.get(id);
-    }
-
-    @Override
     public boolean updateFlowClassifier(FlowClassifier flowClassifier) {
         checkNotNull(flowClassifier, FLOW_CLASSIFIER_NOT_NULL);
-        FlowClassifierId id = flowClassifier.flowClassifierId();
-        flowClassifierStore.put(id, flowClassifier);
+
+        if (!flowClassifierStore.containsKey(flowClassifier.flowClassifierId())) {
+            log.debug("The flowClassifier is not exist whose identifier was {} ", flowClassifier.flowClassifierId()
+                    .toString());
+            return false;
+        }
+
+        flowClassifierStore.put(flowClassifier.flowClassifierId(), flowClassifier);
+
+        if (!flowClassifier.equals(flowClassifierStore.get(flowClassifier.flowClassifierId()))) {
+            log.debug("Updation of flowClassifier is failed whose identifier was {} ", flowClassifier
+                    .flowClassifierId().toString());
+            return false;
+        }
         return true;
     }