1 package org.simantics.databoard.binding.impl;
3 import org.simantics.databoard.binding.ByteBinding;
4 import org.simantics.databoard.binding.error.BindingException;
5 import org.simantics.databoard.primitives.UnsignedByte;
6 import org.simantics.databoard.type.ByteType;
9 * Binding of {@link UnsignedByte} to byte type.
11 * @author Toni Kalajainen <toni.kalajainen@iki.fi>
13 public abstract class UnsignedByteBinding extends ByteBinding {
15 UnsignedByteBinding(ByteType type) {
19 public static class Immutable extends UnsignedByteBinding {
21 public Immutable(ByteType type) {
26 public Object create(Number value) throws BindingException {
28 return UnsignedByte.valueOf(value.longValue());
29 } catch (java.lang.IllegalArgumentException e) {
30 throw new BindingException( e );
35 public Object create(String value) throws BindingException {
37 return UnsignedByte.valueOf( Long.valueOf(value) );
38 } catch (java.lang.IllegalArgumentException e) {
39 throw new BindingException( e );
44 public void setValue(Object obj, Number value) throws BindingException {
45 throw new BindingException("UnsignedByte is immutable class");
49 public boolean isImmutable() {
54 public boolean isInstance(Object obj) {
55 return obj instanceof UnsignedByte.Immutable;
59 public Object create(byte value) throws BindingException {
61 return UnsignedByte.valueOf(value);
62 } catch (java.lang.IllegalArgumentException e) {
63 throw new BindingException( e );
68 public Object create(Byte value) throws BindingException {
70 return UnsignedByte.valueOf(value);
71 } catch (java.lang.IllegalArgumentException e) {
72 throw new BindingException( e );
77 public void setValue(Object obj, byte value) throws BindingException {
78 throw new BindingException("UnsignedByte is immutable class");
83 public static class Mutable extends UnsignedByteBinding {
85 public Mutable(ByteType type) {
90 public Object create(Number value) throws BindingException {
91 return new UnsignedByte.Mutable(value.longValue());
95 public Object create(String value) throws BindingException {
96 return new UnsignedByte.Mutable(value);
100 public void setValue(Object obj, Number value) throws BindingException {
101 UnsignedByte.Mutable bb = (UnsignedByte.Mutable) obj;
102 bb.setBits(value.intValue());
106 public boolean isImmutable() {
111 public boolean isInstance(Object obj) {
112 return obj instanceof UnsignedByte.Mutable;
116 public Object create(byte value) throws BindingException {
117 return new UnsignedByte.Mutable(value);
121 public Object create(Byte value) throws BindingException {
122 return new UnsignedByte.Mutable(value);
126 public void setValue(Object obj, byte value) throws BindingException {
127 UnsignedByte.Mutable bb = (UnsignedByte.Mutable) obj;
133 public Byte getValue(Object obj) throws BindingException {
134 return (byte) ((UnsignedByte)obj).toBits();
138 public byte getValue_(Object obj) throws BindingException {
139 return (byte) ((UnsignedByte)obj).toBits();
143 public String toString(Object value) throws BindingException {
144 return value.toString();