1 package org.simantics.databoard.binding.impl;
3 import org.simantics.databoard.binding.IntegerBinding;
4 import org.simantics.databoard.binding.error.BindingException;
5 import org.simantics.databoard.primitives.UnsignedInteger;
6 import org.simantics.databoard.type.IntegerType;
9 * Binding of {@link UnsignedInteger} to integer type.
10 * This is bitwise binding, i.e. negative values bound to 0x100000000 + value.
12 * @author Toni Kalajainen <toni.kalajainen@iki.fi>
14 public abstract class UnsignedIntegerBinding extends IntegerBinding {
16 UnsignedIntegerBinding(IntegerType type) {
20 public static class Immutable extends UnsignedIntegerBinding {
22 public Immutable(IntegerType type) {
27 public Object create(int value) throws BindingException {
28 return UnsignedInteger.fromBits(value);
32 public Object create(Integer value) throws BindingException {
34 return UnsignedInteger.valueOf(value.intValue());
35 } catch (java.lang.IllegalArgumentException e) {
36 throw new BindingException( e );
41 public Object create(Number value) throws BindingException {
43 return UnsignedInteger.valueOf(value.longValue());
44 } catch (java.lang.IllegalArgumentException e) {
45 throw new BindingException( e );
50 public Object create(String value) throws BindingException {
52 return UnsignedInteger.valueOf( Long.valueOf(value) );
53 } catch (java.lang.IllegalArgumentException e) {
54 throw new BindingException( e );
59 public void setValue(Object obj, Number value) throws BindingException {
60 throw new BindingException("UnsignedInteger is immutable class");
64 public void setValue(Object obj, int value) throws BindingException {
65 throw new BindingException("UnsignedInteger is immutable class");
69 public boolean isImmutable() {
74 public boolean isInstance(Object obj) {
75 return obj instanceof UnsignedInteger.Immutable;
79 public static class Mutable extends UnsignedIntegerBinding {
81 public Mutable(IntegerType type) {
86 public Object create(int value) throws BindingException {
87 return new UnsignedInteger.Mutable(value);
91 public Object create(Integer value) throws BindingException {
92 return new UnsignedInteger.Mutable(value);
96 public Object create(Number value) throws BindingException {
97 return UnsignedInteger.Mutable.fromBits(value.intValue());
101 public Object create(String value) throws BindingException {
102 return new UnsignedInteger.Mutable(value);
106 public void setValue(Object obj, Number value) throws BindingException {
107 UnsignedInteger.Mutable mi = (UnsignedInteger.Mutable) obj;
108 mi.setBits(value.intValue());
112 public void setValue(Object obj, int value) throws BindingException {
113 UnsignedInteger.Mutable mi = (UnsignedInteger.Mutable) obj;
118 public boolean isImmutable() {
123 public boolean isInstance(Object obj) {
124 return obj instanceof UnsignedInteger.Mutable;
130 public Integer getValue(Object obj) throws BindingException {
131 return ((UnsignedInteger)obj).toBits();
135 public int getValue_(Object obj) throws BindingException {
136 return ((UnsignedInteger)obj).toBits();
140 public String toString(Object value) throws BindingException {
141 return value.toString();