]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.databoard/src/org/simantics/databoard/binding/mutable/MutableIntegerBinding.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.databoard / src / org / simantics / databoard / binding / mutable / MutableIntegerBinding.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.IntegerBinding;
15 import org.simantics.databoard.binding.error.BindingException;
16 import org.simantics.databoard.primitives.MutableInteger;
17 import org.simantics.databoard.type.IntegerType;
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 {
48                 try {
49                         MutableInteger result = new MutableInteger();
50                         result.value = Integer.valueOf(value);
51                         return result;
52                 } catch (java.lang.NumberFormatException e) {
53                         throw new BindingException( e );
54                 }
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