Make sure invokeOperation is set once
[controller.git] / opendaylight / adsal / sal / api / src / main / java / org / opendaylight / controller / sal / match / extensible / MatchField.java
1 /*
2  * Copyright (c) 2013 Cisco Systems, Inc. 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.controller.sal.match.extensible;
10
11 import java.io.Serializable;
12
13 import javax.xml.bind.annotation.XmlAccessType;
14 import javax.xml.bind.annotation.XmlAccessorType;
15 import javax.xml.bind.annotation.XmlElement;
16 import javax.xml.bind.annotation.XmlRootElement;
17
18 /**
19  * Represents the generic matching field object
20  */
21 @XmlRootElement
22 @XmlAccessorType(XmlAccessType.NONE)
23 @Deprecated
24 public abstract class MatchField<T> implements Cloneable, Serializable {
25     private static final long serialVersionUID = 1L;
26     private String type;
27
28     // To satisfy JAXB
29     @SuppressWarnings("unused")
30     private MatchField() {
31     }
32
33     public MatchField(String type) {
34         this.type = type;
35     }
36
37     @XmlElement(name = "type")
38     public String getType() {
39         return type;
40     }
41
42     /**
43      * Returns the value set for this match field
44      *
45      * @return
46      */
47     public abstract T getValue();
48
49     @XmlElement(name = "value")
50     protected abstract String getValueString();
51
52     /**
53      * Returns the mask value set for this field match A null mask means this is
54      * a full match
55      *
56      * @return
57      */
58     public abstract T getMask();
59
60     @XmlElement(name = "mask")
61     protected abstract String getMaskString();
62
63     /**
64      * Returns whether the field match configuration is valid or not
65      *
66      * @return true if valid, false otherwise
67      */
68     public abstract boolean isValid();
69
70     public abstract boolean hasReverse();
71
72     /**
73      * Returns the reverse match field. For example for a MatchField matching on
74      * source ip 1.1.1.1 it will return a MatchField matching on destination IP
75      * 1.1.1.1. For not reversable MatchField, a copy of this MatchField will be
76      * returned
77      *
78      * @return the correspondent reverse MatchField object or a copy of this
79      *         object if the field is not reversable
80      */
81     public abstract MatchField<T> getReverse();
82
83     /**
84      * Returns whether the match field is congruent with IPv6 frames
85      *
86      * @return true if congruent with IPv6 frames
87      */
88     public abstract boolean isV6();
89
90     @Override
91     public abstract MatchField<T> clone();
92
93     @Override
94     public int hashCode() {
95         final int prime = 31;
96         int result = 1;
97         result = prime * result + ((type == null) ? 0 : type.hashCode());
98         return result;
99     }
100
101     @Override
102     public boolean equals(Object obj) {
103         if (this == obj) {
104             return true;
105         }
106         if (obj == null) {
107             return false;
108         }
109         if (!(obj instanceof MatchField)) {
110             return false;
111         }
112         MatchField<?> other = (MatchField<?>) obj;
113         if (type == null) {
114             if (other.type != null) {
115                 return false;
116             }
117         } else if (!type.equals(other.type)) {
118             return false;
119         }
120         return true;
121     }
122
123     @Override
124     public String toString() {
125         return (getMask() == null) ? String.format("%s(%s)", getType(), getValueString()) :
126             String.format("%s(%s,%s)", getType(), getValueString(), getMaskString());
127     }
128
129 }