blob: 433ca9d27b58af735ed8c51a62aa8db47d7fe369 [file] [log] [blame]
Andreas Wundsam40e14f72013-05-06 14:49:08 -07001package org.openflow.types;
2
Andreas Wundsam40e14f72013-05-06 14:49:08 -07003
Yotam Harchol161a5d52013-07-25 17:17:48 -07004
Yotam Harchol5c9d6f42013-08-01 11:09:20 -07005public class Masked<T extends OFValueType<T>> implements OFValueType<Masked<T>> {
Yotam Harchold7b84202013-07-26 16:08:10 -07006 protected T value;
7 protected T mask;
Yotam Harchol161a5d52013-07-25 17:17:48 -07008
Yotam Harchold7b84202013-07-26 16:08:10 -07009 protected Masked(T value, T mask) {
Yotam Harchol5c9d6f42013-08-01 11:09:20 -070010 this.value = value.applyMask(mask);
Yotam Harchol161a5d52013-07-25 17:17:48 -070011 this.mask = mask;
12 }
13
14 public T getValue() {
15 return value;
16 }
17
18 public T getMask() {
19 return mask;
20 }
Yotam Harcholfb4bfb92013-08-01 14:02:04 -070021
22 public static <T extends OFValueType<T>> Masked<T> of(T value, T mask) {
23 return new Masked<T>(value, mask);
24 }
Yotam Harchol161a5d52013-07-25 17:17:48 -070025
26 @Override
27 public int getLength() {
28 return this.value.getLength() + this.mask.getLength();
29 }
Yotam Harchol161a5d52013-07-25 17:17:48 -070030
31 @Override
32 public boolean equals(Object obj) {
33 if (!(obj instanceof Masked<?>))
34 return false;
35 Masked<?> mobj = (Masked<?>)obj;
36 return this.value.equals(mobj.value) && this.mask.equals(mobj.mask);
37 }
38
39 @Override
40 public int hashCode() {
41 final int prime = 59;
42 int result = 1;
43 result = prime * result + this.value.hashCode();
44 result = prime * result + this.mask.hashCode();
45 return result;
46 }
47
48 @Override
49 public String toString() {
Yotam Harchold7b84202013-07-26 16:08:10 -070050 // General representation: value/mask
51 StringBuilder sb = new StringBuilder();
52 sb.append(value.toString()).append('/').append(mask.toString());
53 return sb.toString();
Yotam Harchol161a5d52013-07-25 17:17:48 -070054 }
Yotam Harchol5c9d6f42013-08-01 11:09:20 -070055
56 @Override
57 public Masked<T> applyMask(Masked<T> mask) {
58 return this;
59 }
Yotam Harchol161a5d52013-07-25 17:17:48 -070060
Andreas Wundsam40e14f72013-05-06 14:49:08 -070061}