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