]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.databoard/src/org/simantics/databoard/binding/impl/LongBindingDefault.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.databoard / src / org / simantics / databoard / binding / impl / LongBindingDefault.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.impl;
13
14 import org.simantics.databoard.binding.LongBinding;
15 import org.simantics.databoard.binding.error.BindingException;
16 import org.simantics.databoard.binding.error.UnsupportedOperationException;
17 import org.simantics.databoard.type.LongType;
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 {
42                 try {
43                         return Long.parseLong(value);
44                 } catch (java.lang.NumberFormatException e) {
45                         throw new BindingException( e );
46                 }
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         
83     @Override
84     public int compare(Object o1, Object o2)
85     {
86         long i1 = (Long) o1;
87         long i2 = (Long) o2;
88         return (i1<i2 ? -1 : (i1==i2 ? 0 : 1));
89     }    
90     
91 }
92