2 * Copyright (c) 2016 Ericsson India Global Services Pvt Ltd. 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
8 package org.opendaylight.genius.mdsalutil;
10 import com.google.common.base.MoreObjects;
11 import java.io.Serializable;
12 import java.math.BigInteger;
13 import java.util.Arrays;
15 import java.util.Objects;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder;
17 import org.opendaylight.yangtools.util.EvenMoreObjects;
19 public class MatchInfo implements Serializable, MatchInfoBase {
20 private static final long serialVersionUID = 1L;
22 private final MatchFieldType m_matchField;
23 private final long[] m_alMatchValues;
24 private final BigInteger[] m_aBigIntValues;
25 private final String[] m_asMatchValues;
27 public MatchInfo(MatchFieldType matchField, long[] alMatchValues) {
28 m_matchField = matchField;
29 m_alMatchValues = alMatchValues;
30 m_aBigIntValues = null;
31 m_asMatchValues = null;
34 public MatchInfo(MatchFieldType matchField, BigInteger[] alBigMatchValues) {
35 m_matchField = matchField;
36 m_alMatchValues = null;
37 m_aBigIntValues = alBigMatchValues;
38 m_asMatchValues = null;
41 public MatchInfo(MatchFieldType matchField, String[] alStringMatchValues) {
42 m_matchField = matchField;
43 m_alMatchValues = null;
44 m_aBigIntValues = null;
45 m_asMatchValues = alStringMatchValues;
49 public void createInnerMatchBuilder(Map<Class<?>, Object> mapMatchBuilder) {
50 m_matchField.createInnerMatchBuilder(this, mapMatchBuilder);
54 public void setMatch(MatchBuilder matchBuilder, Map<Class<?>, Object> mapMatchBuilder) {
55 m_matchField.setMatch(matchBuilder, this, mapMatchBuilder);
58 public MatchFieldType getMatchField() {
62 public long[] getMatchValues() {
63 return m_alMatchValues;
66 public BigInteger[] getBigMatchValues() {
67 return m_aBigIntValues;
70 public String[] getStringMatchValues() {
71 return m_asMatchValues;
75 public String toString() {
76 return MoreObjects.toStringHelper(this).omitNullValues().add("matchField", m_matchField)
77 .add("matchValues", Arrays.toString(m_alMatchValues))
78 .add("bigMatchValues", Arrays.deepToString(m_aBigIntValues))
79 .add("stringMatchValues", Arrays.deepToString(m_asMatchValues)).toString();
83 public int hashCode() {
84 // BEWARE, Caveat Emptor: Array ([]) type fields must use
85 // Arrays.hashCode(). deepHashCode() would have to be used for nested
87 return Objects.hash(m_matchField, Arrays.hashCode(m_alMatchValues),
88 Arrays.hashCode(m_aBigIntValues), Arrays.hashCode(m_asMatchValues));
92 public boolean equals(Object obj) {
93 // BEWARE, Caveat Emptor: Array ([]) type fields must use
94 // Arrays.equals(). deepEquals() would have to be used for nested
95 // arrays. Use == only for primitive types; if ever changing
96 // those field types, must change to Objects.equals.
97 return EvenMoreObjects.equalsHelper(this, obj,
98 (self, other) -> Objects.equals(self.m_matchField, other.m_matchField)
99 && Arrays.equals(self.m_alMatchValues, other.m_alMatchValues)
100 && Arrays.equals(self.m_aBigIntValues, other.m_aBigIntValues)
101 && Arrays.equals(self.m_asMatchValues, other.m_asMatchValues));