public static ReadResponse success(int resourceId, Map<Integer, ?> value, Type type) { return new ReadResponse(ResponseCode.CONTENT, LwM2mMultipleResource.newResource(resourceId, value, type), null); }
public static LwM2mMultipleResource newBooleanResource(int id, Map<Integer, Boolean> values) { Validate.noNullElements(values.values()); return new LwM2mMultipleResource(id, values, Type.BOOLEAN); }
@Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + id; result = prime * result + ((type == null) ? 0 : type.hashCode()); result = prime * result + ((values == null) ? 0 : internalHashCode(values)); return result; }
@Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; LwM2mMultipleResource other = (LwM2mMultipleResource) obj; if (id != other.id) return false; if (type != other.type) return false; if (values == null) { if (other.values != null) return false; // Custom equals to handle byte arrays } else if (!internalMapEquals(values, other.values)) return false; return true; }
/** * Request to write a <b>Multi-Instance Resource</b> using the TLV content format. * * @param objectId the id of the object to write. * @param objectInstanceId the id of the object instance to write. * @param resourceId the id of the resource to write. * @param values the list of resource instance (id->value) to write. * @param type the data type of the resource. * @exception InvalidRequestException if parameters are invalid. */ public WriteRequest(int objectId, int objectInstanceId, int resourceId, Map<Integer, ?> values, Type type) throws InvalidRequestException { this(Mode.REPLACE, ContentFormat.TLV, new LwM2mPath(objectId, objectInstanceId, resourceId), LwM2mMultipleResource.newResource(resourceId, values, type)); }
public static LwM2mMultipleResource newObjectLinkResource(int id, Map<Integer, ObjectLink> values) { Validate.noNullElements(values.values()); return new LwM2mMultipleResource(id, values, Type.OBJLNK); }
/** * Request to write a <b>Multi-Instance Resource</b>. * * @param contentFormat Format of the payload (TLV or JSON). * @param objectId the id of the object to write. * @param objectInstanceId the id of the object instance to write. * @param resourceId the id of the resource to write. * @param values the list of resource instance (id->value) to write. * @param type the data type of the resource. * @exception InvalidRequestException if bad @{link ContentFormat} format was used. * */ public WriteRequest(ContentFormat contentFormat, int objectId, int objectInstanceId, int resourceId, Map<Integer, ?> values, Type type) throws InvalidRequestException { this(Mode.REPLACE, contentFormat, new LwM2mPath(objectId, objectInstanceId, resourceId), LwM2mMultipleResource.newResource(resourceId, values, type)); }
public static LwM2mMultipleResource newStringResource(int id, Map<Integer, String> values) { Validate.noNullElements(values.values()); return new LwM2mMultipleResource(id, values, Type.STRING); }
node = LwM2mMultipleResource.newResource(id, values, expectedType); } else { throw new JsonParseException("Invalid node element");
public static LwM2mMultipleResource newFloatResource(int id, Map<Integer, Double> values) { Validate.noNullElements(values.values()); return new LwM2mMultipleResource(id, values, Type.FLOAT); }
return LwM2mMultipleResource.newResource(id, values, type);
public static LwM2mMultipleResource newDateResource(int id, Map<Integer, Date> values) { Validate.noNullElements(values.values()); return new LwM2mMultipleResource(id, values, Type.TIME); }
return LwM2mMultipleResource.newResource(id, values, type);
public static LwM2mMultipleResource newIntegerResource(int id, Map<Integer, Long> values) { Validate.noNullElements(values.values()); return new LwM2mMultipleResource(id, values, Type.INTEGER); }
parseJsonValue(e.getValue().getResourceValue(), expectedType, resourcePath)); LwM2mResource resource = LwM2mMultipleResource.newResource(resourcePath.getResourceId(), values, expectedType); LwM2mResource previousRes = lwM2mResourceMap.put(resourcePath.getResourceId(), resource); Type resourceType = getResourceType(baseName, model, null); lwM2mResourceMap.put(baseName.getResourceId(), LwM2mMultipleResource .newResource(baseName.getResourceId(), new HashMap<Integer, Object>(), resourceType));
public static LwM2mMultipleResource newBinaryResource(int id, Map<Integer, byte[]> values) { Validate.noNullElements(values.values()); return new LwM2mMultipleResource(id, values, Type.OPAQUE); }
return LwM2mMultipleResource.newResource(resourceModel.id, values, resourceModel.type);
public static LwM2mMultipleResource newResource(int id, Map<Integer, ?> values, Type type) { switch (type) { case INTEGER: Validate.allElementsOfType(values.values(), Long.class); break; case FLOAT: Validate.allElementsOfType(values.values(), Double.class); break; case BOOLEAN: Validate.allElementsOfType(values.values(), Boolean.class); break; case OPAQUE: Validate.allElementsOfType(values.values(), byte[].class); break; case STRING: Validate.allElementsOfType(values.values(), String.class); break; case TIME: Validate.allElementsOfType(values.values(), Date.class); break; case OBJLNK: Validate.allElementsOfType(values.values(), ObjectLink.class); break; default: throw new IllegalArgumentException(String.format("Type %s is not supported", type.name())); } return new LwM2mMultipleResource(id, values, type); }
private static LwM2mResource parseResourceTlv(Tlv tlv, LwM2mPath resourcePath, LwM2mModel model) throws CodecException { Type expectedType = getResourceType(resourcePath, model); Integer resourceId = tlv.getIdentifier(); switch (tlv.getType()) { case MULTIPLE_RESOURCE: return LwM2mMultipleResource.newResource(resourceId, parseTlvValues(tlv.getChildren(), expectedType, resourcePath), expectedType); case RESOURCE_VALUE: return LwM2mSingleResource.newResource(resourceId, parseTlvValue(tlv.getValue(), expectedType, resourcePath), expectedType); default: throw new CodecException("Invalid TLV type %s for resource %s", tlv.getType(), resourcePath); } }
} else { Type expectedRscType = getResourceType(path, model); return (T) LwM2mMultipleResource.newResource(path.getResourceId(), parseTlvValues(tlvs, expectedRscType, path), expectedRscType);