1 /*******************************************************************************
2 * Copyright (c) 2010 Association for Decentralized Information Management in
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
10 * VTT Technical Research Centre of Finland - initial API and implementation
11 *******************************************************************************/
12 package org.simantics.databoard.binding;
14 import java.util.IdentityHashMap;
17 import org.simantics.databoard.binding.error.BindingException;
18 import org.simantics.databoard.binding.error.RuntimeBindingException;
19 import org.simantics.databoard.type.DoubleType;
20 import org.simantics.databoard.util.IdentityPair;
24 * This is a binding of Double Type and a Java Object.
27 * @author Toni Kalajainen <toni.kalajainen@vtt.fi>
29 public abstract class DoubleBinding extends NumberBinding {
31 public DoubleBinding(DoubleType type) {
35 public DoubleType type() {
36 return (DoubleType) type;
39 public abstract Object create(Double value) throws BindingException;
40 public abstract Object create(double value) throws BindingException;
41 public abstract Object create(Number value) throws BindingException;
42 public abstract Object create(String value) throws BindingException;
43 public abstract Double getValue(Object o) throws BindingException;
44 public abstract double getValue_(Object o) throws BindingException;
45 public abstract void setValue(Object obj, Number value) throws BindingException;
46 public abstract void setValue(Object obj, double value) throws BindingException;
47 public abstract boolean isInstance(Object obj);
50 public void accept(Visitor1 v, Object obj) {
55 public <T> T accept(Visitor<T> v) {
60 public int deepCompare(Object o1, Object o2,
61 Set<IdentityPair<Object, Object>> compareHistory)
62 throws BindingException {
63 double v1 = getValue_(o1);
64 double v2 = getValue_(o2);
65 return Double.compare(v1, v2);
69 public int deepHashValue(Object value, IdentityHashMap<Object, Object> hashedObjects) throws BindingException {
70 double v = getValue_(value);
71 long bits = Double.doubleToLongBits(v);
72 return (int)(bits ^ (bits >>> 32));
75 public Object createUnchecked(double value) throws RuntimeBindingException {
78 } catch (BindingException e) {
79 return new RuntimeBindingException(e);
82 public Object createUnchecked(Double value) throws RuntimeBindingException {
85 } catch (BindingException e) {
86 return new RuntimeBindingException(e);