Skip to content

armgit / core

Public Imported from GitHub
0

100% open-source IoT Platform - Integrate your devices, add intelligence, build custom apps

Added long coercion to Values

Rich Turner1dd888a043a9
diff --git a/model/src/main/java/org/openremote/model/value/Values.java b/model/src/main/java/org/openremote/model/value/Values.java
index 221a7dda9..50f8d3706 100644
--- a/model/src/main/java/org/openremote/model/value/Values.java
+++ b/model/src/main/java/org/openremote/model/value/Values.java
@@ -103,6 +103,16 @@ public class Values {
.map(Double::intValue);
}
+ /**
+ * Attempts to coerce the value into a long (where it makes sense)
+ */
+ public static Optional<Long> getLongCoerced(Value value) {
+
+ return convert(value, NumberValue.class)
+ .map(NumberValue::getNumber)
+ .map(Double::longValue);
+ }
+
public static Optional<ObjectValue> getObject(Value value) {
return cast(ObjectValue.class, value);
}