From: niemisto Date: Tue, 10 May 2011 05:05:01 +0000 (+0000) Subject: added value adapters to objmap X-Git-Tag: simantics-1.4RC1~15 X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=c907e9cc06f9ea2cafe77c656a04d8d05a51b5b0;p=simantics%2Fsysdyn.git added value adapters to objmap git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@20843 ac1ea38d-2e2b-0410-8846-a27921b304fc --- 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 index 00000000..3d4b6913 --- /dev/null +++ b/org.simantics.objmap/src/org/simantics/objmap/rules/adapters/IdentityAdapter.java @@ -0,0 +1,15 @@ +package org.simantics.objmap.rules.adapters; + +public enum IdentityAdapter implements ValueAdapter { + INSTANCE; + + @Override + public Object domainToRange(Object domainValue) { + return domainValue; + } + + @Override + public Object rangeToDomain(Object rangeValue) { + return rangeValue; + } +} 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 index 00000000..c8d0d2d0 --- /dev/null +++ b/org.simantics.objmap/src/org/simantics/objmap/rules/adapters/ValueAdapter.java @@ -0,0 +1,6 @@ +package org.simantics.objmap.rules.adapters; + +public interface ValueAdapter { + Object domainToRange(Object domainValue); + Object rangeToDomain(Object rangeValue); +} 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 index 00000000..a6df00b0 --- /dev/null +++ b/org.simantics.objmap/src/org/simantics/objmap/rules/range/AdaptedRangeAccessor.java @@ -0,0 +1,25 @@ +package org.simantics.objmap.rules.range; + +import org.simantics.objmap.MappingException; +import org.simantics.objmap.rules.adapters.ValueAdapter; + +public class AdaptedRangeAccessor implements IRangeAccessor { + IRangeAccessor baseAccessor; + ValueAdapter adapter; + + public AdaptedRangeAccessor(IRangeAccessor baseAccessror, + ValueAdapter adapter) { + this.baseAccessor = baseAccessror; + this.adapter = adapter; + } + + @Override + public Object get(Object element) throws MappingException { + return adapter.rangeToDomain(baseAccessor.get(element)); + } + + @Override + public boolean set(Object element, Object value) throws MappingException { + return baseAccessor.set(element, adapter.domainToRange(value)); + } +}