@Override public int hashCode() { final int prime = 347; int result = 1; result = prime * result + length; result = prime * result + ((type == null) ? 0 : type.hashCode()); return result; }
/** * Given the output from toString(), create a new SNMPAction * * @param val * @return */ public static SNMPAction fromString(String val) { String tokens[] = val.split(";"); if (!tokens[0].equals("ofaction")) throw new IllegalArgumentException("expected 'ofaction' but got '" + tokens[0] + "'"); String type_tokens[] = tokens[1].split("="); String len_tokens[] = tokens[2].split("="); SNMPAction action = new SNMPAction(); action.setLength(Short.valueOf(len_tokens[1])); action.setType(SNMPActionType.valueOf(type_tokens[1])); return action; }
@Override public boolean equals(Object obj) { if (this == obj) { return true; } if (obj == null) { return false; } if (!(obj instanceof SNMPAction)) { return false; } SNMPAction other = (SNMPAction) obj; if (length != other.length) { return false; } if (type == null) { if (other.type != null) { return false; } } else if (!type.equals(other.type)) { return false; } return true; }
public void writeTo(ByteBuffer data) { data.putShort(type.getTypeValue()); data.putShort(length); // Note missing PAD, see MINIMUM_LENGTH comment for details }
public void readFrom(ByteBuffer data) { this.type = SNMPActionType.valueOf(data.getShort()); this.length = data.getShort(); // Note missing PAD, see MINIMUM_LENGTH comment for details }