Modified UNI/LTP completers to avoid duplicate UNI/LTP arguments in the same command.

Change-Id: I13e65f43a37f8af2736819172138bd34cdedb414
diff --git a/ecord/carrierethernet/src/main/java/org/onosproject/ecord/carrierethernet/app/CarrierEthernetManager.java b/ecord/carrierethernet/src/main/java/org/onosproject/ecord/carrierethernet/app/CarrierEthernetManager.java
index 9f9e667..9d76292 100644
--- a/ecord/carrierethernet/src/main/java/org/onosproject/ecord/carrierethernet/app/CarrierEthernetManager.java
+++ b/ecord/carrierethernet/src/main/java/org/onosproject/ecord/carrierethernet/app/CarrierEthernetManager.java
@@ -99,7 +99,7 @@
     private static final int METRO_CONNECT_TIMEOUT_MILLIS = 7000;
 
     // If set to false, the setup of optical connectivity using the metro app is bypassed
-    private static final boolean PACKET_OPTICAL_TOPO = true;
+    private static final boolean PACKET_OPTICAL_TOPO = false;
 
     // TODO: Implement distributed store for EVCs
     // The installed EVCs
diff --git a/ecord/carrierethernet/src/main/java/org/onosproject/ecord/carrierethernet/cli/CarrierEthernetLtpCompleter.java b/ecord/carrierethernet/src/main/java/org/onosproject/ecord/carrierethernet/cli/CarrierEthernetLtpCompleter.java
index 045483f..198e213 100644
--- a/ecord/carrierethernet/src/main/java/org/onosproject/ecord/carrierethernet/cli/CarrierEthernetLtpCompleter.java
+++ b/ecord/carrierethernet/src/main/java/org/onosproject/ecord/carrierethernet/cli/CarrierEthernetLtpCompleter.java
@@ -15,8 +15,8 @@
  */
 package org.onosproject.ecord.carrierethernet.cli;
 
-import org.apache.karaf.shell.console.Completer;
 import org.apache.karaf.shell.console.completer.StringsCompleter;
+import org.onosproject.cli.AbstractCompleter;
 import org.onosproject.cli.AbstractShellCommand;
 import org.onosproject.ecord.carrierethernet.app.CarrierEthernetManager;
 
@@ -26,19 +26,15 @@
 /**
  * LTP ConnectPoint completer.
  */
-public class CarrierEthernetLtpCompleter implements Completer {
+public class CarrierEthernetLtpCompleter extends AbstractCompleter {
     @Override
     public int complete(String buffer, int cursor, List<String> candidates) {
 
-        // TODO: Add memory
-
-        StringsCompleter delegate = new StringsCompleter();
-
-        CarrierEthernetManager ceManager =
-                AbstractShellCommand.get(CarrierEthernetManager.class);
-
+        StringsCompleter delegate = new UniqueStringsCompleter();
         SortedSet<String> strings = delegate.getStrings();
-        ceManager.getGlobalLtps().forEach(uni -> strings.add(uni.id()));
+
+        CarrierEthernetManager ceManager = AbstractShellCommand.get(CarrierEthernetManager.class);
+        ceManager.getGlobalLtps().forEach(ltp -> strings.add(ltp.id()));
 
         return delegate.complete(buffer, cursor, candidates);
     }
diff --git a/ecord/carrierethernet/src/main/java/org/onosproject/ecord/carrierethernet/cli/CarrierEthernetUniCompleter.java b/ecord/carrierethernet/src/main/java/org/onosproject/ecord/carrierethernet/cli/CarrierEthernetUniCompleter.java
index 853fb5b..daca6b6 100644
--- a/ecord/carrierethernet/src/main/java/org/onosproject/ecord/carrierethernet/cli/CarrierEthernetUniCompleter.java
+++ b/ecord/carrierethernet/src/main/java/org/onosproject/ecord/carrierethernet/cli/CarrierEthernetUniCompleter.java
@@ -15,8 +15,8 @@
  */
 package org.onosproject.ecord.carrierethernet.cli;
 
-import org.apache.karaf.shell.console.Completer;
 import org.apache.karaf.shell.console.completer.StringsCompleter;
+import org.onosproject.cli.AbstractCompleter;
 import org.onosproject.cli.AbstractShellCommand;
 import org.onosproject.ecord.carrierethernet.app.CarrierEthernetManager;
 
@@ -26,18 +26,15 @@
 /**
  * UNI ConnectPoint completer.
  */
-public class CarrierEthernetUniCompleter implements Completer {
+public class CarrierEthernetUniCompleter extends AbstractCompleter {
+
     @Override
     public int complete(String buffer, int cursor, List<String> candidates) {
 
-        // TODO: Add memory
-
-        StringsCompleter delegate = new StringsCompleter();
-
-        CarrierEthernetManager ceManager =
-                AbstractShellCommand.get(CarrierEthernetManager.class);
-
+        StringsCompleter delegate = new UniqueStringsCompleter();
         SortedSet<String> strings = delegate.getStrings();
+
+        CarrierEthernetManager ceManager = AbstractShellCommand.get(CarrierEthernetManager.class);
         ceManager.getGlobalUnis().forEach(uni -> strings.add(uni.id()));
 
         return delegate.complete(buffer, cursor, candidates);
diff --git a/ecord/carrierethernet/src/main/java/org/onosproject/ecord/carrierethernet/cli/UniqueStringsCompleter.java b/ecord/carrierethernet/src/main/java/org/onosproject/ecord/carrierethernet/cli/UniqueStringsCompleter.java
new file mode 100644
index 0000000..6522c71
--- /dev/null
+++ b/ecord/carrierethernet/src/main/java/org/onosproject/ecord/carrierethernet/cli/UniqueStringsCompleter.java
@@ -0,0 +1,47 @@
+/*
+ * 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.ecord.carrierethernet.cli;
+
+import org.apache.felix.service.command.CommandSession;
+import org.apache.karaf.shell.console.CommandSessionHolder;
+import org.apache.karaf.shell.console.completer.ArgumentCompleter;
+import org.apache.karaf.shell.console.completer.StringsCompleter;
+
+import java.util.Arrays;
+import java.util.List;
+
+/**
+ * String completer which excludes strings already included in the preceding argument list.
+ */
+public class UniqueStringsCompleter extends StringsCompleter {
+
+    @Override
+    public int complete(String buffer, int cursor, List candidates) {
+
+        // Get all preceding arguments
+        CommandSession session = CommandSessionHolder.getSession();
+        List<String> prevArgsList = Arrays.asList(((ArgumentCompleter.ArgumentList)session
+                .get("ARGUMENTS_LIST")).getArguments());
+
+        super.complete(buffer, cursor, candidates);
+
+        // Remove from candidate list all strings included in preceding arguments
+        candidates.removeAll(prevArgsList);
+
+        return candidates.isEmpty() ? - 1 : 0;
+    }
+
+}