Bug 2907 - corrections for upgrade to karaf 3.0.3
[controller.git] / opendaylight / md-sal / sal-rest-connector / src / test / java / org / opendaylight / controller / sal / restconf / impl / test / structures / LstItem.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 static org.junit.Assert.assertFalse;
11
12 import java.util.HashMap;
13 import java.util.Map;
14
15 public class LstItem {
16     String lstName;
17     Map<String, Lf> lfs;
18     Map<String, LfLst> lfLsts;
19     Map<String, Lst> lsts;
20     Map<String, Cont> conts;
21     private int numOfEqualItems = 0;
22
23     public LstItem() {
24         lfs = new HashMap<>();
25         conts = new HashMap<>();
26         lfLsts = new HashMap<>();
27         lsts = new HashMap<>();
28     }
29
30     public Map<String, Lst> getLsts() {
31         return lsts;
32     }
33
34     public Map<String, Cont> getConts() {
35         return conts;
36     }
37
38     public Map<String, LfLst> getLfLsts() {
39         return lfLsts;
40     }
41
42     public Map<String, Lf> getLfs() {
43         return lfs;
44     }
45
46     public String getLstName() {
47         return lstName;
48     }
49
50     public LstItem addLf(Lf lf) {
51         lfs.put(lf.getName(), lf);
52         return this;
53     }
54
55     public LstItem addLf(String name, Object value) {
56         lfs.put(name, new Lf(name, value));
57         return this;
58     }
59
60     public void addLfLst(LfLst lfLst) {
61         assertFalse("Found multiple leaf list elements for " + lfLst.getName(), lfLsts.containsKey(lfLst.getName()));
62         lfLsts.put(lfLst.getName(), lfLst);
63     }
64
65     public void addLst(Lst lst) {
66         assertFalse("Found multiple list elements for " + lst.getName(), lsts.containsKey(lst.getName()));
67         lsts.put(lst.getName(), lst);
68     }
69
70     public void addCont(Cont cont) {
71         conts.put(cont.getName(), cont);
72     }
73
74     public void incNumOfEqualItems() {
75         this.numOfEqualItems++;
76     }
77
78     @Override
79     public boolean equals(Object obj) {
80         if (this == obj) {
81             return true;
82         }
83         if (!this.getClass().equals(obj.getClass())) {
84             return false;
85         }
86         LstItem lstItem = (LstItem) obj;
87         if (this.conts == null) {
88             if (lstItem.conts != null) {
89                 return false;
90             }
91         } else if (!this.conts.equals(lstItem.conts)) {
92             return false;
93         }
94         if (this.lfs == null) {
95             if (lstItem.lfs != null) {
96                 return false;
97             }
98         } else if (!this.lfs.equals(lstItem.lfs)) {
99             return false;
100         }
101         if (this.lfLsts == null) {
102             if (lstItem.lfLsts != null) {
103                 return false;
104             }
105         } else if (!this.lfLsts.equals(lstItem.lfLsts)) {
106             return false;
107         }
108         if (this.lsts == null) {
109             if (lstItem.lsts != null) {
110                 return false;
111             }
112         } else if (!this.lsts.equals(lstItem.lsts)) {
113             return false;
114         }
115         if (this.numOfEqualItems != lstItem.numOfEqualItems) {
116             return false;
117         }
118         return true;
119     }
120
121     @Override
122     public int hashCode() {
123         final int prime = 31;
124         int result = 1;
125         result = prime * result + ((lfs == null) ? 0 : lfs.hashCode());
126         result = prime * result + ((lfLsts == null) ? 0 : lfLsts.hashCode());
127         result = prime * result + ((lsts == null) ? 0 : lsts.hashCode());
128         result = prime * result + ((conts == null) ? 0 : conts.hashCode());
129         result = prime * result + numOfEqualItems;
130         return result;
131     }
132
133     @Override
134     public String toString() {
135         return "lst item of " + lstName;
136     }
137
138     public void setLstName(String name) {
139         this.lstName = name;
140     }
141
142 }