1 /*******************************************************************************
\r
2 * Copyright (c) 2010 Association for Decentralized Information Management in
\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
10 * VTT Technical Research Centre of Finland - initial API and implementation
\r
11 *******************************************************************************/
\r
12 package org.simantics.databoard.binding;
14 import java.util.IdentityHashMap;
\r
15 import java.util.Set;
\r
17 import org.simantics.databoard.binding.error.BindingException;
\r
18 import org.simantics.databoard.binding.error.RuntimeBindingException;
\r
19 import org.simantics.databoard.binding.impl.LongBindingDefault;
\r
20 import org.simantics.databoard.binding.mutable.MutableLongBinding;
\r
21 import org.simantics.databoard.type.LongType;
\r
22 import org.simantics.databoard.util.IdentityPair;
\r
25 * This is a binding of a Long Type and a Java Object.
28 * @see LongBindingDefault for java.lang.Long Binding
\r
29 * @see MutableLongBinding for MutableLong Binding
30 * @author Toni Kalajainen <toni.kalajainen@vtt.fi>
32 public abstract class LongBinding extends NumberBinding {
34 public LongBinding(LongType type) {
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);
49 public void accept(Visitor1 v, Object obj) {
54 public <T> T accept(Visitor<T> v) {
59 public int deepCompare(Object o1, Object o2,
60 Set<IdentityPair<Object, Object>> compareHistory)
61 throws BindingException {
63 long v1 = getValue_(o1);
64 long v2 = getValue_(o2);
65 return (v1<v2 ? -1 : (v1==v2 ? 0 : 1));
69 public int deepHashValue(Object value, IdentityHashMap<Object, Object> hashedObjects) throws BindingException {
70 long v = getValue_(value);
71 return (int)(v ^ (v >>> 32));
74 public Object createUnchecked(long value) throws RuntimeBindingException {
77 } catch (BindingException e) {
78 return new RuntimeBindingException(e);
81 public Object createUnchecked(Long value) throws RuntimeBindingException {
84 } catch (BindingException e) {
85 return new RuntimeBindingException(e);
95 public LongType type() {
96 return (LongType) type;