]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.databoard/src/org/simantics/databoard/binding/impl/UnsignedLongBinding.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.databoard / src / org / simantics / databoard / binding / impl / UnsignedLongBinding.java
1 package org.simantics.databoard.binding.impl;
2
3 import org.simantics.databoard.binding.LongBinding;
4 import org.simantics.databoard.binding.error.BindingException;
5 import org.simantics.databoard.primitives.UnsignedLong;
6 import org.simantics.databoard.type.LongType;
7
8 /**
9  * Binding of {@link UnsignedLong} to long type.
10  * This is bitwise binding, i.e. high values are negative.
11  * 
12  * @author Toni Kalajainen <toni.kalajainen@iki.fi>
13  */
14 public abstract class UnsignedLongBinding extends LongBinding {
15
16         UnsignedLongBinding(LongType type) {
17                 super(type);
18         }
19         
20         public static class Immutable extends UnsignedLongBinding {
21
22                 public Immutable(LongType type) {
23                         super(type);
24                 }
25
26                 @Override
27                 public Object create(Number value) throws BindingException {
28                         return UnsignedLong.fromBits(value.longValue());
29                 }
30
31                 @Override
32                 public Object create(String value) throws BindingException {
33                         try {
34                                 return new UnsignedLong.Immutable(value);
35                         } catch (java.lang.IllegalArgumentException e) {
36                                 throw new BindingException( e );
37                         }
38                 }
39
40                 @Override
41                 public Object create(long value) throws BindingException {
42                         return UnsignedLong.fromBits(value);
43                 }
44
45                 @Override
46                 public Object create(Long value) throws BindingException {
47                         return UnsignedLong.fromBits(value);
48                 }
49
50                 @Override
51                 public void setValue(Object obj, long value) throws BindingException {
52                         throw new BindingException("UnsignedLong is immutable class");
53                 }
54
55                 @Override
56                 public void setValue(Object obj, Number value) throws BindingException {
57                         throw new BindingException("UnsignedLong is immutable class");
58                 }
59                 
60                 @Override
61                 public boolean isImmutable() {
62                         return true;
63                 }
64                 
65                 @Override
66                 public boolean isInstance(Object obj) {
67                         return obj instanceof UnsignedLong.Immutable;
68                 }
69                 
70         }
71
72         public static class Mutable extends UnsignedLongBinding {
73
74                 public Mutable(LongType type) {
75                         super(type);
76                 }
77
78                 @Override
79                 public Object create(Number value) throws BindingException {
80                         return UnsignedLong.Mutable.fromBits(value.longValue());
81                 }
82
83                 @Override
84                 public Object create(String value) throws BindingException {
85                         return new UnsignedLong.Mutable(value);
86                 }
87
88                 @Override
89                 public void setValue(Object obj, Number value) throws BindingException {
90                         UnsignedLong.Mutable v = (UnsignedLong.Mutable) obj;
91                         v.setValue(value.longValue());
92                 }
93                 
94                 @Override
95                 public boolean isImmutable() {
96                         return false;
97                 }
98
99                 @Override
100                 public Object create(long value) throws BindingException {
101                         return UnsignedLong.Mutable.fromBits(value);
102                 }
103
104                 @Override
105                 public Object create(Long value) throws BindingException {
106                         return UnsignedLong.Mutable.fromBits(value);
107                 }
108
109                 @Override
110                 public void setValue(Object obj, long value) throws BindingException {
111                         UnsignedLong.Mutable v = (UnsignedLong.Mutable) obj;
112                         v.setValue(value);
113                 }
114
115                 @Override
116                 public boolean isInstance(Object obj) {
117                         return obj instanceof UnsignedLong.Mutable;
118                 }
119                 
120         }       
121         
122         @Override
123         public String toString(Object value) throws BindingException {
124                 return value.toString();
125         }
126
127         @Override
128         public Long getValue(Object o) throws BindingException {
129                 UnsignedLong v = (UnsignedLong) o;
130                 return v.toBits();
131         }
132
133         @Override
134         public long getValue_(Object o) throws BindingException {
135                 UnsignedLong v = (UnsignedLong) o;
136                 return v.toBits();
137         }
138
139 }