2 * Copyright (c) 2013, 2015 IBM Corporation and others. All rights reserved.
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
9 package org.opendaylight.openflowplugin.applications.statistics.manager.impl.helper;
11 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.Match;
13 * Provides comparator for comparing according to various {@link Match} attributes
16 public final class MatchComparatorFactory {
18 private MatchComparatorFactory() {
22 public static SimpleComparator<Match> createNull() {
23 return new SimpleComparator<Match>() {
25 * Comparation by whole object
28 public boolean areObjectsEqual(Match statsMatch, Match storedMatch) {
29 return (statsMatch == null) == (storedMatch == null);
34 public static SimpleComparator<Match> createVlan() {
35 return new SimpleComparator<Match>() {
40 public boolean areObjectsEqual(Match statsMatch, Match storedMatch) {
41 if (storedMatch == null) return false;
42 if (storedMatch.getVlanMatch() == null) {
43 if (statsMatch.getVlanMatch() != null) {
46 } else if (!storedMatch.getVlanMatch().equals(statsMatch.getVlanMatch())) {
54 public static SimpleComparator<Match> createTunnel() {
55 return new SimpleComparator<Match>() {
57 * Comparation by tunnel
60 public boolean areObjectsEqual(Match statsMatch, Match storedMatch) {
61 if (storedMatch == null) return false;
62 if (storedMatch.getTunnel() == null) {
63 if (statsMatch.getTunnel() != null) {
66 } else if (!storedMatch.getTunnel().equals(statsMatch.getTunnel())) {
74 public static SimpleComparator<Match> createProtocolMatchFields() {
75 return new SimpleComparator<Match>() {
77 * Comparation by protocol fields
80 public boolean areObjectsEqual(Match statsMatch, Match storedMatch) {
81 if (storedMatch == null) return false;
82 if (storedMatch.getProtocolMatchFields() == null) {
83 if (statsMatch.getProtocolMatchFields() != null) {
86 } else if (!storedMatch.getProtocolMatchFields().equals(statsMatch.getProtocolMatchFields())) {
94 public static SimpleComparator<Match> createMetadata() {
95 return new SimpleComparator<Match>() {
97 * Comparation by metadata
100 public boolean areObjectsEqual(Match statsMatch, Match storedMatch) {
101 if (storedMatch == null) return false;
102 if (storedMatch.getMetadata() == null) {
103 if (statsMatch.getMetadata() != null) {
106 } else if (!storedMatch.getMetadata().equals(statsMatch.getMetadata())) {
114 public static SimpleComparator<Match> createL4() {
115 return new SimpleComparator<Match>() {
117 * Comparation by layer4
120 public boolean areObjectsEqual(Match statsMatch, Match storedMatch) {
121 if (storedMatch == null) return false;
122 if (storedMatch.getLayer4Match() == null) {
123 if (statsMatch.getLayer4Match() != null) {
126 } else if (!storedMatch.getLayer4Match().equals(statsMatch.getLayer4Match())) {
134 public static SimpleComparator<Match> createL3() {
135 return new SimpleComparator<Match>() {
137 * Comparation by layer3
140 public boolean areObjectsEqual(Match statsMatch, Match storedMatch) {
141 if (storedMatch == null) return false;
142 if (storedMatch.getLayer3Match() == null) {
143 if (statsMatch.getLayer3Match() != null) {
146 } else if (!MatchComparatorHelper.layer3MatchEquals(statsMatch.getLayer3Match(), storedMatch.getLayer3Match())) {
154 public static SimpleComparator<Match> createIp() {
155 return new SimpleComparator<Match>() {
160 public boolean areObjectsEqual(Match statsMatch, Match storedMatch) {
161 if (storedMatch == null) return false;
162 if (storedMatch.getIpMatch() == null) {
163 if (statsMatch.getIpMatch() != null) {
166 } else if (!storedMatch.getIpMatch().equals(statsMatch.getIpMatch())) {
174 public static SimpleComparator<Match> createInPort() {
175 return new SimpleComparator<Match>() {
177 * Comparation by InPort
180 public boolean areObjectsEqual(Match statsMatch, Match storedMatch) {
181 if (storedMatch == null) return false;
182 if (storedMatch.getInPort() == null) {
183 if (statsMatch.getInPort() != null) {
186 } else if (!storedMatch.getInPort().equals(statsMatch.getInPort())) {
194 public static SimpleComparator<Match> createInPhyPort() {
195 return new SimpleComparator<Match>() {
197 * Comparation by InPhyPort
200 public boolean areObjectsEqual(Match statsMatch, Match storedMatch) {
201 if (storedMatch == null) return false;
202 if (storedMatch.getInPhyPort() == null) {
203 if (statsMatch.getInPhyPort() != null) {
206 } else if (!storedMatch.getInPhyPort().equals(statsMatch.getInPhyPort())) {
214 public static SimpleComparator<Match> createEthernet() {
215 return new SimpleComparator<Match>() {
217 * Comparation by Ethernet
220 public boolean areObjectsEqual(Match statsMatch, Match storedMatch) {
221 if (storedMatch == null) return false;
222 if (storedMatch.getEthernetMatch() == null) {
223 if (statsMatch.getEthernetMatch() != null) {
226 } else if (!MatchComparatorHelper.ethernetMatchEquals(statsMatch.getEthernetMatch(), storedMatch.getEthernetMatch())) {
234 public static SimpleComparator<Match> createIcmpv4() {
235 return new SimpleComparator<Match>() {
237 * Comparation by Icmpv4
240 public boolean areObjectsEqual(Match statsMatch, Match storedMatch) {
241 if (storedMatch == null) return false;
242 if (storedMatch.getIcmpv4Match() == null) {
243 if (statsMatch.getIcmpv4Match() != null) {
246 } else if (!storedMatch.getIcmpv4Match().equals(statsMatch.getIcmpv4Match())) {