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.LongBinding;
\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.LongType;
\r
19 public class LongBindingDefault extends LongBinding {
21 public LongBindingDefault(LongType type) {
25 public Object create(long value) {
26 return Long.valueOf(value);
29 public Object create(Long value) {
30 return Long.valueOf(value);
34 public Object create(Number value)
36 if (value.getClass()==Long.class) return value;
37 return Long.valueOf( value.longValue() );
41 public Object create(String value) throws BindingException {
\r
43 return Long.parseLong(value);
\r
44 } catch (java.lang.NumberFormatException e) {
\r
45 throw new BindingException( e );
\r
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");
56 public long getValue_(Object o)
57 throws BindingException
59 if (o.getClass()!=Long.class)
60 throw new BindingException("Unexpected class "+o.getClass().getSimpleName()+", Long expected");
65 public void setValue(Object obj, Number value) throws BindingException {
66 throw new UnsupportedOperationException("Cannot change the value of immutable java.lang.Long");
69 public void setValue(Object obj, long value) throws BindingException {
70 throw new UnsupportedOperationException("Cannot change the value of immutable java.lang.Long");
74 public boolean isInstance(Object obj) {
75 return obj instanceof Long;
79 public boolean isImmutable() {
84 public int compare(Object o1, Object o2)
\r
86 long i1 = (Long) o1;
\r
87 long i2 = (Long) o2;
\r
88 return (i1<i2 ? -1 : (i1==i2 ? 0 : 1));
\r