Apply Null Object pattern

Change-Id: I9b4d30114b22dcd32b228e4f17bb541beed4ebed
diff --git a/core/api/src/main/java/org/onosproject/net/flow/FlowRuleOperations.java b/core/api/src/main/java/org/onosproject/net/flow/FlowRuleOperations.java
index 5456513..1bf8007 100644
--- a/core/api/src/main/java/org/onosproject/net/flow/FlowRuleOperations.java
+++ b/core/api/src/main/java/org/onosproject/net/flow/FlowRuleOperations.java
@@ -23,6 +23,7 @@
 import java.util.List;
 import java.util.Set;
 
+import static com.google.common.base.Preconditions.checkNotNull;
 import static org.onosproject.net.flow.FlowRuleOperation.Type.*;
 
 /**
@@ -32,7 +33,7 @@
 public class FlowRuleOperations {
 
     private final List<Set<FlowRuleOperation>> stages;
-    private final FlowRuleOperationsContext callback; // TODO consider Optional
+    private final FlowRuleOperationsContext callback;
 
     private FlowRuleOperations(List<Set<FlowRuleOperation>> stages,
                                FlowRuleOperationsContext cb) {
@@ -164,7 +165,7 @@
          * @return flow rule operations
          */
         public FlowRuleOperations build() {
-            return build(null);
+            return build(NullFlowRuleOperationsContext.getInstance());
         }
 
         /**
@@ -174,6 +175,8 @@
          * @return flow rule operations
          */
         public FlowRuleOperations build(FlowRuleOperationsContext cb) {
+            checkNotNull(cb);
+
             closeStage();
             return new FlowRuleOperations(listBuilder.build(), cb);
         }
diff --git a/core/api/src/main/java/org/onosproject/net/flow/NullFlowRuleOperationsContext.java b/core/api/src/main/java/org/onosproject/net/flow/NullFlowRuleOperationsContext.java
new file mode 100644
index 0000000..a452f22
--- /dev/null
+++ b/core/api/src/main/java/org/onosproject/net/flow/NullFlowRuleOperationsContext.java
@@ -0,0 +1,35 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * 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.net.flow;
+
+/**
+ * Represents FlowRuleOperations that does nothing on success or on error.
+ */
+final class NullFlowRuleOperationsContext implements FlowRuleOperationsContext {
+    private static final FlowRuleOperationsContext INSTANCE = new NullFlowRuleOperationsContext();
+
+    private NullFlowRuleOperationsContext() {}
+
+    /**
+     * Returns an instance of this class.
+     *
+     * @return instance
+     */
+    public static FlowRuleOperationsContext getInstance() {
+        return INSTANCE;
+    }
+}