Merge "BUG 2799: SPI for EventSources"
[controller.git] / opendaylight / md-sal / sal-rest-connector / src / test / java / org / opendaylight / controller / sal / restconf / impl / test / structures / Lst.java
index f5b3a5446e8f504c29f05989d9992cb2c7c448d1..8eccf373b9e3b8fd40283517303540517412b97d 100644 (file)
@@ -1,18 +1,30 @@
+/*
+ * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
 package org.opendaylight.controller.sal.restconf.impl.test.structures;
 
-import java.util.*;
+import java.util.HashSet;
+import java.util.Set;
 
 public class Lst extends YangElement {
-    private Set<LstItem> lstItems;
+    private final Set<LstItem> lstItems;
 
-    public Lst(String name) {
+    public Lst(final String name) {
         super(name);
         lstItems = new HashSet<>();
     }
 
-    public void addLstItem(LstItem lstItem) {
+    public Lst addLstItem(final LstItem lstItem) {
         lstItem.setLstName(name);
+        while (this.lstItems.contains(lstItem)) {
+            lstItem.incNumOfEqualItems();
+        }
         this.lstItems.add(lstItem);
+        return this;
     }
 
     public Set<LstItem> getLstItems() {
@@ -20,7 +32,7 @@ public class Lst extends YangElement {
     }
 
     @Override
-    public boolean equals(Object obj) {
+    public boolean equals(final Object obj) {
         if (this == obj) {
             return true;
         }
@@ -31,7 +43,11 @@ public class Lst extends YangElement {
             return false;
         }
         Lst lst = (Lst) obj;
-        if (!this.lstItems.equals(lst.lstItems)) {
+        if (this.lstItems == null) {
+            if (lst.lstItems != null) {
+                return false;
+            }
+        } else if (!this.lstItems.equals(lst.lstItems)) {
             return false;
         }
         return true;
@@ -44,5 +60,4 @@ public class Lst extends YangElement {
         result = prime * result + ((lstItems == null) ? 0 : lstItems.hashCode());
         return result;
     }
-
 }