@Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + id; result = prime * result + ((type == null) ? 0 : type.hashCode()); if (type == Type.OPAQUE) { // Custom hashcode to handle byte arrays result = prime * result + ((value == null) ? 0 : Arrays.hashCode((byte[]) value)); } else { result = prime * result + ((value == null) ? 0 : value.hashCode()); } return result; }
public static LwM2mSingleResource newResource(int id, Object value, Type type) { switch (type) { case INTEGER: if (value instanceof Long) break; case FLOAT: if (value instanceof Double) break; case BOOLEAN: if (value instanceof Boolean) break; case OPAQUE: if (value instanceof byte[]) break; case STRING: if (value instanceof String) break; case TIME: if (value instanceof Date) break; throw new IllegalArgumentException("Value does not match the given datatype"); default: throw new IllegalArgumentException(String.format("Type %s is not supported", type.name())); } return new LwM2mSingleResource(id, value, type); }