-package org.simantics.databoard.binding.impl;\r
-\r
-import org.simantics.databoard.binding.IntegerBinding;\r
-import org.simantics.databoard.binding.error.BindingException;\r
-import org.simantics.databoard.primitives.UnsignedInteger;\r
-import org.simantics.databoard.type.IntegerType;\r
-\r
-/**\r
- * Binding of {@link UnsignedInteger} to integer type.\r
- * This is bitwise binding, i.e. negative values bound to 0x100000000 + value.\r
- * \r
- * @author Toni Kalajainen <toni.kalajainen@iki.fi>\r
- */\r
-public abstract class UnsignedIntegerBinding extends IntegerBinding {\r
- \r
- UnsignedIntegerBinding(IntegerType type) {\r
- super(type);\r
- }\r
-\r
- public static class Immutable extends UnsignedIntegerBinding {\r
-\r
- public Immutable(IntegerType type) {\r
- super(type);\r
- }\r
- \r
- @Override\r
- public Object create(int value) throws BindingException {\r
- return UnsignedInteger.fromBits(value);\r
- }\r
-\r
- @Override\r
- public Object create(Integer value) throws BindingException {\r
- try {\r
- return UnsignedInteger.valueOf(value.intValue());\r
- } catch (java.lang.IllegalArgumentException e) {\r
- throw new BindingException( e );\r
- }\r
- }\r
-\r
- @Override\r
- public Object create(Number value) throws BindingException {\r
- try { \r
- return UnsignedInteger.valueOf(value.longValue());\r
- } catch (java.lang.IllegalArgumentException e) {\r
- throw new BindingException( e );\r
- }\r
- }\r
-\r
- @Override\r
- public Object create(String value) throws BindingException {\r
- try {\r
- return UnsignedInteger.valueOf( Long.valueOf(value) );\r
- } catch (java.lang.IllegalArgumentException e) {\r
- throw new BindingException( e );\r
- }\r
- } \r
- \r
- @Override\r
- public void setValue(Object obj, Number value) throws BindingException {\r
- throw new BindingException("UnsignedInteger is immutable class");\r
- }\r
-\r
- @Override\r
- public void setValue(Object obj, int value) throws BindingException {\r
- throw new BindingException("UnsignedInteger is immutable class");\r
- }\r
- \r
- @Override\r
- public boolean isImmutable() {\r
- return true;\r
- }\r
- \r
- @Override\r
- public boolean isInstance(Object obj) {\r
- return obj instanceof UnsignedInteger.Immutable;\r
- } \r
- }\r
- \r
- public static class Mutable extends UnsignedIntegerBinding {\r
-\r
- public Mutable(IntegerType type) {\r
- super(type);\r
- }\r
- \r
- @Override\r
- public Object create(int value) throws BindingException {\r
- return new UnsignedInteger.Mutable(value);\r
- }\r
-\r
- @Override\r
- public Object create(Integer value) throws BindingException {\r
- return new UnsignedInteger.Mutable(value);\r
- }\r
-\r
- @Override\r
- public Object create(Number value) throws BindingException {\r
- return UnsignedInteger.Mutable.fromBits(value.intValue());\r
- }\r
-\r
- @Override\r
- public Object create(String value) throws BindingException {\r
- return new UnsignedInteger.Mutable(value);\r
- }\r
-\r
- @Override\r
- public void setValue(Object obj, Number value) throws BindingException {\r
- UnsignedInteger.Mutable mi = (UnsignedInteger.Mutable) obj;\r
- mi.setBits(value.intValue());\r
- }\r
-\r
- @Override\r
- public void setValue(Object obj, int value) throws BindingException {\r
- UnsignedInteger.Mutable mi = (UnsignedInteger.Mutable) obj;\r
- mi.setBits(value);\r
- }\r
-\r
- @Override\r
- public boolean isImmutable() {\r
- return false;\r
- }\r
-\r
- @Override\r
- public boolean isInstance(Object obj) {\r
- return obj instanceof UnsignedInteger.Mutable;\r
- }\r
- \r
- }\r
-\r
- @Override\r
- public Integer getValue(Object obj) throws BindingException {\r
- return ((UnsignedInteger)obj).toBits();\r
- }\r
-\r
- @Override\r
- public int getValue_(Object obj) throws BindingException {\r
- return ((UnsignedInteger)obj).toBits();\r
- }\r
-\r
- @Override\r
- public String toString(Object value) throws BindingException {\r
- return value.toString();\r
- }\r
-\r
-\r
-}\r
+package org.simantics.databoard.binding.impl;
+
+import org.simantics.databoard.binding.IntegerBinding;
+import org.simantics.databoard.binding.error.BindingException;
+import org.simantics.databoard.primitives.UnsignedInteger;
+import org.simantics.databoard.type.IntegerType;
+
+/**
+ * Binding of {@link UnsignedInteger} to integer type.
+ * This is bitwise binding, i.e. negative values bound to 0x100000000 + value.
+ *
+ * @author Toni Kalajainen <toni.kalajainen@iki.fi>
+ */
+public abstract class UnsignedIntegerBinding extends IntegerBinding {
+
+ UnsignedIntegerBinding(IntegerType type) {
+ super(type);
+ }
+
+ public static class Immutable extends UnsignedIntegerBinding {
+
+ public Immutable(IntegerType type) {
+ super(type);
+ }
+
+ @Override
+ public Object create(int value) throws BindingException {
+ return UnsignedInteger.fromBits(value);
+ }
+
+ @Override
+ public Object create(Integer value) throws BindingException {
+ try {
+ return UnsignedInteger.valueOf(value.intValue());
+ } catch (java.lang.IllegalArgumentException e) {
+ throw new BindingException( e );
+ }
+ }
+
+ @Override
+ public Object create(Number value) throws BindingException {
+ try {
+ return UnsignedInteger.valueOf(value.longValue());
+ } catch (java.lang.IllegalArgumentException e) {
+ throw new BindingException( e );
+ }
+ }
+
+ @Override
+ public Object create(String value) throws BindingException {
+ try {
+ return UnsignedInteger.valueOf( Long.valueOf(value) );
+ } catch (java.lang.IllegalArgumentException e) {
+ throw new BindingException( e );
+ }
+ }
+
+ @Override
+ public void setValue(Object obj, Number value) throws BindingException {
+ throw new BindingException("UnsignedInteger is immutable class");
+ }
+
+ @Override
+ public void setValue(Object obj, int value) throws BindingException {
+ throw new BindingException("UnsignedInteger is immutable class");
+ }
+
+ @Override
+ public boolean isImmutable() {
+ return true;
+ }
+
+ @Override
+ public boolean isInstance(Object obj) {
+ return obj instanceof UnsignedInteger.Immutable;
+ }
+ }
+
+ public static class Mutable extends UnsignedIntegerBinding {
+
+ public Mutable(IntegerType type) {
+ super(type);
+ }
+
+ @Override
+ public Object create(int value) throws BindingException {
+ return new UnsignedInteger.Mutable(value);
+ }
+
+ @Override
+ public Object create(Integer value) throws BindingException {
+ return new UnsignedInteger.Mutable(value);
+ }
+
+ @Override
+ public Object create(Number value) throws BindingException {
+ return UnsignedInteger.Mutable.fromBits(value.intValue());
+ }
+
+ @Override
+ public Object create(String value) throws BindingException {
+ return new UnsignedInteger.Mutable(value);
+ }
+
+ @Override
+ public void setValue(Object obj, Number value) throws BindingException {
+ UnsignedInteger.Mutable mi = (UnsignedInteger.Mutable) obj;
+ mi.setBits(value.intValue());
+ }
+
+ @Override
+ public void setValue(Object obj, int value) throws BindingException {
+ UnsignedInteger.Mutable mi = (UnsignedInteger.Mutable) obj;
+ mi.setBits(value);
+ }
+
+ @Override
+ public boolean isImmutable() {
+ return false;
+ }
+
+ @Override
+ public boolean isInstance(Object obj) {
+ return obj instanceof UnsignedInteger.Mutable;
+ }
+
+ }
+
+ @Override
+ public Integer getValue(Object obj) throws BindingException {
+ return ((UnsignedInteger)obj).toBits();
+ }
+
+ @Override
+ public int getValue_(Object obj) throws BindingException {
+ return ((UnsignedInteger)obj).toBits();
+ }
+
+ @Override
+ public String toString(Object value) throws BindingException {
+ return value.toString();
+ }
+
+
+}