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