org.simantics.databoard.accessor.java
Class JavaMap

java.lang.Object
  extended by org.simantics.databoard.accessor.java.JavaObject
      extended by org.simantics.databoard.accessor.java.JavaMap
All Implemented Interfaces:
Accessor, MapAccessor

public class JavaMap
extends JavaObject
implements MapAccessor


Nested Class Summary
 
Nested classes/interfaces inherited from interface org.simantics.databoard.accessor.Accessor
Accessor.Listener
 
Constructor Summary
JavaMap(JavaObject parent, MapBinding binding, java.lang.Object object)
           
 
Method Summary
 void addListener(Accessor.Listener listener, InterestSet interestSet, AccessorReference path)
          Place a listener to an accessor node.
 void clear()
          Clear all entries.
 boolean containsKey(Binding keyBinding, java.lang.Object key)
          Returns true if map has a value for specified key
 boolean containsValue(Binding valueBinding, java.lang.Object value)
          Returns true if map has a value for one or multiple keys
 java.lang.Object get(Binding keyBinding, java.lang.Object key, Binding valueBinding)
          Get the value that is specified for a key
<T extends Accessor>
T
getAccessor(AccessorReference reference)
          Get an accessor to a sub-container.
 void getAll(Binding keyBinding, Binding valueBinding, java.util.Map<java.lang.Object,java.lang.Object> to)
          Get all entries, write to a Java Collection
 void getAll(Binding keyBinding, Binding valueBinding, java.lang.Object[] keys, java.lang.Object[] values)
          Get all entries in order, write to 2 arrays.
 MapBinding getBinding()
           
 java.lang.Object getCeilingKey(Binding keyBinding, java.lang.Object key)
           
 java.lang.Object getFirstKey(Binding keyBinding)
           
 java.lang.Object getFloorKey(Binding keyBinding, java.lang.Object key)
           
 java.lang.Object getHigherKey(Binding keyBinding, java.lang.Object key)
           
 Binding getKeyBinding()
           
 java.lang.Object[] getKeys(Binding keyBinding)
          Get all keys in order
 java.lang.Object getLastKey(Binding keyBinding)
           
 java.lang.Object getLowerKey(Binding keyBinding, java.lang.Object key)
           
<T extends Accessor>
T
getValueAccessor(Binding keyBinding, java.lang.Object key)
          Get an accessor to a value.
 Binding getValueBinding()
           
 java.lang.Object[] getValues(Binding valueBinding)
          Get all values
 void put(Binding keyBinding, java.lang.Object key, Binding valueBinding, java.lang.Object value)
          Put an entry to the map.
 void putAll(Binding keyBinding, Binding valueBinding, java.util.Map<java.lang.Object,java.lang.Object> from)
          Put entries from a map.
 void putAll(Binding keyBinding, Binding valueBinding, java.lang.Object[] keys, java.lang.Object[] values)
          Put entries from a map.
 void remove(Binding keyBinding, java.lang.Object key)
          Remove an entry.
 void removeListener(Accessor.Listener listener)
          Remove a listener.
 void setValue(Binding mapBinding, java.lang.Object newMap)
          Set & copy all entries from a Map Value.
 int size()
          Get the number of elements in the map
 MapType type()
          Get structural represtentation of the accessor presented in databoard's type system format.
 
Methods inherited from class org.simantics.databoard.accessor.java.JavaObject
apply, createAccessor, getObject, getValue, toString
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.simantics.databoard.accessor.Accessor
apply, getValue
 

Constructor Detail

JavaMap

public JavaMap(JavaObject parent,
               MapBinding binding,
               java.lang.Object object)
Method Detail

type

public MapType type()
Description copied from interface: Accessor
Get structural represtentation of the accessor presented in databoard's type system format.

Specified by:
type in interface Accessor
Specified by:
type in interface MapAccessor
Overrides:
type in class JavaObject
Returns:
type description

getBinding

public MapBinding getBinding()
Overrides:
getBinding in class JavaObject

getKeyBinding

public Binding getKeyBinding()

getValueBinding

public Binding getValueBinding()

clear

public void clear()
           throws AccessorException
Description copied from interface: MapAccessor
Clear all entries. If there is an accessor to a removed container, it becomes invalid.

Specified by:
clear in interface MapAccessor
Throws:
AccessorException

put

public void put(Binding keyBinding,
                java.lang.Object key,
                Binding valueBinding,
                java.lang.Object value)
         throws AccessorException
Description copied from interface: MapAccessor
Put an entry to the map. If previous entry exists for the key, it is removed.

Specified by:
put in interface MapAccessor
Throws:
AccessorException

putAll

public void putAll(Binding keyBinding,
                   Binding valueBinding,
                   java.util.Map<java.lang.Object,java.lang.Object> from)
            throws AccessorException
Description copied from interface: MapAccessor
Put entries from a map. Replaces any possible existing entry.

Specified by:
putAll in interface MapAccessor
Throws:
AccessorException

putAll

public void putAll(Binding keyBinding,
                   Binding valueBinding,
                   java.lang.Object[] keys,
                   java.lang.Object[] values)
            throws AccessorException
Description copied from interface: MapAccessor
Put entries from a map. Replaces any possible existing entry.

Specified by:
putAll in interface MapAccessor
Throws:
AccessorException

remove

public void remove(Binding keyBinding,
                   java.lang.Object key)
            throws AccessorException
Description copied from interface: MapAccessor
Remove an entry. If there is an accessor, it becomes invalid.

Specified by:
remove in interface MapAccessor
Throws:
AccessorException

setValue

public void setValue(Binding mapBinding,
                     java.lang.Object newMap)
              throws AccessorException
Description copied from interface: MapAccessor
Set & copy all entries from a Map Value. If entries are removed and they have accessors, the accessors are invalidated.

Specified by:
setValue in interface Accessor
Specified by:
setValue in interface MapAccessor
Throws:
AccessorException

getValueAccessor

public <T extends Accessor> T getValueAccessor(Binding keyBinding,
                                               java.lang.Object key)
                                    throws AccessorConstructionException
Description copied from interface: MapAccessor
Get an accessor to a value. It becomes invalid if the entry is removed or overwritten with a new value.

Specified by:
getValueAccessor in interface MapAccessor
Returns:
value accessor
Throws:
AccessorConstructionException

getAccessor

public <T extends Accessor> T getAccessor(AccessorReference reference)
                               throws AccessorConstructionException
Description copied from interface: Accessor
Get an accessor to a sub-container. If one already exists, the same is returned, otherwise a new is created.

InvalidatedEvent is thrown from the accessor if it is unlinked from the parent hierarchy.

Specified by:
getAccessor in interface Accessor
Parameters:
reference - component reference or null to return _this_ accessor
Returns:
accessor
Throws:
AccessorConstructionException

size

public int size()
         throws AccessorException
Description copied from interface: MapAccessor
Get the number of elements in the map

Specified by:
size in interface MapAccessor
Returns:
size
Throws:
AccessorException

containsKey

public boolean containsKey(Binding keyBinding,
                           java.lang.Object key)
                    throws AccessorException
Description copied from interface: MapAccessor
Returns true if map has a value for specified key

Specified by:
containsKey in interface MapAccessor
Returns:
true if entry exists
Throws:
AccessorException

containsValue

public boolean containsValue(Binding valueBinding,
                             java.lang.Object value)
                      throws AccessorException
Description copied from interface: MapAccessor
Returns true if map has a value for one or multiple keys

Specified by:
containsValue in interface MapAccessor
Returns:
true if value exists
Throws:
AccessorException

get

public java.lang.Object get(Binding keyBinding,
                            java.lang.Object key,
                            Binding valueBinding)
                     throws AccessorException
Description copied from interface: MapAccessor
Get the value that is specified for a key

Specified by:
get in interface MapAccessor
Returns:
the value or null
Throws:
AccessorException

getAll

public void getAll(Binding keyBinding,
                   Binding valueBinding,
                   java.util.Map<java.lang.Object,java.lang.Object> to)
            throws AccessorException
Description copied from interface: MapAccessor
Get all entries, write to a Java Collection

Specified by:
getAll in interface MapAccessor
Throws:
AccessorException

getAll

public void getAll(Binding keyBinding,
                   Binding valueBinding,
                   java.lang.Object[] keys,
                   java.lang.Object[] values)
            throws AccessorException
Description copied from interface: MapAccessor
Get all entries in order, write to 2 arrays.

Specified by:
getAll in interface MapAccessor
Throws:
AccessorException

getKeys

public java.lang.Object[] getKeys(Binding keyBinding)
                           throws AccessorException
Description copied from interface: MapAccessor
Get all keys in order

Specified by:
getKeys in interface MapAccessor
Returns:
an array or keys
Throws:
AccessorException

getValues

public java.lang.Object[] getValues(Binding valueBinding)
                             throws AccessorException
Description copied from interface: MapAccessor
Get all values

Specified by:
getValues in interface MapAccessor
Returns:
an array of values
Throws:
AccessorException

getCeilingKey

public java.lang.Object getCeilingKey(Binding keyBinding,
                                      java.lang.Object key)
                               throws AccessorException
Specified by:
getCeilingKey in interface MapAccessor
Throws:
AccessorException

getFirstKey

public java.lang.Object getFirstKey(Binding keyBinding)
                             throws AccessorException
Specified by:
getFirstKey in interface MapAccessor
Throws:
AccessorException

getLastKey

public java.lang.Object getLastKey(Binding keyBinding)
                            throws AccessorException
Specified by:
getLastKey in interface MapAccessor
Throws:
AccessorException

getFloorKey

public java.lang.Object getFloorKey(Binding keyBinding,
                                    java.lang.Object key)
                             throws AccessorException
Specified by:
getFloorKey in interface MapAccessor
Throws:
AccessorException

getHigherKey

public java.lang.Object getHigherKey(Binding keyBinding,
                                     java.lang.Object key)
                              throws AccessorException
Specified by:
getHigherKey in interface MapAccessor
Throws:
AccessorException

getLowerKey

public java.lang.Object getLowerKey(Binding keyBinding,
                                    java.lang.Object key)
                             throws AccessorException
Specified by:
getLowerKey in interface MapAccessor
Throws:
AccessorException

addListener

public void addListener(Accessor.Listener listener,
                        InterestSet interestSet,
                        AccessorReference path)
                 throws AccessorException
Description copied from interface: Accessor
Place a listener to an accessor node. The listener will be notified for changes in the node or posssibly its decendant nodes, depending on interest set.

The synchronization contract is implementation specific, so read the document. A common contract is that the listener object must not make modifications to the accessor within the handle event function. The correct strategy is to collect events and mutate the accessor afterwards.

Each event instance spawned by the listener, is annotated with a reference that describes the reference path of the node to which the event applies to. The path originates from the node where the listener was placed.

Listener is attached to the container that holds the value at the time at the of the adding. For example, If a listener is attached to an array of element at index 3, and a new value is inserted at position 2, the listener still monitors the same container, which is now at index 4. The references of incoming the events are modified to have the new index.

Also, if a new value is assigned to the parent of an object that is listened, the listener keeps on monitoring the new value at the same reference. This doesn't apply when a new value is set to a union of different tag, to a variant with a new type, or value is removed from Optional type. In these two cases the listener is invalidated.

See ChangeSet is an implementation that collects events.

Specified by:
addListener in interface Accessor
Overrides:
addListener in class JavaObject
path - path to the accessor or null. This is used in the events the accessor produces
Throws:
AccessorException
See Also:
collects events

removeListener

public void removeListener(Accessor.Listener listener)
                    throws AccessorException
Description copied from interface: Accessor
Remove a listener. If the listener is added multiple times, the last one added is removed.

Specified by:
removeListener in interface Accessor
Overrides:
removeListener in class JavaObject
Throws:
AccessorException