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.UnsignedShort;
6 import org.simantics.databoard.type.IntegerType;
9 * Binding of {@link UnsignedShort} to integer type.
11 * @author Toni Kalajainen <toni.kalajainen@iki.fi>
13 public abstract class UnsignedShortBinding extends IntegerBinding {
15 UnsignedShortBinding(IntegerType type) {
19 public static class Immutable extends UnsignedShortBinding {
21 public Immutable(IntegerType type) {
26 public Object create(int value) throws BindingException {
28 return UnsignedShort.fromBits(value);
29 } catch (java.lang.IllegalArgumentException e) {
30 throw new BindingException( e );
35 public Object create(Integer value) throws BindingException {
37 return UnsignedShort.valueOf(value.intValue());
38 } catch (java.lang.IllegalArgumentException e) {
39 throw new BindingException( e );
44 public Object create(Number value) throws BindingException {
46 return UnsignedShort.valueOf(value.longValue());
47 } catch (java.lang.IllegalArgumentException e) {
48 throw new BindingException( e );
53 public Object create(String value) throws BindingException {
55 return UnsignedShort.valueOf( Long.valueOf(value) );
56 } catch (java.lang.IllegalArgumentException e) {
57 throw new BindingException( e );
62 public void setValue(Object obj, Number value) throws BindingException {
63 throw new BindingException("UnsignedShort is immutable class");
67 public void setValue(Object obj, int value) throws BindingException {
68 throw new BindingException("UnsignedShort is immutable class");
72 public boolean isImmutable() {
77 public boolean isInstance(Object obj) {
78 return obj instanceof UnsignedShort.Immutable;
84 public static class Mutable extends UnsignedShortBinding {
86 public Mutable(IntegerType type) {
91 public Object create(int value) throws BindingException {
93 return new UnsignedShort.Mutable(value);
94 } catch (java.lang.IllegalArgumentException e) {
95 throw new BindingException( e );
100 public Object create(Integer value) throws BindingException {
102 return new UnsignedShort.Mutable(value);
103 } catch (java.lang.IllegalArgumentException e) {
104 throw new BindingException( e );
109 public Object create(Number value) throws BindingException {
111 return UnsignedShort.Mutable.fromBits(value.intValue());
112 } catch (java.lang.IllegalArgumentException e) {
113 throw new BindingException( e );
118 public Object create(String value) throws BindingException {
120 return new UnsignedShort.Mutable(value);
121 } catch (java.lang.IllegalArgumentException e) {
122 throw new BindingException( e );
127 public void setValue(Object obj, Number value) throws BindingException {
128 UnsignedShort.Mutable mi = (UnsignedShort.Mutable) obj;
129 mi.setBits(value.intValue());
133 public void setValue(Object obj, int value) throws BindingException {
134 UnsignedShort.Mutable mi = (UnsignedShort.Mutable) obj;
139 public boolean isImmutable() {
144 public boolean isInstance(Object obj) {
145 return obj instanceof UnsignedShort.Mutable;
151 public Integer getValue(Object obj) throws BindingException {
152 return ((UnsignedShort)obj).toBits();
156 public int getValue_(Object obj) throws BindingException {
157 return ((UnsignedShort)obj).toBits();
161 public String toString(Object value) throws BindingException {
162 return value.toString();