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.impl;
14 import org.simantics.databoard.binding.LongBinding;
15 import org.simantics.databoard.binding.error.BindingException;
16 import org.simantics.databoard.binding.error.UnsupportedOperationException;
17 import org.simantics.databoard.type.LongType;
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 {
43 return Long.parseLong(value);
44 } catch (java.lang.NumberFormatException e) {
45 throw new BindingException( e );
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)
88 return (i1<i2 ? -1 : (i1==i2 ? 0 : 1));