]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.databoard/src/org/simantics/databoard/binding/LongBinding.java
Use type reflection tools from databoard in objmap2.
[simantics/platform.git] / bundles / org.simantics.databoard / src / org / simantics / databoard / binding / LongBinding.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;
13
14 import java.util.IdentityHashMap;
15 import java.util.Set;
16
17 import org.simantics.databoard.binding.error.BindingException;
18 import org.simantics.databoard.binding.error.RuntimeBindingException;
19 import org.simantics.databoard.binding.impl.LongBindingDefault;
20 import org.simantics.databoard.binding.mutable.MutableLongBinding;
21 import org.simantics.databoard.type.LongType;
22 import org.simantics.databoard.util.IdentityPair;
23
24 /**
25  * This is a binding of a Long Type and a Java Object.
26  *
27  * @see LongType
28  * @see LongBindingDefault for java.lang.Long Binding
29  * @see MutableLongBinding for MutableLong Binding
30  * @author Toni Kalajainen <toni.kalajainen@vtt.fi>
31  */
32 public abstract class LongBinding extends NumberBinding {
33         
34         public LongBinding(LongType type) {
35                 this.type = type;
36         }
37         
38         public abstract Object create(long value) throws BindingException;
39         public abstract Object create(Long value) throws BindingException;
40         public abstract Object create(Number value) throws BindingException;
41         public abstract Object create(String value) throws BindingException;
42         public abstract Long getValue(Object o) throws BindingException;
43         public abstract long getValue_(Object o) throws BindingException; 
44         public abstract void setValue(Object obj, Number value) throws BindingException;
45         public abstract void setValue(Object obj, long value) throws BindingException;
46         public abstract boolean isInstance(Object obj);
47         
48     @Override
49     public void accept(Visitor1 v, Object obj) {
50         v.visit(this, obj);        
51     }
52     
53     @Override
54     public <T> T accept(Visitor<T> v) {
55         return v.visit(this);
56     }
57         
58     @Override
59     public int deepCompare(Object o1, Object o2,
60                 Set<IdentityPair<Object, Object>> compareHistory)
61                 throws BindingException {
62         
63         long v1 = getValue_(o1);
64         long v2 = getValue_(o2);
65         return (v1<v2 ? -1 : (v1==v2 ? 0 : 1));
66     }
67     
68     @Override
69     public int deepHashValue(Object value, IdentityHashMap<Object, Object> hashedObjects) throws BindingException {
70         long v = getValue_(value); 
71         return (int)(v ^ (v >>> 32));
72     }
73
74         public Object createUnchecked(long value) throws RuntimeBindingException {
75                 try {
76                         return create(value);
77                 } catch (BindingException e) {
78                         return new RuntimeBindingException(e);
79                 }
80         }
81         public Object createUnchecked(Long value) throws RuntimeBindingException {
82                 try {
83                         return create(value);
84                 } catch (BindingException e) {
85                         return new RuntimeBindingException(e);
86                 }
87         }
88         
89         /**
90          * Get Data type
91          * 
92          * @return data type
93          */
94         @Override
95         public LongType type() {
96                 return (LongType) type;
97         }
98         
99 }