Add KeyLeaf sanity check
RFC6020 section 7.8.2
A leaf identifier MUST NOT appear more than once in the key.
Change-Id: Ia11373dfcb88821527589e3c85a47e891531ea25
diff --git a/model/src/main/java/org/onosproject/yang/model/KeyLeaf.java b/model/src/main/java/org/onosproject/yang/model/KeyLeaf.java
index b5edf17..675521c 100644
--- a/model/src/main/java/org/onosproject/yang/model/KeyLeaf.java
+++ b/model/src/main/java/org/onosproject/yang/model/KeyLeaf.java
@@ -51,6 +51,7 @@
* @throws CloneNotSupportedException if the object's class does not
* support the {@code Cloneable} interface
*/
+ @Override
public KeyLeaf clone() throws CloneNotSupportedException {
KeyLeaf clonedLeaf = (KeyLeaf) super.clone();
clonedLeaf.leafSchema = leafSchema.clone();
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 b5be8f7..9f65a16 100644
--- a/model/src/main/java/org/onosproject/yang/model/ListKey.java
+++ b/model/src/main/java/org/onosproject/yang/model/ListKey.java
@@ -23,6 +23,7 @@
import java.util.Objects;
import static com.google.common.base.MoreObjects.toStringHelper;
+import static com.google.common.base.Preconditions.checkArgument;
/**
* Represents an entity which identifies a unique branching node
@@ -135,9 +136,13 @@
* @param name key leaf name
* @param nameSpace key leaf namespace
* @param val value of key
+ * @throws IllegalArgumentException if duplicate key already exists
*/
public void addKeyLeaf(String name, String nameSpace, Object val) {
KeyLeaf keyLeaf = new KeyLeaf(name, nameSpace, val);
+ checkArgument(!keyLeafs.contains(keyLeaf),
+ "Attempted to add duplicate key: %s@%s=%s",
+ name, nameSpace, val);
keyLeafs.add(keyLeaf);
}