]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.databoard/src/org/simantics/databoard/binding/impl/UnsignedShortBinding.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.databoard / src / org / simantics / databoard / binding / impl / UnsignedShortBinding.java
1 package org.simantics.databoard.binding.impl;\r
2 \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
7 \r
8 /**\r
9  * Binding of {@link UnsignedShort} to integer type.\r
10  * \r
11  * @author Toni Kalajainen <toni.kalajainen@iki.fi>\r
12  */\r
13 public abstract class UnsignedShortBinding extends IntegerBinding {\r
14 \r
15         UnsignedShortBinding(IntegerType type) {\r
16                 super(type);\r
17         }\r
18 \r
19         public static class Immutable extends UnsignedShortBinding {\r
20 \r
21                 public Immutable(IntegerType type) {\r
22                         super(type);\r
23                 }\r
24                 \r
25                 @Override\r
26                 public Object create(int value) throws BindingException {\r
27                         try {\r
28                                 return UnsignedShort.fromBits(value);\r
29                         } catch (java.lang.IllegalArgumentException e) {\r
30                                 throw new BindingException( e );\r
31                         }\r
32                 }\r
33 \r
34                 @Override\r
35                 public Object create(Integer value) throws BindingException {\r
36                         try {\r
37                                 return UnsignedShort.valueOf(value.intValue());\r
38                         } catch (java.lang.IllegalArgumentException e) {\r
39                                 throw new BindingException( e );\r
40                         }\r
41                 }\r
42 \r
43                 @Override\r
44                 public Object create(Number value) throws BindingException {\r
45                         try {\r
46                                 return UnsignedShort.valueOf(value.longValue());\r
47                         } catch (java.lang.IllegalArgumentException e) {\r
48                                 throw new BindingException( e );\r
49                         }\r
50                 }\r
51 \r
52                 @Override\r
53                 public Object create(String value) throws BindingException {\r
54                         try {\r
55                                 return UnsignedShort.valueOf( Long.valueOf(value) );\r
56                         } catch (java.lang.IllegalArgumentException e) {\r
57                                 throw new BindingException( e );\r
58                         }\r
59                 }\r
60 \r
61                 @Override\r
62                 public void setValue(Object obj, Number value) throws BindingException {\r
63                         throw new BindingException("UnsignedShort is immutable class");\r
64                 }\r
65 \r
66                 @Override\r
67                 public void setValue(Object obj, int value) throws BindingException {\r
68                         throw new BindingException("UnsignedShort is immutable class");\r
69                 }\r
70                 \r
71                 @Override\r
72                 public boolean isImmutable() {\r
73                         return true;\r
74                 }\r
75                 \r
76                 @Override\r
77                 public boolean isInstance(Object obj) {\r
78                         return obj instanceof UnsignedShort.Immutable;\r
79                 }\r
80                 \r
81         }\r
82 \r
83         \r
84         public static class Mutable extends UnsignedShortBinding {\r
85 \r
86                 public Mutable(IntegerType type) {\r
87                         super(type);\r
88                 }\r
89                 \r
90                 @Override\r
91                 public Object create(int value) throws BindingException {\r
92                         try {\r
93                                 return new UnsignedShort.Mutable(value);\r
94                         } catch (java.lang.IllegalArgumentException e) {\r
95                                 throw new BindingException( e );\r
96                         }\r
97                 }\r
98 \r
99                 @Override\r
100                 public Object create(Integer value) throws BindingException {\r
101                         try {\r
102                                 return new UnsignedShort.Mutable(value);\r
103                         } catch (java.lang.IllegalArgumentException e) {\r
104                                 throw new BindingException( e );\r
105                         }\r
106                 }\r
107 \r
108                 @Override\r
109                 public Object create(Number value) throws BindingException {\r
110                         try {\r
111                                 return UnsignedShort.Mutable.fromBits(value.intValue());\r
112                         } catch (java.lang.IllegalArgumentException e) {\r
113                                 throw new BindingException( e );\r
114                         }\r
115                 }\r
116 \r
117                 @Override\r
118                 public Object create(String value) throws BindingException {\r
119                         try {\r
120                                 return new UnsignedShort.Mutable(value);\r
121                         } catch (java.lang.IllegalArgumentException e) {\r
122                                 throw new BindingException( e );\r
123                         }\r
124                 }\r
125 \r
126                 @Override\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
130                 }\r
131 \r
132                 @Override\r
133                 public void setValue(Object obj, int value) throws BindingException {\r
134                         UnsignedShort.Mutable mi = (UnsignedShort.Mutable) obj;\r
135                         mi.setBits(value);\r
136                 }\r
137                 \r
138                 @Override\r
139                 public boolean isImmutable() {\r
140                         return false;\r
141                 }\r
142 \r
143                 @Override\r
144                 public boolean isInstance(Object obj) {\r
145                         return obj instanceof UnsignedShort.Mutable;\r
146                 }               \r
147                 \r
148         }\r
149         \r
150         @Override\r
151         public Integer getValue(Object obj) throws BindingException {\r
152                 return ((UnsignedShort)obj).toBits();\r
153         }\r
154 \r
155         @Override\r
156         public int getValue_(Object obj) throws BindingException {\r
157                 return ((UnsignedShort)obj).toBits();\r
158         }\r
159 \r
160         @Override\r
161         public String toString(Object value) throws BindingException {\r
162                 return value.toString();\r
163         }\r
164 \r
165 \r
166 }\r