MDSAL-API Migration
[genius.git] / mdsalutil / mdsalutil-api / src / main / java / org / opendaylight / genius / mdsalutil / nxmatches / NxMatchRegister.java
1 /*
2  * Copyright © 2017 Red Hat, Inc. and others.
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.genius.mdsalutil.nxmatches;
9
10 import com.google.common.collect.ImmutableBiMap;
11 import java.util.Map;
12 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.NxmNxReg3;
13 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.NxmNxReg4;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.NxmNxReg5;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.NxmNxReg6;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.NxmNxReg7;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.general.rev140714.ExtensionKey;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxAugMatchNodesNodeTableFlowBuilder;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxmNxReg3Key;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxmNxReg4Key;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxmNxReg5Key;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxmNxReg6Key;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxmNxReg7Key;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.nxm.nx.reg.grouping.NxmNxReg;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.nxm.nx.reg.grouping.NxmNxRegBuilder;
26
27 /**
28  * Nicira extension register match.
29  */
30 public class NxMatchRegister extends NxMatchInfoHelper<NxmNxReg, NxmNxRegBuilder> {
31     private static final Map<Class<? extends org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match
32             .rev140421.NxmNxReg>, Class<? extends ExtensionKey>> KEYS =
33             ImmutableBiMap.of(
34                     NxmNxReg3.class, NxmNxReg3Key.class,
35                     NxmNxReg4.class, NxmNxReg4Key.class,
36                     NxmNxReg5.class, NxmNxReg5Key.class,
37                     NxmNxReg6.class, NxmNxReg6Key.class,
38                     NxmNxReg7.class, NxmNxReg7Key.class
39                     );
40
41     private final Class<
42             ? extends org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.NxmNxReg> register;
43     private final long value;
44     private final Long mask;
45
46     public NxMatchRegister(
47             Class<? extends org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.NxmNxReg>
48             register, long value) {
49         this(register, value, null);
50     }
51
52     public NxMatchRegister(
53             Class<? extends org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.NxmNxReg>
54             register, long value, Long mask) {
55         super(KEYS.get(register));
56         if (!KEYS.containsKey(register)) {
57             throw new IllegalArgumentException("Unknown NXM register " + register);
58         }
59         this.register = register;
60         this.value = value;
61         this.mask = mask;
62     }
63
64     @Override
65     protected void applyValue(NxAugMatchNodesNodeTableFlowBuilder matchBuilder, NxmNxReg regValue) {
66         matchBuilder.setNxmNxReg(regValue);
67     }
68
69     @Override
70     protected void populateBuilder(NxmNxRegBuilder builder) {
71         builder.setReg(register).setValue(value).setMask(mask);
72     }
73
74     public Class<? extends org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.NxmNxReg>
75         getRegister() {
76         return register;
77     }
78
79     public long getValue() {
80         return value;
81     }
82
83     public Long getMask() {
84         return mask;
85     }
86
87     @Override
88     public boolean equals(Object other) {
89         if (this == other) {
90             return true;
91         }
92         if (other == null || getClass() != other.getClass()) {
93             return false;
94         }
95         if (!super.equals(other)) {
96             return false;
97         }
98
99         NxMatchRegister that = (NxMatchRegister) other;
100
101         if (value != that.value) {
102             return false;
103         }
104         if (register != null ? !register.equals(that.register) : that.register != null) {
105             return false;
106         }
107         return mask != null ? mask.equals(that.mask) : that.mask == null;
108     }
109
110     @Override
111     public int hashCode() {
112         int result = super.hashCode();
113         result = 31 * result + (register != null ? register.hashCode() : 0);
114         result = 31 * result + (int) (value ^ (value >>> 32));
115         result = 31 * result + (mask != null ? mask.hashCode() : 0);
116         return result;
117     }
118
119     @Override
120     public String toString() {
121         return "NxMatchRegister[" + register.getSimpleName() + ", " + value + (mask != null ? "/" + mask : "") + "]";
122     }
123 }