Copy only once on instantiation

- fix test data bug, which relied on mutable behavior.

Change-Id: I4c799deaed20a1bd40f020857c7910e1f541fb05
diff --git a/model/src/main/java/org/onosproject/yang/model/ListKey.java b/model/src/main/java/org/onosproject/yang/model/ListKey.java
index 297a660..9f643a4 100644
--- a/model/src/main/java/org/onosproject/yang/model/ListKey.java
+++ b/model/src/main/java/org/onosproject/yang/model/ListKey.java
@@ -30,6 +30,7 @@
  */
 public final class ListKey extends NodeKey<ListKey> implements Comparable<ListKey> {
 
+    // effectively final, but not possible due to clone()
     private List<KeyLeaf> keyLeafs;
 
     /**
@@ -39,7 +40,7 @@
      */
     private ListKey(ListKeyBuilder builder) {
         super(builder);
-        keyLeafs = builder.keyLeafs;
+        keyLeafs = ImmutableList.copyOf(builder.keyLeafs);
     }
 
     /**
@@ -50,7 +51,7 @@
      * @return List of key leaf nodes
      */
     public List<KeyLeaf> keyLeafs() {
-        return ImmutableList.copyOf(keyLeafs);
+        return keyLeafs;
     }
 
     /**
@@ -60,19 +61,21 @@
      * @throws CloneNotSupportedException if the object's class does not
      *                                    support the {@code Cloneable} interface
      */
+    @Override
     public ListKey clone() throws CloneNotSupportedException {
         ListKey clonedListKey = (ListKey) super.clone();
-        List<KeyLeaf> clonedKeyLeafs = new LinkedList<>();
+        ImmutableList.Builder<KeyLeaf> clonedKeyLeafs = ImmutableList.builder();
         for (KeyLeaf leaf : keyLeafs) {
             clonedKeyLeafs.add(leaf.clone());
         }
-        clonedListKey.keyLeafs = clonedKeyLeafs;
+        clonedListKey.keyLeafs = clonedKeyLeafs.build();
         return clonedListKey;
     }
 
+    @Override
     public int compareTo(ListKey o) {
         //TODO: implement me
-        return 0;
+        throw new UnsupportedOperationException();
     }
 
     @Override
@@ -129,7 +132,7 @@
          * Adds the key leaf for the list resource.
          *
          * @param name      key leaf name
-         * @param nameSpace key laef namespace
+         * @param nameSpace key leaf namespace
          * @param val       value of key
          */
         public void addKeyLeaf(String name, String nameSpace, Object val) {
@@ -142,6 +145,7 @@
          *
          * @return list key
          */
+        @Override
         public ListKey build() {
             return new ListKey(this);
         }
diff --git a/runtime/src/test/java/org/onosproject/yang/runtime/impl/serializerhelper/AddToDataNodeList1Test.java b/runtime/src/test/java/org/onosproject/yang/runtime/impl/serializerhelper/AddToDataNodeList1Test.java
index 94d0a4b..9872c8d 100644
--- a/runtime/src/test/java/org/onosproject/yang/runtime/impl/serializerhelper/AddToDataNodeList1Test.java
+++ b/runtime/src/test/java/org/onosproject/yang/runtime/impl/serializerhelper/AddToDataNodeList1Test.java
@@ -130,14 +130,14 @@
         dBlr = exitDataNode(dBlr);
 
         //Tree validation
-        nA = new String[]{"/", "l1", "k1", "k2", "k3", "c1", "leaf_c1"};
-        nsA = new String[]{null, LNS, LNS, LNS, LNS, LNS, LNS};
-        valA = new String[]{"1", "2", "3", "0"};
+        nA = new String[]{"/", "l1", "k1", "k2", "c1", "leaf_c1"};
+        nsA = new String[]{null, LNS, LNS, LNS, LNS, LNS};
+        valA = new String[]{"1", "2", null, "0"};
         validateResourceId(nA, nsA, valA, id);
 
-        nA = new String[]{"/", "l1", "k1", "k2", "k3", "c1"};
-        nsA = new String[]{null, LNS, LNS, LNS, LNS, LNS};
-        valA = new String[]{"1", "2", "3"};
+        nA = new String[]{"/", "l1", "k1", "k2", "c1"};
+        nsA = new String[]{null, LNS, LNS, LNS, LNS};
+        valA = new String[]{"1", "2", null};
         validateResourceId(nA, nsA, valA, id1);
 
         nA = new String[]{"/", "l1", "k1", "k2", "k3"};
diff --git a/runtime/src/test/java/org/onosproject/yang/runtime/impl/serializerhelper/AddToDataNodeListTest.java b/runtime/src/test/java/org/onosproject/yang/runtime/impl/serializerhelper/AddToDataNodeListTest.java
index 4102e74..db25f51 100644
--- a/runtime/src/test/java/org/onosproject/yang/runtime/impl/serializerhelper/AddToDataNodeListTest.java
+++ b/runtime/src/test/java/org/onosproject/yang/runtime/impl/serializerhelper/AddToDataNodeListTest.java
@@ -167,14 +167,14 @@
         dBlr = exitDataNode(dBlr);
 
         //Tree validation
-        nA = new String[]{"/", "l1", "k1", "k2", "k3", "c1", "leaf_c1"};
-        nsA = new String[]{null, LNS, LNS, LNS, LNS, LNS, LNS};
-        valA = new String[]{"1", "2", "3", "0"};
+        nA = new String[]{"/", "l1", "k1", "k2", "c1", "leaf_c1"};
+        nsA = new String[]{null, LNS, LNS, LNS, LNS, LNS};
+        valA = new String[]{"1", "2", null, "0"};
         validateResourceId(nA, nsA, valA, id);
 
-        nA = new String[]{"/", "l1", "k1", "k2", "k3", "c1"};
-        nsA = new String[]{null, LNS, LNS, LNS, LNS, LNS};
-        valA = new String[]{"1", "2", "3"};
+        nA = new String[]{"/", "l1", "k1", "k2", "c1"};
+        nsA = new String[]{null, LNS, LNS, LNS, LNS};
+        valA = new String[]{"1", "2", null};
         validateResourceId(nA, nsA, valA, id1);
 
         nA = new String[]{"/", "l1", "k1", "k2", "k3"};