public PropertySetBuilder(PropertySet propertySet) throws SparkplugInvalidTypeException { this.propertyMap = new HashMap<String, PropertyValue>(); for (String name : propertySet.getNames()) { PropertyValue value = propertySet.getPropertyValue(name); propertyMap.put(name, new PropertyValue(value.getType(), value.getValue())); } }
@Override public boolean equals(Object object) { if (this == object) { return true; } if (object == null || this.getClass() != object.getClass()) { return false; } PropertyValue propValue = (PropertyValue) object; return Objects.equals(type, propValue.getType()) && Objects.equals(value, propValue.getValue()); }
private Map<String, PropertyValue> newProps(boolean withPropTypes) throws SparkplugException { Random random = new Random(); Map<String, PropertyValue> propMap = new HashMap<String, PropertyValue>(); propMap.put("PropInt8", new PropertyValue(PropertyDataType.Int8, (byte)random.nextInt())); propMap.put("PropInt16", new PropertyValue(PropertyDataType.Int16, (short)random.nextInt())); propMap.put("PropInt32", new PropertyValue(PropertyDataType.Int32, random.nextInt())); propMap.put("PropInt64", new PropertyValue(PropertyDataType.Int64, random.nextLong())); propMap.put("PropUInt8", new PropertyValue(PropertyDataType.UInt8, (short)random.nextInt())); propMap.put("PropUInt16", new PropertyValue(PropertyDataType.UInt16, random.nextInt())); propMap.put("PropUInt32", new PropertyValue(PropertyDataType.UInt32, random.nextLong())); propMap.put("PropUInt64", new PropertyValue(PropertyDataType.UInt64, BigInteger.valueOf(random.nextLong()))); propMap.put("PropFloat", new PropertyValue(PropertyDataType.Float, random.nextFloat())); propMap.put("PropDouble", new PropertyValue(PropertyDataType.Double, random.nextDouble())); propMap.put("PropBoolean", new PropertyValue(PropertyDataType.Boolean, random.nextBoolean())); propMap.put("PropString", new PropertyValue(PropertyDataType.String, newUUID())); propMap.put("PropDateTime", new PropertyValue(PropertyDataType.DateTime, new Date())); propMap.put("PropText", new PropertyValue(PropertyDataType.Text, newUUID())); if (withPropTypes) { propMap.put("PropPropertySet", new PropertyValue(PropertyDataType.PropertySet, new PropertySetBuilder() .addProperties(newProps(false)) .createPropertySet())); List<PropertySet> propsList = new ArrayList<PropertySet>(); propsList.add(new PropertySetBuilder().addProperties(newProps(false)).createPropertySet()); propsList.add(new PropertySetBuilder().addProperties(newProps(false)).createPropertySet()); propsList.add(new PropertySetBuilder().addProperties(newProps(false)).createPropertySet()); propMap.put("PropPropertySetList", new PropertyValue(PropertyDataType.PropertySetList, propsList)); } return propMap; }
private Map<String, PropertyValue> convertProperties(SparkplugBProto.Payload.PropertySet decodedPropSet) throws SparkplugInvalidTypeException, Exception { Map<String, PropertyValue> map = new HashMap<String, PropertyValue>(); List<String> keys = decodedPropSet.getKeysList(); List<SparkplugBProto.Payload.PropertyValue> values = decodedPropSet.getValuesList(); for (int i = 0; i < keys.size(); i++) { SparkplugBProto.Payload.PropertyValue value = values.get(i); map.put(keys.get(i), new PropertyValue(PropertyDataType.fromInteger(value.getType()), getPropertyValue(value))); } return map; }
SparkplugBProto.Payload.PropertyValue.Builder builder = SparkplugBProto.Payload.PropertyValue.newBuilder(); PropertyValue value = map.get(key); PropertyDataType type = value.getType(); builder.setType(type.toIntValue()); if (value.getValue() == null) { builder.setIsNull(true); } else { switch (type) { case Boolean: builder.setBooleanValue((Boolean) value.getValue()); break; case DateTime: builder.setLongValue(((Date) value.getValue()).getTime()); break; case Double: builder.setDoubleValue((Double) value.getValue()); break; case Float: builder.setFloatValue((Float) value.getValue()); break; case Int8: builder.setIntValue((Byte) value.getValue()); break; case Int16: case UInt8: builder.setIntValue((Short) value.getValue()); break; case Int32: case UInt16:
.addProperty("engUnit", new PropertyValue(PropertyDataType.String, "My Units")) .addProperty("engLow", new PropertyValue(PropertyDataType.Double, 1.0)) .addProperty("engHigh", new PropertyValue(PropertyDataType.Double, 10.0))
.addProperty("engUnit", new PropertyValue(PropertyDataType.String, "My Units")) .addProperty("engHigh", new PropertyValue(PropertyDataType.Int32, Integer.MAX_VALUE)) .addProperty("engLow", new PropertyValue(PropertyDataType.Int32, Integer.MIN_VALUE)) .createPropertySet()) .createMetric());
.addProperty("engUnit", new PropertyValue(PropertyDataType.String, "My Units")) .addProperty("engLow", new PropertyValue(PropertyDataType.Double, 1.0)) .addProperty("engHigh", new PropertyValue(PropertyDataType.Double, 10.0))