org.simantics.databoard.binding
Class UnionBinding

java.lang.Object
  extended by org.simantics.databoard.binding.Binding
      extended by org.simantics.databoard.binding.UnionBinding
All Implemented Interfaces:
java.util.Comparator<java.lang.Object>
Direct Known Subclasses:
ReflectionEnumBinding, ReflectionUnionClassBinding

public abstract class UnionBinding
extends Binding

This is a binding of Union Type and a Java Object.

Author:
Toni Kalajainen
See Also:
UnionType

Nested Class Summary
 
Nested classes/interfaces inherited from class org.simantics.databoard.binding.Binding
Binding.Visitor<T>, Binding.Visitor1
 
Constructor Summary
UnionBinding()
           
UnionBinding(Binding... componentBindings)
           
 
Method Summary
<T> T
accept(Binding.Visitor<T> v)
           
 void accept(Binding.Visitor1 v, java.lang.Object obj)
           
 void assertInstaceIsValid(java.lang.Object obj, java.util.Set<java.lang.Object> validInstances)
          Asserts the obj is valid to its UnionType.
 int count()
           
abstract  java.lang.Object create(int tag, java.lang.Object value)
           
 java.lang.Object create(java.lang.String tag, java.lang.Object value)
           
 java.lang.Object createUnchecked(int tag, java.lang.Object value)
           
 int deepCompare(java.lang.Object o1, java.lang.Object o2, java.util.Set<IdentityPair<java.lang.Object,java.lang.Object>> compareHistory)
           
 int deepHashValue(java.lang.Object value, java.util.IdentityHashMap<java.lang.Object,java.lang.Object> hashedObjects)
          Calculate hash value
 Binding getComponentBinding(int tagIndex)
           
 Binding[] getComponentBindings()
           
abstract  int getTag(java.lang.Object obj)
          Get tag number of an instance.
abstract  java.lang.Object getValue(java.lang.Object obj)
           
 void setComponentBindings(Binding[] componentBindings)
           
abstract  void setValue(java.lang.Object union, int tag, java.lang.Object value)
          Set value to an union.
 UnionType type()
          Get Value Type
 
Methods inherited from class org.simantics.databoard.binding.Binding
assertInstaceIsValid, clone, cloneUnchecked, compare, createDefault, createDefaultUnchecked, createRandom, createRandomUnchecked, equals, hashValue, isImmutable, isInstance, parseValue, parseValue, parseValueDefinition, printValue, printValueDefinition, serializer, serializer, serializerUnchecked
 
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

UnionBinding

public UnionBinding()

UnionBinding

public UnionBinding(Binding... componentBindings)
Method Detail

type

public UnionType type()
Description copied from class: Binding
Get Value Type

Overrides:
type in class Binding
Returns:
value type

count

public int count()

getComponentBinding

public Binding getComponentBinding(int tagIndex)

getComponentBindings

public Binding[] getComponentBindings()

getTag

public abstract int getTag(java.lang.Object obj)
                    throws BindingException
Get tag number of an instance.

Parameters:
obj -
Returns:
the tag number
Throws:
BindingException - is thrown if the instance is not a tag of this union

getValue

public abstract java.lang.Object getValue(java.lang.Object obj)
                                   throws BindingException
Throws:
BindingException

create

public abstract java.lang.Object create(int tag,
                                        java.lang.Object value)
                                 throws BindingException
Throws:
BindingException

create

public java.lang.Object create(java.lang.String tag,
                               java.lang.Object value)
                        throws BindingException
Throws:
BindingException

createUnchecked

public java.lang.Object createUnchecked(int tag,
                                        java.lang.Object value)
                                 throws RuntimeBindingException
Throws:
RuntimeBindingException

setValue

public abstract void setValue(java.lang.Object union,
                              int tag,
                              java.lang.Object value)
                       throws BindingException
Set value to an union. Throws BindingException if value cannot be written.

Parameters:
union -
tag -
value -
Throws:
BindingException

accept

public void accept(Binding.Visitor1 v,
                   java.lang.Object obj)
Specified by:
accept in class Binding

accept

public <T> T accept(Binding.Visitor<T> v)
Specified by:
accept in class Binding

assertInstaceIsValid

public void assertInstaceIsValid(java.lang.Object obj,
                                 java.util.Set<java.lang.Object> validInstances)
                          throws BindingException
Asserts the obj is valid to its UnionType. Asserts the obj using the component type

Specified by:
assertInstaceIsValid in class Binding
Parameters:
obj - the instance
validInstances - optional set of already validated instances
Throws:
BindingException - if obj is not valid according to the UnionType

deepHashValue

public int deepHashValue(java.lang.Object value,
                         java.util.IdentityHashMap<java.lang.Object,java.lang.Object> hashedObjects)
                  throws BindingException
Description copied from class: Binding
Calculate hash value

Specified by:
deepHashValue in class Binding
hashedObjects - collection of already hashed object or optionally null
Returns:
hash value
Throws:
BindingException

deepCompare

public int deepCompare(java.lang.Object o1,
                       java.lang.Object o2,
                       java.util.Set<IdentityPair<java.lang.Object,java.lang.Object>> compareHistory)
                throws BindingException
Specified by:
deepCompare in class Binding
Throws:
BindingException

setComponentBindings

public void setComponentBindings(Binding[] componentBindings)