m-chrzan.xyz
aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/pl/edu/mimuw/cloudatlas/model
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/pl/edu/mimuw/cloudatlas/model')
-rw-r--r--src/main/java/pl/edu/mimuw/cloudatlas/model/AttributesUtil.java21
-rw-r--r--src/main/java/pl/edu/mimuw/cloudatlas/model/ValueUtils.java7
2 files changed, 28 insertions, 0 deletions
diff --git a/src/main/java/pl/edu/mimuw/cloudatlas/model/AttributesUtil.java b/src/main/java/pl/edu/mimuw/cloudatlas/model/AttributesUtil.java
new file mode 100644
index 0000000..cd2ae91
--- /dev/null
+++ b/src/main/java/pl/edu/mimuw/cloudatlas/model/AttributesUtil.java
@@ -0,0 +1,21 @@
+package pl.edu.mimuw.cloudatlas.model;
+
+import java.util.Iterator;
+import java.util.Map.Entry;
+
+public class AttributesUtil {
+ public static void transferAttributes(AttributesMap fromAttributes, AttributesMap toAttributes) {
+ Iterator<Entry<Attribute, Value>> iterator = toAttributes.iterator();
+ while (iterator.hasNext()) {
+ Entry<Attribute, Value> entry = iterator.next();
+ Attribute attribute = entry.getKey();
+ Value newValue = fromAttributes.getOrNull(attribute);
+ if (newValue == null) {
+ iterator.remove();
+ }
+ }
+ for (Entry<Attribute, Value> entry : fromAttributes) {
+ toAttributes.addOrChange(entry.getKey(), entry.getValue());
+ }
+ }
+}
diff --git a/src/main/java/pl/edu/mimuw/cloudatlas/model/ValueUtils.java b/src/main/java/pl/edu/mimuw/cloudatlas/model/ValueUtils.java
new file mode 100644
index 0000000..01a45b5
--- /dev/null
+++ b/src/main/java/pl/edu/mimuw/cloudatlas/model/ValueUtils.java
@@ -0,0 +1,7 @@
+package pl.edu.mimuw.cloudatlas.model;
+
+public class ValueUtils {
+ public static boolean valueNonNullOfType(Value value, Type type) {
+ return value != null && !value.isNull() && value.getType().isCompatible(type);
+ }
+}