xinwu | ed8d558 | 2013-09-18 17:19:31 -0700 | [diff] [blame] | 1 | package org.projectfloodlight.openflow.types; |
| 2 | |
| 3 | import javax.annotation.concurrent.Immutable; |
| 4 | |
| 5 | @Immutable |
| 6 | public class Metadata { |
| 7 | static final int LENGTH = 4; |
Andreas Wundsam | b75c4ad | 2013-09-23 14:45:35 -0700 | [diff] [blame] | 8 | |
| 9 | private final static int NONE_VAL = 0; |
| 10 | public final static Metadata NONE = new Metadata(NONE_VAL); |
| 11 | |
xinwu | ed8d558 | 2013-09-18 17:19:31 -0700 | [diff] [blame] | 12 | private final int rawValue; |
| 13 | |
| 14 | private Metadata(final int rawValue) { |
| 15 | this.rawValue = rawValue; |
| 16 | } |
| 17 | |
| 18 | public static Metadata of(final int raw) { |
Andreas Wundsam | b75c4ad | 2013-09-23 14:45:35 -0700 | [diff] [blame] | 19 | if(raw == NONE_VAL) |
| 20 | return NONE; |
| 21 | |
xinwu | ed8d558 | 2013-09-18 17:19:31 -0700 | [diff] [blame] | 22 | return new Metadata(raw); |
| 23 | } |
| 24 | |
| 25 | public int getInt() { |
| 26 | return rawValue; |
| 27 | } |
| 28 | |
| 29 | public int getLength() { |
| 30 | return LENGTH; |
| 31 | } |
| 32 | |
| 33 | @Override |
| 34 | public int hashCode() { |
| 35 | final int prime = 31; |
| 36 | int result = 1; |
| 37 | result = prime * result + rawValue; |
| 38 | return result; |
| 39 | } |
| 40 | |
| 41 | @Override |
| 42 | public boolean equals(Object obj) { |
| 43 | if (this == obj) |
| 44 | return true; |
| 45 | if (obj == null) |
| 46 | return false; |
| 47 | if (getClass() != obj.getClass()) |
| 48 | return false; |
| 49 | Metadata other = (Metadata) obj; |
| 50 | if (rawValue != other.rawValue) |
| 51 | return false; |
| 52 | return true; |
| 53 | } |
| 54 | |
| 55 | @Override |
| 56 | public String toString() { |
| 57 | return Integer.toString(rawValue); |
| 58 | } |
| 59 | } |