de.grogra.graph
Class GraphState

java.lang.Object
  extended by de.grogra.graph.GraphState
Direct Known Subclasses:
DelegateGraphState, GraphBase.State, State

public abstract class GraphState
extends java.lang.Object

A GraphState provides a context to access and modify a Graph. It also contains state information for object instancing and object context. Each graph state is associated with a thread, most operations may only be performed when this thread is the current thread.

Author:
Ole Kniemeyer
See Also:
Graph

Nested Class Summary
static class GraphState.ObjectContext
          This class represents an object context.
 
Constructor Summary
protected GraphState()
           
 
Method Summary
static int allocatePropertyId()
           
 void beginInstancing(java.lang.Object refNode, long id)
           
 boolean checkBoolean(java.lang.Object object, boolean asNode, BooleanAttribute a, boolean value)
           
 byte checkByte(java.lang.Object object, boolean asNode, ByteAttribute a, byte value)
           
 char checkChar(java.lang.Object object, boolean asNode, CharAttribute a, char value)
           
 double checkDouble(java.lang.Object object, boolean asNode, DoubleAttribute a, double value)
           
 float checkFloat(java.lang.Object object, boolean asNode, FloatAttribute a, float value)
           
 int checkInt(java.lang.Object object, boolean asNode, IntAttribute a, int value)
           
 long checkLong(java.lang.Object object, boolean asNode, LongAttribute a, long value)
           
<T> T
checkObject(java.lang.Object object, boolean asNode, ObjectAttribute<? extends T> a, T value)
           
 short checkShort(java.lang.Object object, boolean asNode, ShortAttribute a, short value)
           
abstract  boolean containsInTree(java.lang.Object object, boolean asNode)
          Tests whether an object is contained in the tree of the graph.
protected abstract  GraphState createDelegate(ThreadContext tc)
           
 GraphState.ObjectContext createObjectState(java.lang.Object object, boolean asNode)
           
static GraphState current(Graph graph)
          Returns the graph state of the graph which is valid within the current thread.
 void deinstantiate()
           
 void dispose()
           
 void endInstancing()
           
protected  void finalize()
           
abstract  void fireAttributeChanged(java.lang.Object object, boolean asNode, Attribute a, FieldChain field, int[] indices)
           
protected abstract  void fireEdgeChanged(java.lang.Object source, java.lang.Object target, java.lang.Object edge)
           
 GraphState forContext(ThreadContext tc)
           
static GraphState get(Graph graph, ThreadContext tc)
          Returns the graph state of the graph which is valid within the given ThreadContext.
 boolean getBoolean(java.lang.Object object, boolean asNode, BooleanAttribute a)
          Returns the value of attribute a for object in this graph state.
 boolean getBooleanDefault(java.lang.Object object, boolean asNode, BooleanAttribute a, boolean defaultValue)
          Returns the value of attribute a for object in this graph state.
 byte getByte(java.lang.Object object, boolean asNode, ByteAttribute a)
          Returns the value of attribute a for object in this graph state.
 byte getByteDefault(java.lang.Object object, boolean asNode, ByteAttribute a, byte defaultValue)
          Returns the value of attribute a for object in this graph state.
 char getChar(java.lang.Object object, boolean asNode, CharAttribute a)
          Returns the value of attribute a for object in this graph state.
 char getCharDefault(java.lang.Object object, boolean asNode, CharAttribute a, char defaultValue)
          Returns the value of attribute a for object in this graph state.
 ThreadContext getContext()
          Returns the ThreadContext within which operations on this graph state are valid.
 double getDouble(java.lang.Object object, boolean asNode, DoubleAttribute a)
          Returns the value of attribute a for object in this graph state.
 double getDoubleDefault(java.lang.Object object, boolean asNode, DoubleAttribute a, double defaultValue)
          Returns the value of attribute a for object in this graph state.
 float getFloat(java.lang.Object object, boolean asNode, FloatAttribute a)
          Returns the value of attribute a for object in this graph state.
 float getFloatDefault(java.lang.Object object, boolean asNode, FloatAttribute a, float defaultValue)
          Returns the value of attribute a for object in this graph state.
 Graph getGraph()
          Returns the graph of this graph state.
 Path getInstancingPath()
           
 int getInstancingPathIndex()
           
 int getInt(java.lang.Object object, boolean asNode, IntAttribute a)
          Returns the value of attribute a for object in this graph state.
 int getIntDefault(java.lang.Object object, boolean asNode, IntAttribute a, int defaultValue)
          Returns the value of attribute a for object in this graph state.
 long getLong(java.lang.Object object, boolean asNode, LongAttribute a)
          Returns the value of attribute a for object in this graph state.
 long getLongDefault(java.lang.Object object, boolean asNode, LongAttribute a, long defaultValue)
          Returns the value of attribute a for object in this graph state.
<T> T
getObject(java.lang.Object object, boolean asNode, ObjectAttribute<T> a)
           
<T> T
getObject(java.lang.Object object, boolean asNode, T placeIn, ObjectAttribute<T> a)
          Returns the value of attribute a for object in this graph state.
 GraphState.ObjectContext getObjectContext()
           
<T> T
getObjectDefault(java.lang.Object object, boolean asNode, ObjectAttribute<? extends T> a, T defaultValue)
          Returns the value of attribute a for object in this graph state.
 short getShort(java.lang.Object object, boolean asNode, ShortAttribute a)
          Returns the value of attribute a for object in this graph state.
 short getShortDefault(java.lang.Object object, boolean asNode, ShortAttribute a, short defaultValue)
          Returns the value of attribute a for object in this graph state.
 java.lang.Object getUserProperty(int id)
           
protected  void initialize(Graph graph, ThreadContext ctx)
           
 void instantiate(java.lang.Object object, boolean asNode, long id)
           
 void instantiateEdge(int edges, boolean edgeDirection, long id)
           
 void moveToInstance(int index)
           
 void moveToNextInstance()
           
 void moveToPreviousInstance()
           
abstract  void setEdgeBits(java.lang.Object edge, int bits)
           
 void setInstanceAttribute(Attribute a, java.lang.Object value)
           
 void setObjectContext(GraphState.ObjectContext newState)
           
 void setObjectContext(java.lang.Object object, boolean asNode)
           
 java.lang.Object setUserProperty(int id, java.lang.Object value)
           
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

GraphState

protected GraphState()
Method Detail

allocatePropertyId

public static int allocatePropertyId()

beginInstancing

public void beginInstancing(java.lang.Object refNode,
                            long id)

checkBoolean

public boolean checkBoolean(java.lang.Object object,
                            boolean asNode,
                            BooleanAttribute a,
                            boolean value)

checkByte

public byte checkByte(java.lang.Object object,
                      boolean asNode,
                      ByteAttribute a,
                      byte value)

checkChar

public char checkChar(java.lang.Object object,
                      boolean asNode,
                      CharAttribute a,
                      char value)

checkDouble

public double checkDouble(java.lang.Object object,
                          boolean asNode,
                          DoubleAttribute a,
                          double value)

checkFloat

public float checkFloat(java.lang.Object object,
                        boolean asNode,
                        FloatAttribute a,
                        float value)

checkInt

public int checkInt(java.lang.Object object,
                    boolean asNode,
                    IntAttribute a,
                    int value)

checkLong

public long checkLong(java.lang.Object object,
                      boolean asNode,
                      LongAttribute a,
                      long value)

checkObject

public <T> T checkObject(java.lang.Object object,
                         boolean asNode,
                         ObjectAttribute<? extends T> a,
                         T value)

checkShort

public short checkShort(java.lang.Object object,
                        boolean asNode,
                        ShortAttribute a,
                        short value)

containsInTree

public abstract boolean containsInTree(java.lang.Object object,
                                       boolean asNode)
Tests whether an object is contained in the tree of the graph. The tree is defined by Graph.getTreePattern().

Parameters:
object - the object
asNode - true if object is a node, false if object is an edge
Returns:
true iff the object is part of the tree

createDelegate

protected abstract GraphState createDelegate(ThreadContext tc)

createObjectState

public GraphState.ObjectContext createObjectState(java.lang.Object object,
                                                  boolean asNode)

current

public static GraphState current(Graph graph)
Returns the graph state of the graph which is valid within the current thread.

Parameters:
graph - a graph
Returns:
the graph state for current thread, or null if such a graph state has not yet been created

deinstantiate

public void deinstantiate()

dispose

public void dispose()

endInstancing

public void endInstancing()

finalize

protected void finalize()
Overrides:
finalize in class java.lang.Object

fireAttributeChanged

public abstract void fireAttributeChanged(java.lang.Object object,
                                          boolean asNode,
                                          Attribute a,
                                          FieldChain field,
                                          int[] indices)

fireEdgeChanged

protected abstract void fireEdgeChanged(java.lang.Object source,
                                        java.lang.Object target,
                                        java.lang.Object edge)

forContext

public GraphState forContext(ThreadContext tc)

get

public static GraphState get(Graph graph,
                             ThreadContext tc)
Returns the graph state of the graph which is valid within the given ThreadContext.

Parameters:
graph - a graph
tc - a thread context
Returns:
the graph state for the context, or null if such a graph state has not yet been created

getBoolean

public boolean getBoolean(java.lang.Object object,
                          boolean asNode,
                          BooleanAttribute a)
Returns the value of attribute a for object in this graph state. This method respects derived attributes and attribute values of instantiated objects which are set by setInstanceAttribute(Attribute, Object).

Parameters:
object - the object
asNode - true if object is a node, false if object is an edge
a - the attribute to read
Returns:
value of the attribute for the object
Throws:
NoSuchKeyException - if the attribute is not defined for the object

getBooleanDefault

public boolean getBooleanDefault(java.lang.Object object,
                                 boolean asNode,
                                 BooleanAttribute a,
                                 boolean defaultValue)
Returns the value of attribute a for object in this graph state. If no such value is defined, defaultValue is used instead. This method respects derived attributes and attribute values of instantiated objects which are set by setInstanceAttribute(Attribute, Object).

Parameters:
object - the object
asNode - true if object is a node, false if object is an edge
a - the attribute to read
defaultValue - default value to return if the attribute is not defined on object
Returns:
value of the attribute for the object, or defaultValue

getByte

public byte getByte(java.lang.Object object,
                    boolean asNode,
                    ByteAttribute a)
Returns the value of attribute a for object in this graph state. This method respects derived attributes and attribute values of instantiated objects which are set by setInstanceAttribute(Attribute, Object).

Parameters:
object - the object
asNode - true if object is a node, false if object is an edge
a - the attribute to read
Returns:
value of the attribute for the object
Throws:
NoSuchKeyException - if the attribute is not defined for the object

getByteDefault

public byte getByteDefault(java.lang.Object object,
                           boolean asNode,
                           ByteAttribute a,
                           byte defaultValue)
Returns the value of attribute a for object in this graph state. If no such value is defined, defaultValue is used instead. This method respects derived attributes and attribute values of instantiated objects which are set by setInstanceAttribute(Attribute, Object).

Parameters:
object - the object
asNode - true if object is a node, false if object is an edge
a - the attribute to read
defaultValue - default value to return if the attribute is not defined on object
Returns:
value of the attribute for the object, or defaultValue

getChar

public char getChar(java.lang.Object object,
                    boolean asNode,
                    CharAttribute a)
Returns the value of attribute a for object in this graph state. This method respects derived attributes and attribute values of instantiated objects which are set by setInstanceAttribute(Attribute, Object).

Parameters:
object - the object
asNode - true if object is a node, false if object is an edge
a - the attribute to read
Returns:
value of the attribute for the object
Throws:
NoSuchKeyException - if the attribute is not defined for the object

getCharDefault

public char getCharDefault(java.lang.Object object,
                           boolean asNode,
                           CharAttribute a,
                           char defaultValue)
Returns the value of attribute a for object in this graph state. If no such value is defined, defaultValue is used instead. This method respects derived attributes and attribute values of instantiated objects which are set by setInstanceAttribute(Attribute, Object).

Parameters:
object - the object
asNode - true if object is a node, false if object is an edge
a - the attribute to read
defaultValue - default value to return if the attribute is not defined on object
Returns:
value of the attribute for the object, or defaultValue

getContext

public final ThreadContext getContext()
Returns the ThreadContext within which operations on this graph state are valid.

Returns:
ThreadContext of this graph state

getDouble

public double getDouble(java.lang.Object object,
                        boolean asNode,
                        DoubleAttribute a)
Returns the value of attribute a for object in this graph state. This method respects derived attributes and attribute values of instantiated objects which are set by setInstanceAttribute(Attribute, Object).

Parameters:
object - the object
asNode - true if object is a node, false if object is an edge
a - the attribute to read
Returns:
value of the attribute for the object
Throws:
NoSuchKeyException - if the attribute is not defined for the object

getDoubleDefault

public double getDoubleDefault(java.lang.Object object,
                               boolean asNode,
                               DoubleAttribute a,
                               double defaultValue)
Returns the value of attribute a for object in this graph state. If no such value is defined, defaultValue is used instead. This method respects derived attributes and attribute values of instantiated objects which are set by setInstanceAttribute(Attribute, Object).

Parameters:
object - the object
asNode - true if object is a node, false if object is an edge
a - the attribute to read
defaultValue - default value to return if the attribute is not defined on object
Returns:
value of the attribute for the object, or defaultValue

getFloat

public float getFloat(java.lang.Object object,
                      boolean asNode,
                      FloatAttribute a)
Returns the value of attribute a for object in this graph state. This method respects derived attributes and attribute values of instantiated objects which are set by setInstanceAttribute(Attribute, Object).

Parameters:
object - the object
asNode - true if object is a node, false if object is an edge
a - the attribute to read
Returns:
value of the attribute for the object
Throws:
NoSuchKeyException - if the attribute is not defined for the object

getFloatDefault

public float getFloatDefault(java.lang.Object object,
                             boolean asNode,
                             FloatAttribute a,
                             float defaultValue)
Returns the value of attribute a for object in this graph state. If no such value is defined, defaultValue is used instead. This method respects derived attributes and attribute values of instantiated objects which are set by setInstanceAttribute(Attribute, Object).

Parameters:
object - the object
asNode - true if object is a node, false if object is an edge
a - the attribute to read
defaultValue - default value to return if the attribute is not defined on object
Returns:
value of the attribute for the object, or defaultValue

getGraph

public final Graph getGraph()
Returns the graph of this graph state.

Returns:
graph of this state

getInstancingPath

public Path getInstancingPath()

getInstancingPathIndex

public int getInstancingPathIndex()

getInt

public int getInt(java.lang.Object object,
                  boolean asNode,
                  IntAttribute a)
Returns the value of attribute a for object in this graph state. This method respects derived attributes and attribute values of instantiated objects which are set by setInstanceAttribute(Attribute, Object).

Parameters:
object - the object
asNode - true if object is a node, false if object is an edge
a - the attribute to read
Returns:
value of the attribute for the object
Throws:
NoSuchKeyException - if the attribute is not defined for the object

getIntDefault

public int getIntDefault(java.lang.Object object,
                         boolean asNode,
                         IntAttribute a,
                         int defaultValue)
Returns the value of attribute a for object in this graph state. If no such value is defined, defaultValue is used instead. This method respects derived attributes and attribute values of instantiated objects which are set by setInstanceAttribute(Attribute, Object).

Parameters:
object - the object
asNode - true if object is a node, false if object is an edge
a - the attribute to read
defaultValue - default value to return if the attribute is not defined on object
Returns:
value of the attribute for the object, or defaultValue

getLong

public long getLong(java.lang.Object object,
                    boolean asNode,
                    LongAttribute a)
Returns the value of attribute a for object in this graph state. This method respects derived attributes and attribute values of instantiated objects which are set by setInstanceAttribute(Attribute, Object).

Parameters:
object - the object
asNode - true if object is a node, false if object is an edge
a - the attribute to read
Returns:
value of the attribute for the object
Throws:
NoSuchKeyException - if the attribute is not defined for the object

getLongDefault

public long getLongDefault(java.lang.Object object,
                           boolean asNode,
                           LongAttribute a,
                           long defaultValue)
Returns the value of attribute a for object in this graph state. If no such value is defined, defaultValue is used instead. This method respects derived attributes and attribute values of instantiated objects which are set by setInstanceAttribute(Attribute, Object).

Parameters:
object - the object
asNode - true if object is a node, false if object is an edge
a - the attribute to read
defaultValue - default value to return if the attribute is not defined on object
Returns:
value of the attribute for the object, or defaultValue

getObject

public <T> T getObject(java.lang.Object object,
                       boolean asNode,
                       ObjectAttribute<T> a)

getObject

public <T> T getObject(java.lang.Object object,
                       boolean asNode,
                       T placeIn,
                       ObjectAttribute<T> a)
Returns the value of attribute a for object in this graph state. This method respects derived attributes and attribute values of instantiated objects which are set by setInstanceAttribute(Attribute, Object).

Parameters:
object - the object
asNode - true if object is a node, false if object is an edge
a - the attribute to read
placeIn - an instance for the result may be provided by the caller
Returns:
value of the attribute for the object
Throws:
NoSuchKeyException - if the attribute is not defined for the object

getObjectContext

public GraphState.ObjectContext getObjectContext()

getObjectDefault

public <T> T getObjectDefault(java.lang.Object object,
                              boolean asNode,
                              ObjectAttribute<? extends T> a,
                              T defaultValue)
Returns the value of attribute a for object in this graph state. If no such value is defined, defaultValue is used instead. This method respects derived attributes and attribute values of instantiated objects which are set by setInstanceAttribute(Attribute, Object).

Parameters:
object - the object
asNode - true if object is a node, false if object is an edge
a - the attribute to read
defaultValue - default value to return if the attribute is not defined on object
Returns:
value of the attribute for the object, or defaultValue

getShort

public short getShort(java.lang.Object object,
                      boolean asNode,
                      ShortAttribute a)
Returns the value of attribute a for object in this graph state. This method respects derived attributes and attribute values of instantiated objects which are set by setInstanceAttribute(Attribute, Object).

Parameters:
object - the object
asNode - true if object is a node, false if object is an edge
a - the attribute to read
Returns:
value of the attribute for the object
Throws:
NoSuchKeyException - if the attribute is not defined for the object

getShortDefault

public short getShortDefault(java.lang.Object object,
                             boolean asNode,
                             ShortAttribute a,
                             short defaultValue)
Returns the value of attribute a for object in this graph state. If no such value is defined, defaultValue is used instead. This method respects derived attributes and attribute values of instantiated objects which are set by setInstanceAttribute(Attribute, Object).

Parameters:
object - the object
asNode - true if object is a node, false if object is an edge
a - the attribute to read
defaultValue - default value to return if the attribute is not defined on object
Returns:
value of the attribute for the object, or defaultValue

getUserProperty

public java.lang.Object getUserProperty(int id)

initialize

protected void initialize(Graph graph,
                          ThreadContext ctx)

instantiate

public void instantiate(java.lang.Object object,
                        boolean asNode,
                        long id)

instantiateEdge

public void instantiateEdge(int edges,
                            boolean edgeDirection,
                            long id)

moveToInstance

public void moveToInstance(int index)

moveToNextInstance

public void moveToNextInstance()

moveToPreviousInstance

public void moveToPreviousInstance()

setEdgeBits

public abstract void setEdgeBits(java.lang.Object edge,
                                 int bits)

setInstanceAttribute

public void setInstanceAttribute(Attribute a,
                                 java.lang.Object value)

setObjectContext

public void setObjectContext(GraphState.ObjectContext newState)

setObjectContext

public void setObjectContext(java.lang.Object object,
                             boolean asNode)

setUserProperty

public java.lang.Object setUserProperty(int id,
                                        java.lang.Object value)