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:
EnumClassBinding, UnionTaggedObjectBinding

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.
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 createDefault(int tag)
          Create a new union object with tag of default 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(ChildReference path)
          Get component binding
 Binding getComponentBinding(int tagIndex)
          Get component binding
 Binding getComponentBinding(java.lang.String tagName)
           
 Binding[] getComponentBindings()
           
 int getComponentCount()
          Get component binding count
abstract  int getTag(java.lang.Object obj)
          Get tag number of an instance.
abstract  java.lang.Object getValue(java.lang.Object obj)
           
 boolean isTagMutable()
          Returns true if the tag of this union type can be modified
 void readFrom(Binding srcBinding, java.lang.Object src, java.lang.Object dst)
          Read values from one object to another.
 void setComponentBindings(Binding[] componentBindings)
           
 void setTag(java.lang.Object union, int tag)
          Set to tag with default value.
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, createRandom, createRandom, createRandomUnchecked, equals, hashValue, isImmutable, isInstance, parseValue, parseValue, parseValueDefinition, printValue, printValueDefinition, readFromTry, readFromTryUnchecked, readFromUnchecked, serializer, toString, 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

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

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 tagIndex)
Description copied from class: Binding
Get component binding

Specified by:
getComponentBinding in class Binding
Returns:
binding

getComponentBinding

public Binding getComponentBinding(java.lang.String tagName)

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

createDefault

public java.lang.Object createDefault(int tag)
                               throws BindingException
Create a new union object with tag of default value.

Parameters:
tag -
Returns:
new union object
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

readFrom

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

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

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

setTag

public void setTag(java.lang.Object union,
                   int tag)
            throws BindingException
Set to tag with default value.

Parameters:
union -
tag -
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)

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

isTagMutable

public boolean isTagMutable()
Returns true if the tag of this union type can be modified

Returns: