From c907e9cc06f9ea2cafe77c656a04d8d05a51b5b0 Mon Sep 17 00:00:00 2001 From: niemisto Date: Tue, 10 May 2011 05:05:01 +0000 Subject: [PATCH] added value adapters to objmap git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@20843 ac1ea38d-2e2b-0410-8846-a27921b304fc --- .../rules/adapters/IdentityAdapter.java | 15 +++++++++++ .../objmap/rules/adapters/ValueAdapter.java | 6 +++++ .../rules/range/AdaptedRangeAccessor.java | 25 +++++++++++++++++++ 3 files changed, 46 insertions(+) create mode 100644 org.simantics.objmap/src/org/simantics/objmap/rules/adapters/IdentityAdapter.java create mode 100644 org.simantics.objmap/src/org/simantics/objmap/rules/adapters/ValueAdapter.java create mode 100644 org.simantics.objmap/src/org/simantics/objmap/rules/range/AdaptedRangeAccessor.java 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)); + } +} -- 2.47.1