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