]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.databoard/src/org/simantics/databoard/binding/impl/LongBindingDefault.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.databoard / src / org / simantics / databoard / binding / impl / LongBindingDefault.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.impl;
13
14 import org.simantics.databoard.binding.LongBinding;\r
15 import org.simantics.databoard.binding.error.BindingException;\r
16 import org.simantics.databoard.binding.error.UnsupportedOperationException;\r
17 import org.simantics.databoard.type.LongType;\r
18
19 public class LongBindingDefault extends LongBinding {
20
21         public LongBindingDefault(LongType type) {
22                 super(type);
23         }
24         
25         public Object create(long value) {
26                 return Long.valueOf(value);
27         }
28         
29         public Object create(Long value) {
30                 return Long.valueOf(value);
31         }
32         
33         @Override
34         public Object create(Number value) 
35         {
36                 if (value.getClass()==Long.class) return value;
37                 return Long.valueOf( value.longValue() );
38         }       
39
40         @Override
41         public Object create(String value) throws BindingException {\r
42                 try {
43                         return Long.parseLong(value);\r
44                 } catch (java.lang.NumberFormatException e) {\r
45                         throw new BindingException( e );\r
46                 }\r
47         }
48         
49         public Long getValue(Object o) 
50         throws BindingException {
51                 if (o.getClass()!=Long.class)
52                         throw new BindingException("Unexpected class "+o.getClass().getSimpleName()+", Long expected");         
53                 return ((Long)o);
54         }
55
56         public long getValue_(Object o) 
57         throws BindingException 
58         {
59                 if (o.getClass()!=Long.class)
60                         throw new BindingException("Unexpected class "+o.getClass().getSimpleName()+", Long expected");         
61                 return ((Long)o);
62         }
63         
64         @Override
65         public void setValue(Object obj, Number value) throws BindingException {
66                 throw new UnsupportedOperationException("Cannot change the value of immutable java.lang.Long");
67         }
68
69         public void setValue(Object obj, long value) throws BindingException {
70                 throw new UnsupportedOperationException("Cannot change the value of immutable java.lang.Long");
71         }
72         
73     @Override
74         public boolean isInstance(Object obj) {
75                 return obj instanceof Long;
76         }       
77     
78     @Override
79     public boolean isImmutable() {
80         return true;
81     }
82         \r
83     @Override\r
84     public int compare(Object o1, Object o2)\r
85     {\r
86         long i1 = (Long) o1;\r
87         long i2 = (Long) o2;\r
88         return (i1<i2 ? -1 : (i1==i2 ? 0 : 1));\r
89     }    \r
90     
91 }
92