Merge "NxMatchInfo redesign"
[genius.git] / mdsalutil / mdsalutil-api / src / main / java / org / opendaylight / genius / mdsalutil / matches / MatchMetadata.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.matches;
9
10 import java.math.BigInteger;
11 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder;
12 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Metadata;
13 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.MetadataBuilder;
14
15 /**
16  * Metadata match.
17  */
18 public class MatchMetadata extends MatchInfoHelper<Metadata, MetadataBuilder> {
19
20     private final BigInteger metadata;
21     private final BigInteger mask;
22
23     public MatchMetadata(BigInteger metadata, BigInteger mask) {
24         this.metadata = metadata;
25         this.mask = mask;
26     }
27
28     @Override
29     protected void applyValue(MatchBuilder matchBuilder, Metadata value) {
30         matchBuilder.setMetadata(value);
31     }
32
33     @Override
34     protected void populateBuilder(MetadataBuilder builder) {
35         builder.setMetadata(metadata).setMetadataMask(mask);
36     }
37
38     public BigInteger getMetadata() {
39         return metadata;
40     }
41
42     public BigInteger getMask() {
43         return mask;
44     }
45
46     @Override
47     public boolean equals(Object other) {
48         if (this == other) {
49             return true;
50         }
51         if (other == null || getClass() != other.getClass()) {
52             return false;
53         }
54         if (!super.equals(other)) {
55             return false;
56         }
57
58         MatchMetadata that = (MatchMetadata) other;
59
60         if (metadata != null ? !metadata.equals(that.metadata) : that.metadata != null) {
61             return false;
62         }
63         return mask != null ? mask.equals(that.mask) : that.mask == null;
64     }
65
66     @Override
67     public int hashCode() {
68         int result = super.hashCode();
69         result = 31 * result + (metadata != null ? metadata.hashCode() : 0);
70         result = 31 * result + (mask != null ? mask.hashCode() : 0);
71         return result;
72     }
73
74     @Override
75     public String toString() {
76         return "MatchMetadata[metadata=" + metadata + ", mask=" + mask + "]";
77     }
78
79 }