]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.databoard/src/org/simantics/databoard/binding/mutable/MutableLongBinding.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.databoard / src / org / simantics / databoard / binding / mutable / MutableLongBinding.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.LongBinding;
15 import org.simantics.databoard.binding.error.BindingException;
16 import org.simantics.databoard.primitives.MutableLong;
17 import org.simantics.databoard.type.LongType;
18
19 /**
20  * Binds LongType to {@link MutableLong}
21  *
22  * @author Toni Kalajainen <toni.kalajainen@vtt.fi>
23  */
24 public class MutableLongBinding extends LongBinding {
25         
26         public MutableLongBinding(LongType type) {
27                 super(type);
28         }
29
30         @Override
31         public Object create(long value) {
32                 MutableLong result = new MutableLong();
33                 result.value = value;
34                 return result;
35         }
36
37         @Override
38         public Object create(Long value) {
39                 MutableLong result = new MutableLong();
40                 result.value = value;
41                 return result;
42         }
43
44         @Override
45         public Object create(Number value) {
46                 MutableLong result = new MutableLong();
47                 result.value = value.longValue();
48                 return result;
49         }
50
51         @Override
52         public Object create(String value) throws BindingException {
53                 try {
54                         MutableLong result = new MutableLong();
55                         result.value = Long.valueOf(value);
56                         return result;
57                 } catch (java.lang.NumberFormatException e) {
58                         throw new BindingException( e );
59                 }
60         }
61
62         @Override
63         public long getValue_(Object o) throws BindingException {
64                 MutableLong result = (MutableLong) o;
65                 return result.value;
66         }
67
68         @Override
69         public Long getValue(Object o) throws BindingException {
70                 MutableLong result = (MutableLong) o;
71                 return result.value;
72         }
73
74         @Override
75         public boolean isInstance(Object obj) {
76                 return obj instanceof MutableLong;
77         }
78
79         @Override
80         public void setValue(Object obj, long value) throws BindingException {
81                 MutableLong result = (MutableLong) obj;
82                 result.value = value;
83         }
84
85         @Override
86         public void setValue(Object obj, Number value) throws BindingException {
87                 MutableLong result = (MutableLong) obj;
88                 result.value = value.longValue();
89         }
90                         
91 }
92