d0f6a4644f99b9ff4bc0df4e886697fbae00a4b4
[netvirt.git] / statistics / impl / src / main / java / org / opendaylight / netvirt / statistics / ElementCountersRequest.java
1 /*
2  * Copyright (c) 2017 HPE, 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.netvirt.statistics;
9
10 import java.math.BigInteger;
11 import java.util.HashMap;
12 import java.util.Map;
13
14 public class ElementCountersRequest {
15
16     private ElementCountersDirection direction;
17     private String portId;
18     private BigInteger dpn;
19     private int lportTag;
20     private Map<String, Map<String, String>> filters;
21
22     public ElementCountersRequest(String portId) {
23         this.portId = portId;
24         filters = new HashMap<>();
25     }
26
27     public void setElementCountersDirection(ElementCountersDirection elementCountersDirection) {
28         this.direction = elementCountersDirection;
29     }
30
31     public String getPortId() {
32         return portId;
33     }
34
35     public ElementCountersDirection getDirection() {
36         return direction;
37     }
38
39     public Map<String, Map<String, String>> getFilters() {
40         return filters;
41     }
42
43     public void addFilterGroup(String filterGroupName) {
44         filters.put(filterGroupName, new HashMap<>());
45     }
46
47     public Map<String, String> getFilterGroup(String filterGroupName) {
48         return filters.get(filterGroupName);
49     }
50
51     public void addFilterToFilterGroup(String filterGroupName, String filterName, String value) {
52         if (filters.get(filterGroupName) == null) {
53             addFilterGroup(filterGroupName);
54         }
55         filters.get(filterGroupName).put(filterName, value);
56     }
57
58     public String getFilterFromFilterGroup(String filterGroupName, String filterName) {
59         if (filters.containsKey(filterGroupName)) {
60             return filters.get(filterGroupName).get(filterName);
61         }
62
63         return null;
64     }
65
66     public int getLportTag() {
67         return lportTag;
68     }
69
70     public void setLportTag(int lportTag) {
71         this.lportTag = lportTag;
72     }
73
74     public BigInteger getDpn() {
75         return dpn;
76     }
77
78     public void setDpn(BigInteger dpn) {
79         this.dpn = dpn;
80     }
81
82     public boolean isFilterGroupExist(String filterGroupName) {
83         return filters.containsKey(filterGroupName);
84     }
85
86     public boolean isFilterExist(String filterGroupName, String filterName) {
87         if (!isFilterGroupExist(filterGroupName)) {
88             return false;
89         }
90
91         return filters.get(filterGroupName).containsKey(filterName);
92     }
93
94     @Override
95     public int hashCode() {
96         final int prime = 31;
97         int result = 1;
98         result = prime * result + ((direction == null) ? 0 : direction.hashCode());
99         result = prime * result + ((dpn == null) ? 0 : dpn.hashCode());
100         result = prime * result + ((filters == null) ? 0 : filters.hashCode());
101         result = prime * result + lportTag;
102         result = prime * result + ((portId == null) ? 0 : portId.hashCode());
103         return result;
104     }
105
106     @Override
107     public boolean equals(Object obj) {
108         if (this == obj) {
109             return true;
110         }
111         if (obj == null) {
112             return false;
113         }
114         if (getClass() != obj.getClass()) {
115             return false;
116         }
117         ElementCountersRequest other = (ElementCountersRequest) obj;
118         if (direction != other.direction) {
119             return false;
120         }
121         if (dpn == null) {
122             if (other.dpn != null) {
123                 return false;
124             }
125         } else if (!dpn.equals(other.dpn)) {
126             return false;
127         }
128         if (filters == null) {
129             if (other.filters != null) {
130                 return false;
131             }
132         } else if (!filters.equals(other.filters)) {
133             return false;
134         }
135         if (lportTag != other.lportTag) {
136             return false;
137         }
138         if (portId == null) {
139             if (other.portId != null) {
140                 return false;
141             }
142         } else if (!portId.equals(other.portId)) {
143             return false;
144         }
145         return true;
146     }
147
148     @Override
149     public String toString() {
150         return "ElementCountersRequest [direction=" + direction + ", portId=" + portId + ", dpn=" + dpn + ", lportTag="
151                 + lportTag + ", filters=" + filters + "]";
152     }
153 }