BUG-272: cleanup sal-rest-connector
[controller.git] / opendaylight / md-sal / sal-rest-connector / src / test / java / org / opendaylight / controller / sal / restconf / impl / test / structures / Lst.java
1 /*
2  * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.controller.sal.restconf.impl.test.structures;
9
10 import java.util.HashSet;
11 import java.util.Set;
12
13 public class Lst extends YangElement {
14     private final Set<LstItem> lstItems;
15
16     public Lst(final String name) {
17         super(name);
18         lstItems = new HashSet<>();
19     }
20
21     public Lst addLstItem(final LstItem lstItem) {
22         lstItem.setLstName(name);
23         while (this.lstItems.contains(lstItem)) {
24             lstItem.incNumOfEqualItems();
25         }
26         this.lstItems.add(lstItem);
27         return this;
28     }
29
30     public Set<LstItem> getLstItems() {
31         return lstItems;
32     }
33
34     @Override
35     public boolean equals(final Object obj) {
36         if (this == obj) {
37             return true;
38         }
39         if (!this.getClass().equals(obj.getClass())) {
40             return false;
41         }
42         if (!super.equals(obj)) {
43             return false;
44         }
45         Lst lst = (Lst) obj;
46         if (this.lstItems == null) {
47             if (lst.lstItems != null) {
48                 return false;
49             }
50         } else if (!this.lstItems.equals(lst.lstItems)) {
51             return false;
52         }
53         return true;
54     }
55
56     @Override
57     public int hashCode() {
58         final int prime = 31;
59         int result = super.hashCode();
60         result = prime * result + ((lstItems == null) ? 0 : lstItems.hashCode());
61         return result;
62     }
63 }