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.impl;
14 import org.simantics.databoard.binding.DoubleBinding;
\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.DoubleType;
\r
20 * Binds DoubleType to java.lang.Double
22 * @author Toni Kalajainen <toni.kalajainen@vtt.fi>
24 public class DoubleBindingDefault extends DoubleBinding {
26 public DoubleBindingDefault(DoubleType type) {
31 public DoubleType type() {
32 return (DoubleType) type;
35 public Object create(Double value) {
39 public Object create(double value) {
40 return Double.valueOf(value);
44 public Object create(Number value)
46 if (value.getClass()==Double.class) return value;
47 return Double.valueOf( value.doubleValue() );
51 public Object create(String value) throws BindingException {
\r
53 return Double.parseDouble(value);
\r
54 } catch (java.lang.NumberFormatException e) {
\r
55 throw new BindingException( e );
\r
59 public Double getValue(Object o)
60 throws BindingException
62 if (o.getClass()!=Double.class)
63 throw new BindingException("Unexpected class "+o.getClass().getSimpleName()+", Double expected");
67 public double getValue_(Object o)
68 throws BindingException
70 if (o.getClass()!=Double.class)
71 throw new BindingException("Unexpected class "+o.getClass().getSimpleName()+", Double expected");
76 public void setValue(Object obj, Number value) throws BindingException {
77 throw new UnsupportedOperationException("Cannot change the value of immutable java.lang.Double");
80 public void setValue(Object obj, double value) throws BindingException {
81 throw new UnsupportedOperationException("Cannot change the value of immutable java.lang.Double");
85 public boolean isInstance(Object obj) {
86 return obj instanceof Double;
90 public boolean isImmutable() {
95 public int compare(Object o1, Object o2)
\r
97 Double d1 = (Double) o1;
\r
98 Double d2 = (Double) o2;
\r
99 return d1.compareTo(d2);
\r