]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.databoard/src/org/simantics/databoard/binding/mutable/MutableByteBinding.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.databoard / src / org / simantics / databoard / binding / mutable / MutableByteBinding.java
1 /*******************************************************************************
2  *  Copyright (c) 2010 Association for Decentralized Information Management in
3  *  Industry THTH ry.
4  *  All rights reserved. This program and the accompanying materials
5  *  are made available under the terms of the Eclipse Public License v1.0
6  *  which accompanies this distribution, and is available at
7  *  http://www.eclipse.org/legal/epl-v10.html
8  *
9  *  Contributors:
10  *      VTT Technical Research Centre of Finland - initial API and implementation
11  *******************************************************************************/
12 package org.simantics.databoard.binding.mutable;
13
14 import org.simantics.databoard.binding.ByteBinding;
15 import org.simantics.databoard.binding.error.BindingException;
16 import org.simantics.databoard.primitives.MutableByte;
17 import org.simantics.databoard.type.ByteType;
18
19 /**
20  * Binds java.lang.Byte to {@link MutableByte}
21  *
22  * @author Toni Kalajainen <toni.kalajainen@vtt.fi>
23  */
24 public class MutableByteBinding extends ByteBinding {
25         
26         public MutableByteBinding(ByteType type) {
27                 super( type );
28         }
29
30         @Override
31         public Object create(byte value) {
32                 MutableByte result = new MutableByte();
33                 result.value = value;
34                 return result;
35         }
36
37         @Override
38         public Object create(Byte value) {
39                 MutableByte result = new MutableByte();
40                 result.value = value;
41                 return result;
42         }
43
44         @Override
45         public Object create(Number value) {
46                 MutableByte result = new MutableByte();
47                 result.value = value.byteValue();
48                 return result;
49         }
50
51         @Override
52         public Object create(String value) throws BindingException {
53                 try {
54                         byte x = Byte.valueOf( value );
55                         MutableByte result = new MutableByte();
56                         result.value = x;
57                         return result;
58                 } catch (java.lang.NumberFormatException e) {
59                         throw new BindingException( e );
60                 }
61         }
62
63         @Override
64         public byte getValue_(Object obj) throws BindingException {
65                 MutableByte result = (MutableByte) obj;
66                 return result.value;
67         }
68
69         @Override
70         public Byte getValue(Object obj) throws BindingException {
71                 MutableByte result = (MutableByte) obj;
72                 return result.value;
73         }
74
75         @Override
76         public boolean isInstance(Object obj) {
77                 return obj instanceof MutableByte;
78         }
79
80         @Override
81         public void setValue(Object obj, byte value) throws BindingException {
82                 MutableByte result = (MutableByte) obj;
83                 result.value = value;
84         }
85
86         @Override
87         public void setValue(Object obj, Number value) throws BindingException {
88                 MutableByte result = (MutableByte) obj;
89                 result.value = value.byteValue();
90         }
91         
92 }
93