X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.databoard%2Fsrc%2Forg%2Fsimantics%2Fdataboard%2Fbinding%2Fimpl%2FUnsignedIntegerBinding.java;h=f0602981206c2cf5d53f17c9246f5a498f929321;hb=refs%2Fchanges%2F65%2F2565%2F2;hp=e21e9d2c3ee6850d003751bab8aa20a8f84e3d61;hpb=969bd23cab98a79ca9101af33334000879fb60c5;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.databoard/src/org/simantics/databoard/binding/impl/UnsignedIntegerBinding.java b/bundles/org.simantics.databoard/src/org/simantics/databoard/binding/impl/UnsignedIntegerBinding.java index e21e9d2c3..f06029812 100644 --- a/bundles/org.simantics.databoard/src/org/simantics/databoard/binding/impl/UnsignedIntegerBinding.java +++ b/bundles/org.simantics.databoard/src/org/simantics/databoard/binding/impl/UnsignedIntegerBinding.java @@ -1,145 +1,145 @@ -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 - */ -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(); - } - - -} +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 + */ +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(); + } + + +}