org.simantics.databoard.binding
Class NumberBinding

java.lang.Object
  extended by org.simantics.databoard.binding.Binding
      extended by org.simantics.databoard.binding.NumberBinding
All Implemented Interfaces:
java.util.Comparator<java.lang.Object>
Direct Known Subclasses:
ByteBinding, DoubleBinding, FloatBinding, IntegerBinding, LongBinding

public abstract class NumberBinding
extends Binding

Super class for number types.

Author:
Toni Kalajainen

Nested Class Summary
 
Nested classes/interfaces inherited from class org.simantics.databoard.binding.Binding
Binding.Visitor<T>, Binding.Visitor1
 
Constructor Summary
NumberBinding()
           
 
Method Summary
 void assertInstaceIsValid(java.lang.Object obj, java.util.Set<java.lang.Object> validInstances)
          Assert the obj is a valid number.
abstract  java.lang.Object create(java.lang.Number value)
          Create value by converting it from any Number instance to a Number instance of this Binding type.
abstract  java.lang.Object create(java.lang.String value)
          Creates a value from its string representation
 java.lang.Object createUnchecked(java.lang.Number value)
           
 java.lang.Object createUnchecked(java.lang.String value)
           
 Binding getComponentBinding(ChildReference path)
          Get component binding
 Binding getComponentBinding(int index)
          Get component binding
 int getComponentCount()
          Get component binding count
 java.lang.Number getValue(java.lang.Object obj)
          Get numeric value of an object
 void readFrom(Binding srcBinding, java.lang.Object src, java.lang.Object dst)
          Read values from another object.
abstract  void setValue(java.lang.Object obj, java.lang.Number value)
           
 NumberType type()
          Get Data type
 
Methods inherited from class org.simantics.databoard.binding.Binding
accept, accept, assertInstaceIsValid, clone, cloneUnchecked, compare, createDefault, createDefaultUnchecked, createRandom, createRandomUnchecked, deepCompare, deepHashValue, equals, hashValue, isImmutable, isInstance, parseValue, parseValue, parseValueDefinition, printValue, printValueDefinition, serializer, toString
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface java.util.Comparator
equals
 

Constructor Detail

NumberBinding

public NumberBinding()
Method Detail

create

public abstract java.lang.Object create(java.lang.Number value)
                                 throws BindingException
Create value by converting it from any Number instance to a Number instance of this Binding type. NOTE WARNING! Using this method may lose precision or value in the conversion. E.g. Double to Integer, or Long to Byte

Parameters:
value -
Returns:
the value in the format of the binding type
Throws:
BindingException

create

public abstract java.lang.Object create(java.lang.String value)
                                 throws BindingException
Creates a value from its string representation

Parameters:
value -
Returns:
number
Throws:
BindingException

type

public NumberType type()
Get Data type

Overrides:
type in class Binding
Returns:
data type

getValue

public java.lang.Number getValue(java.lang.Object obj)
                          throws BindingException
Get numeric value of an object

Parameters:
obj - object
Returns:
Number
Throws:
BindingException - thrown if obj is incorrect class

setValue

public abstract void setValue(java.lang.Object obj,
                              java.lang.Number value)
                       throws BindingException
Throws:
BindingException

assertInstaceIsValid

public void assertInstaceIsValid(java.lang.Object obj,
                                 java.util.Set<java.lang.Object> validInstances)
                          throws BindingException
Assert the obj is a valid number. This asserts 1. The value is within the range defined in the NumberType

Specified by:
assertInstaceIsValid in class Binding
Parameters:
obj - the instance
validInstances - optional set of already validated instances
Throws:
BindingException

createUnchecked

public java.lang.Object createUnchecked(java.lang.String value)
                                 throws RuntimeBindingException
Throws:
RuntimeBindingException

createUnchecked

public java.lang.Object createUnchecked(java.lang.Number value)
                                 throws RuntimeBindingException
Throws:
RuntimeBindingException

readFrom

public void readFrom(Binding srcBinding,
                     java.lang.Object src,
                     java.lang.Object dst)
              throws BindingException
Description copied from class: Binding
Read values from another object.

Specified by:
readFrom in class Binding
dst - valid object of this binding
Throws:
BindingException

getComponentBinding

public Binding getComponentBinding(ChildReference path)
Description copied from class: Binding
Get component binding

Specified by:
getComponentBinding in class Binding
Parameters:
path - child path or null to return this.
Returns:
binding

getComponentCount

public int getComponentCount()
Description copied from class: Binding
Get component binding count

Specified by:
getComponentCount in class Binding
Returns:
component count

getComponentBinding

public Binding getComponentBinding(int index)
Description copied from class: Binding
Get component binding

Specified by:
getComponentBinding in class Binding
Returns:
binding