]> gerrit.simantics Code Review - simantics/sysdyn.git/commitdiff
added value adapters to objmap
authorniemisto <niemisto@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Tue, 10 May 2011 05:05:01 +0000 (05:05 +0000)
committerniemisto <niemisto@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Tue, 10 May 2011 05:05:01 +0000 (05:05 +0000)
git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@20843 ac1ea38d-2e2b-0410-8846-a27921b304fc

org.simantics.objmap/src/org/simantics/objmap/rules/adapters/IdentityAdapter.java [new file with mode: 0644]
org.simantics.objmap/src/org/simantics/objmap/rules/adapters/ValueAdapter.java [new file with mode: 0644]
org.simantics.objmap/src/org/simantics/objmap/rules/range/AdaptedRangeAccessor.java [new file with mode: 0644]

diff --git a/org.simantics.objmap/src/org/simantics/objmap/rules/adapters/IdentityAdapter.java b/org.simantics.objmap/src/org/simantics/objmap/rules/adapters/IdentityAdapter.java
new file mode 100644 (file)
index 0000000..3d4b691
--- /dev/null
@@ -0,0 +1,15 @@
+package org.simantics.objmap.rules.adapters;\r
+\r
+public enum IdentityAdapter implements ValueAdapter {\r
+    INSTANCE;\r
+\r
+    @Override\r
+    public Object domainToRange(Object domainValue) {\r
+        return domainValue;\r
+    }\r
+\r
+    @Override\r
+    public Object rangeToDomain(Object rangeValue) {\r
+        return rangeValue;\r
+    }\r
+}\r
diff --git a/org.simantics.objmap/src/org/simantics/objmap/rules/adapters/ValueAdapter.java b/org.simantics.objmap/src/org/simantics/objmap/rules/adapters/ValueAdapter.java
new file mode 100644 (file)
index 0000000..c8d0d2d
--- /dev/null
@@ -0,0 +1,6 @@
+package org.simantics.objmap.rules.adapters;\r
+\r
+public interface ValueAdapter {\r
+    Object domainToRange(Object domainValue);\r
+    Object rangeToDomain(Object rangeValue);\r
+}\r
diff --git a/org.simantics.objmap/src/org/simantics/objmap/rules/range/AdaptedRangeAccessor.java b/org.simantics.objmap/src/org/simantics/objmap/rules/range/AdaptedRangeAccessor.java
new file mode 100644 (file)
index 0000000..a6df00b
--- /dev/null
@@ -0,0 +1,25 @@
+package org.simantics.objmap.rules.range;\r
+\r
+import org.simantics.objmap.MappingException;\r
+import org.simantics.objmap.rules.adapters.ValueAdapter;\r
+\r
+public class AdaptedRangeAccessor implements IRangeAccessor<Object> {\r
+    IRangeAccessor<Object> baseAccessor;\r
+    ValueAdapter adapter;\r
+    \r
+    public AdaptedRangeAccessor(IRangeAccessor<Object> baseAccessror,\r
+            ValueAdapter adapter) {\r
+        this.baseAccessor = baseAccessror;\r
+        this.adapter = adapter;\r
+    }\r
+\r
+    @Override\r
+    public Object get(Object element) throws MappingException {\r
+        return adapter.rangeToDomain(baseAccessor.get(element));    \r
+    }\r
+    \r
+    @Override\r
+    public boolean set(Object element, Object value) throws MappingException {\r
+        return baseAccessor.set(element, adapter.domainToRange(value));\r
+    }\r
+}\r