Remove config subsystem from OpenFlowJava
[openflowplugin.git] / applications / statistics-manager / src / main / java / org / opendaylight / openflowplugin / applications / statistics / manager / impl / helper / MatchComparatorFactory.java
1 /*
2  * Copyright (c) 2013, 2015 IBM Corporation 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
9 package org.opendaylight.openflowplugin.applications.statistics.manager.impl.helper;
10
11 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.Match;
12 /**
13  * Provides comparator for comparing according to various {@link Match} attributes
14  *
15  */
16 public final class MatchComparatorFactory {
17
18     private MatchComparatorFactory() {
19         // NOOP
20     }
21
22     public static SimpleComparator<Match> createNull() {
23         return new SimpleComparator<Match>() {
24             /**
25              * Comparation by whole object
26              */
27             @Override
28             public boolean areObjectsEqual(Match statsMatch, Match storedMatch) {
29                 return (statsMatch == null) == (storedMatch == null);
30             }
31         };
32     }
33
34     public static SimpleComparator<Match> createVlan() {
35         return new SimpleComparator<Match>() {
36             /**
37              * Comparation by VLAN
38              */
39             @Override
40             public boolean areObjectsEqual(Match statsMatch, Match storedMatch) {
41                 if (storedMatch == null) return false;
42                 if (storedMatch.getVlanMatch() == null) {
43                     if (statsMatch.getVlanMatch() != null) {
44                         return false;
45                     }
46                 } else if (!storedMatch.getVlanMatch().equals(statsMatch.getVlanMatch())) {
47                     return false;
48                 }
49                 return true;
50             }
51         };
52     }
53
54     public static SimpleComparator<Match> createTunnel() {
55         return new SimpleComparator<Match>() {
56             /**
57              * Comparation by tunnel
58              */
59             @Override
60             public boolean areObjectsEqual(Match statsMatch, Match storedMatch) {
61                 if (storedMatch == null) return false;
62                 if (storedMatch.getTunnel() == null) {
63                     if (statsMatch.getTunnel() != null) {
64                         return false;
65                     }
66                 } else if (!storedMatch.getTunnel().equals(statsMatch.getTunnel())) {
67                     return false;
68                 }
69                 return true;
70             }
71         };
72     }
73
74     public static SimpleComparator<Match> createProtocolMatchFields() {
75         return new SimpleComparator<Match>() {
76             /**
77              * Comparation by protocol fields
78              */
79             @Override
80             public boolean areObjectsEqual(Match statsMatch, Match storedMatch) {
81                 if (storedMatch == null) return false;
82                 if (storedMatch.getProtocolMatchFields() == null) {
83                     if (statsMatch.getProtocolMatchFields() != null) {
84                         return false;
85                     }
86                 } else if (!storedMatch.getProtocolMatchFields().equals(statsMatch.getProtocolMatchFields())) {
87                     return false;
88                 }
89                 return true;
90             }
91         };
92     }
93
94     public static SimpleComparator<Match> createMetadata() {
95         return new SimpleComparator<Match>() {
96             /**
97              * Comparation by metadata
98              */
99             @Override
100             public boolean areObjectsEqual(Match statsMatch, Match storedMatch) {
101                 if (storedMatch == null) return false;
102                 if (storedMatch.getMetadata() == null) {
103                     if (statsMatch.getMetadata() != null) {
104                         return false;
105                     }
106                 } else if (!storedMatch.getMetadata().equals(statsMatch.getMetadata())) {
107                     return false;
108                 }
109                 return true;
110             }
111         };
112     }
113
114     public static SimpleComparator<Match> createL4() {
115         return new SimpleComparator<Match>() {
116             /**
117              * Comparation by layer4
118              */
119             @Override
120             public boolean areObjectsEqual(Match statsMatch, Match storedMatch) {
121                 if (storedMatch == null) return false;
122                 if (storedMatch.getLayer4Match() == null) {
123                     if (statsMatch.getLayer4Match() != null) {
124                         return false;
125                     }
126                 } else if (!storedMatch.getLayer4Match().equals(statsMatch.getLayer4Match())) {
127                     return false;
128                 }
129                 return true;
130             }
131         };
132     }
133
134     public static SimpleComparator<Match> createL3() {
135         return new SimpleComparator<Match>() {
136             /**
137              * Comparation by layer3
138              */
139             @Override
140             public boolean areObjectsEqual(Match statsMatch, Match storedMatch) {
141                 if (storedMatch == null) return false;
142                 if (storedMatch.getLayer3Match() == null) {
143                     if (statsMatch.getLayer3Match() != null) {
144                         return false;
145                     }
146                 } else if (!MatchComparatorHelper.layer3MatchEquals(statsMatch.getLayer3Match(), storedMatch.getLayer3Match())) {
147                     return false;
148                 }
149                 return true;
150             }
151         };
152     }
153
154     public static SimpleComparator<Match> createIp() {
155         return new SimpleComparator<Match>() {
156             /**
157              * Comparation by Ip
158              */
159             @Override
160             public boolean areObjectsEqual(Match statsMatch, Match storedMatch) {
161                 if (storedMatch == null) return false;
162                 if (storedMatch.getIpMatch() == null) {
163                     if (statsMatch.getIpMatch() != null) {
164                         return false;
165                     }
166                 } else if (!storedMatch.getIpMatch().equals(statsMatch.getIpMatch())) {
167                     return false;
168                 }
169                 return true;
170             }
171         };
172     }
173
174     public static SimpleComparator<Match> createInPort() {
175         return new SimpleComparator<Match>() {
176             /**
177              * Comparation by InPort
178              */
179             @Override
180             public boolean areObjectsEqual(Match statsMatch, Match storedMatch) {
181                 if (storedMatch == null) return false;
182                 if (storedMatch.getInPort() == null) {
183                     if (statsMatch.getInPort() != null) {
184                         return false;
185                     }
186                 } else if (!storedMatch.getInPort().equals(statsMatch.getInPort())) {
187                     return false;
188                 }
189                 return true;
190             }
191         };
192     }
193
194     public static SimpleComparator<Match> createInPhyPort() {
195         return new SimpleComparator<Match>() {
196             /**
197              * Comparation by InPhyPort
198              */
199             @Override
200             public boolean areObjectsEqual(Match statsMatch, Match storedMatch) {
201                 if (storedMatch == null) return false;
202                 if (storedMatch.getInPhyPort() == null) {
203                     if (statsMatch.getInPhyPort() != null) {
204                         return false;
205                     }
206                 } else if (!storedMatch.getInPhyPort().equals(statsMatch.getInPhyPort())) {
207                     return false;
208                 }
209                 return true;
210             }
211         };
212     }
213
214     public static SimpleComparator<Match> createEthernet() {
215         return new SimpleComparator<Match>() {
216             /**
217              * Comparation by Ethernet
218              */
219             @Override
220             public boolean areObjectsEqual(Match statsMatch, Match storedMatch) {
221                 if (storedMatch == null) return false;
222                 if (storedMatch.getEthernetMatch() == null) {
223                     if (statsMatch.getEthernetMatch() != null) {
224                         return false;
225                     }
226                 } else if (!MatchComparatorHelper.ethernetMatchEquals(statsMatch.getEthernetMatch(), storedMatch.getEthernetMatch())) {
227                     return false;
228                 }
229                 return true;
230             }
231         };
232     }
233
234     public static SimpleComparator<Match> createIcmpv4() {
235         return new SimpleComparator<Match>() {
236             /**
237              * Comparation by Icmpv4
238              */
239             @Override
240             public boolean areObjectsEqual(Match statsMatch, Match storedMatch) {
241                 if (storedMatch == null) return false;
242                 if (storedMatch.getIcmpv4Match() == null) {
243                     if (statsMatch.getIcmpv4Match() != null) {
244                         return false;
245                     }
246                 } else if (!storedMatch.getIcmpv4Match().equals(statsMatch.getIcmpv4Match())) {
247                     return false;
248                 }
249                 return true;
250             }
251         };
252     }
253
254 }