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