de.grogra.graph.impl
Class Node

java.lang.Object
  extended by de.grogra.graph.impl.Edge
      extended by de.grogra.graph.impl.Node
All Implemented Interfaces:
Manageable, PersistenceCapable, Shareable, UserFields, XObject, Map, java.io.Serializable
Direct Known Subclasses:
AdjustLU, Assignment, Axiom, BlendItem, BooleanNode, ByteNode, C0, Cell, ChannelMapNode, CharNode, D0, DoubleNode, Expression, FieldUpdater, FloatNode, FruitObject, H0, HDir, IncScale, InterpretiveMark, IntNode, InvokeMethod, Item, K, KAssignment, KL, L0, LeafObject, LongNode, MSMLMetadata, MSNode, N0, Null, ObjectNode, P0, RGG, RGGRoot, Rotate, Rotation, Scale, SharedObjectNode, ShortNode, ToolRoot, Translate, Tropism, U0, V0, Variation

public class Node
extends Edge
implements PersistenceCapable, Shareable, Map, XObject, UserFields

This class represents the base class of nodes in a GraphManager. Such a graph is used, e.g., as the project graph of the GroIMP software.

Node extends Edge: A Node is able to represent not only itself, but also a single incoming edge. The advantage of this feature is the reduced number of instances for a given graph. E.g., a tree graph with N nodes has N-1 edges. Assuming that they point from a parent to child, all these edges can be represented as part of the child node instances.

If a node is part of the graph of GraphManager, it can be identified by its unique id. A node also has a name, however, this may be null and is not unique. Nevertheless, the graph maintains a map from names to nodes which may be used to efficiently obtain nodes having some specified name.

Author:
Ole Kniemeyer
See Also:
Serialized Form

Nested Class Summary
static class Node.AccessorBridge
           
static class Node.FieldAttributeAccessor
           
static class Node.NType
           
 
Nested classes/interfaces inherited from interface de.grogra.util.Map
Map.Chain
 
Field Summary
static Node.NType $TYPE
           
static ObjectAttribute ADDITIONAL_FIELDS
           
protected  int bits
          This field packs the information of some boolean and integral attributes into a single 32-bit value.
static int DELETED
           
static int EXTENT_BIT
           
static int EXTENT_MASK
           
static Node.NType.Field extentIndex$FIELD
           
static Node.NType.Field extentTail$FIELD
           
static int HAS_OBSERVERS
           
static int IS_INTERPRETIVE
           
static Node.NType.Field isInterpretive$FIELD
           
static int LAST_EXTENT_INDEX
           
static Node.NType.Field layer$FIELD
           
static int MARK
           
static Node.NType.Field mark$FIELD
           
static MimeType MIME_TYPE
           
static int MIN_UNUSED_SPECIAL_OF_SOURCE
           
static int MIN_UNUSED_SPECIAL_OF_TARGET
           
static Node.NType.Field name$FIELD
           
static int USED_BITS
           
 
Fields inherited from interface de.grogra.util.Map
DEFAULT_VALUE, EMPTY_MAP
 
Constructor Summary
Node()
           
 
Method Summary
 void addEdgeBitsTo(Node target, int edges, Transaction t)
           
 void addReference(SharedObjectReference ref)
           
 void appendBranchNode(Node node)
           
 void appendBranchNode(Node node, Transaction xa)
           
 void appendReferencesTo(java.util.List out)
           
protected  java.lang.Object clone()
           
 Node clone(boolean cloneFields)
          Creates a clone of this node using the methods newInstance() and dup(de.grogra.graph.impl.Node, boolean, de.grogra.persistence.Transaction).
 Node cloneGraph(EdgePattern edges, boolean cloneFields)
           
 void dump()
           
 void dumpTree()
           
 void dup(Node original, boolean cloneFields, Transaction t)
           
protected  void dupUnmanagedFields(Node original)
           
protected  void edgeChanged(Edge set, int old, Transaction t)
           
 void fieldModified(PersistenceField field, int[] indices, Transaction t)
           
 Node findAdjacent(boolean in, boolean out, int edgeBits)
          Find an adjacent node n to this one.
 java.lang.Object get(java.lang.Object key, java.lang.Object defaultValue)
          Returns the value associated with key.
 AttributeAccessor getAccessor(Attribute attribute)
           
 AttributeAccessor getAccessor(java.lang.String name)
           
 Attribute[] getAttributes()
           
 Node getAxisParent()
          Returns the parent node of this node.
protected  boolean getBoolean(BooleanAttribute a, GraphState gs)
           
 Node getBranch()
          Returns the first child of this node.
 int getBranchLength()
           
 Node getBranchNode(int index)
          Returns the index-th child of this node.
 Node getBranchTail()
           
protected  byte getByte(ByteAttribute a, GraphState gs)
           
protected  char getChar(CharAttribute a, GraphState gs)
           
 Node getCommonAncestor(Node n)
           
 GraphState getCurrentGraphState()
           
 int getDirectChildCount()
           
protected  double getDouble(DoubleAttribute a, GraphState gs)
           
 AttributeAccessor getEdgeAttributeAccessor(Attribute attribute)
           
 Attribute[] getEdgeAttributes(Edge edge)
           
 int getEdgeBitsTo(Node target)
           
 Edge getEdgeTo(Node target)
           
 int getExtentIndex()
          Returns the extentIndex property of this node.
 Node getFirst(int edgeBits)
           
 Edge getFirstEdge()
           
protected  float getFloat(FloatAttribute a, GraphState gs)
           
 GraphManager getGraph()
           
 long getId()
          Returns a unique ID for this node.
 int getIndex()
          Returns the index of this node in the list of children of its parent.
 Instantiator getInstantiator()
           
protected  int getInt(IntAttribute a, GraphState gs)
           
 int getLayer()
           
protected  long getLong(LongAttribute a, GraphState gs)
           
 ManageableType getManageableType()
           
 java.lang.String getName()
          Returns the name of this node.
 Node getNeighbor(Node start)
           
 Edge getNext(Node parent)
           
 Node.NType getNType()
           
protected  Node.NType getNTypeImpl()
          This method returns the Node.NType which describes the managed fields of the class of this node.
protected  java.lang.Object getObject(ObjectAttribute a, java.lang.Object placeIn, GraphState gs)
           
 Edge getOrCreateEdgeTo(Node target)
           
 java.lang.Object getOrNull(java.lang.Object key)
           
 PersistenceManager getPersistenceManager()
           
 Node getPredecessor()
          Returns the previous sibling of this node.
 SharedObjectProvider getProvider()
           
protected  short getShort(ShortAttribute a, GraphState gs)
           
 Node getSource()
           
 int getStamp()
          Returns a stamp for this object.
 Node getSuccessor()
          Returns the next sibling of this node.
 int getSymbol()
           
 int getSymbolColor()
           
 Node getTarget()
           
 Transaction getTransaction(boolean create)
           
 Field getUserField(int index)
           
 int getUserFieldCount()
           
 XClass getXClass()
           
 de.grogra.graph.impl.NodeData getXData()
           
 boolean hasName(java.lang.String name)
          Tests if this node has the specified name.
 void initProvider(SharedObjectProvider provider)
           
 void initXClass(XClass cls)
           
 void insertBranchNode(int index, Node node)
           
 void insertBranchNode(int index, Node node, Transaction xa)
           
 boolean instantiateGraph(int edges, ArrayPath path, Visitor v)
           
 boolean isAncestorOf(Node n)
           
 boolean isDirection(Node source, Node target)
           
 boolean isManagingInstance()
           
 boolean isMarked()
           
 boolean isRoot()
           
 boolean isSource(Node node)
           
 boolean isTarget(Node node)
           
 Manageable manageableReadResolve()
           
 java.lang.Object manageableWriteReplace()
           
protected  Node newInstance()
          This method returns a new instance of the class of this node.
protected  java.lang.String paramString()
          Computes the class-specific part of the string returned by toString() which shall be enclosed in brackets.
 void removeAll(Transaction t)
           
 void removeEdgeBitsTo(Node target, int edges, Transaction t)
           
 void removeFromChain()
           
 void removeFromChain(Transaction t)
           
 void removeReference(SharedObjectReference ref)
           
 void setBranch(Node c)
           
 void setBranch(Node c, Transaction xa)
           
 void setExtentIndex(int index)
          Sets the extentIndex property of this node
 GraphManager setGraphForDeserialization(GraphManager mgr)
          When a serialized stream containing references to already existing nodes is deserialized, the graph to use for resolving the id-based references has to be specified by this method.
 void setLayer(int layer)
           
 void setMark(boolean value)
           
 void setName(java.lang.String name)
          Sets the name of this node.
 void setSuccessor(Node s)
           
 void setSuccessor(Node s, Transaction xa)
           
protected  void specialEdgeAdded(Edge set, Transaction t)
           
protected  void specialEdgeRefModified(Node ref, Node.NType.Field edgeField, PersistenceField field, int[] indices, Transaction t)
           
protected  void specialEdgeRemoved(Edge set, int old, Transaction t)
           
 java.lang.String toString()
           
protected  java.lang.Object writeReplace()
          This method is used by object serialization.
 
Methods inherited from class de.grogra.graph.impl.Edge
addEdgeBits, getBitMark, getEdgeBits, getObjectMark, getSpecialEdgeDescriptor, parseEdgeKeys, remove, removeEdgeBits, setBitMark, setEdgeBits, setObjectMark, testEdgeBits
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface de.grogra.persistence.PersistenceCapable
getBitMark, getObjectMark, setBitMark, setObjectMark
 

Field Detail

$TYPE

public static final Node.NType $TYPE

ADDITIONAL_FIELDS

public static final ObjectAttribute ADDITIONAL_FIELDS

bits

protected int bits
This field packs the information of some boolean and integral attributes into a single 32-bit value. The bits defined in the base class Node are the first USED_BITS bits, starting at bit 0.


DELETED

public static final int DELETED
See Also:
Constant Field Values

EXTENT_BIT

public static final int EXTENT_BIT
See Also:
Constant Field Values

EXTENT_MASK

public static final int EXTENT_MASK
See Also:
Constant Field Values

extentIndex$FIELD

public static final Node.NType.Field extentIndex$FIELD

extentTail$FIELD

public static final Node.NType.Field extentTail$FIELD

HAS_OBSERVERS

public static final int HAS_OBSERVERS
See Also:
Constant Field Values

IS_INTERPRETIVE

public static final int IS_INTERPRETIVE
See Also:
Constant Field Values

isInterpretive$FIELD

public static final Node.NType.Field isInterpretive$FIELD

LAST_EXTENT_INDEX

public static final int LAST_EXTENT_INDEX
See Also:
Constant Field Values

layer$FIELD

public static final Node.NType.Field layer$FIELD

MARK

public static final int MARK
See Also:
Constant Field Values

mark$FIELD

public static final Node.NType.Field mark$FIELD

MIME_TYPE

public static final MimeType MIME_TYPE

MIN_UNUSED_SPECIAL_OF_SOURCE

public static final int MIN_UNUSED_SPECIAL_OF_SOURCE
See Also:
Constant Field Values

MIN_UNUSED_SPECIAL_OF_TARGET

public static final int MIN_UNUSED_SPECIAL_OF_TARGET
See Also:
Constant Field Values

name$FIELD

public static final Node.NType.Field name$FIELD

USED_BITS

public static final int USED_BITS
See Also:
Constant Field Values
Constructor Detail

Node

public Node()
Method Detail

addEdgeBitsTo

public final void addEdgeBitsTo(Node target,
                                int edges,
                                Transaction t)

addReference

public void addReference(SharedObjectReference ref)
Specified by:
addReference in interface Shareable

appendBranchNode

public void appendBranchNode(Node node)

appendBranchNode

public void appendBranchNode(Node node,
                             Transaction xa)

appendReferencesTo

public void appendReferencesTo(java.util.List out)
Specified by:
appendReferencesTo in interface Shareable

clone

protected java.lang.Object clone()
                          throws java.lang.CloneNotSupportedException
Overrides:
clone in class java.lang.Object
Throws:
java.lang.CloneNotSupportedException

clone

public Node clone(boolean cloneFields)
           throws java.lang.CloneNotSupportedException
Creates a clone of this node using the methods newInstance() and dup(de.grogra.graph.impl.Node, boolean, de.grogra.persistence.Transaction). The clone is not part of the graph.

Parameters:
cloneFields - perform a deep clone of field values?
Returns:
clone of this node
Throws:
java.lang.CloneNotSupportedException

cloneGraph

public Node cloneGraph(EdgePattern edges,
                       boolean cloneFields)
                throws java.lang.CloneNotSupportedException
Throws:
java.lang.CloneNotSupportedException

dump

public void dump()

dumpTree

public void dumpTree()

dup

public void dup(Node original,
                boolean cloneFields,
                Transaction t)
         throws java.lang.CloneNotSupportedException
Throws:
java.lang.CloneNotSupportedException

dupUnmanagedFields

protected void dupUnmanagedFields(Node original)

edgeChanged

protected void edgeChanged(Edge set,
                           int old,
                           Transaction t)

fieldModified

public void fieldModified(PersistenceField field,
                          int[] indices,
                          Transaction t)
Specified by:
fieldModified in interface Manageable

findAdjacent

public Node findAdjacent(boolean in,
                         boolean out,
                         int edgeBits)
Find an adjacent node n to this one. The edgeBits are used to determine if a relation between those two nodes exists (Edge.testEdgeBits(int)). If out is true and this node is the source or if in is true and this node is the target, n is returned. Thus, if in and out is true, any adjacent node where the connecting edge matches the edgeBits is considered.

Parameters:
in - true if edges incoming to this node should be considered
out - true if edges outgoing from this node should be considered
edgeBits - the type/types of edges to consider
Returns:
an adjacent node that matches the criteria or null if none found

get

public java.lang.Object get(java.lang.Object key,
                            java.lang.Object defaultValue)
Description copied from interface: Map
Returns the value associated with key. If there is no value associated with key, defaultValue is returned.

Specified by:
get in interface Map
Parameters:
key - a key for the map
defaultValue - the default value
Returns:
the associated value, or defaultValue

getAccessor

public AttributeAccessor getAccessor(Attribute attribute)

getAccessor

public AttributeAccessor getAccessor(java.lang.String name)

getAttributes

public Attribute[] getAttributes()

getAxisParent

public Node getAxisParent()
Returns the parent node of this node. The underlying tree structure is defined by the edges Graph.BRANCH_EDGE and Graph.SUCCESSOR_EDGE.

Returns:
the parent
See Also:
getBranch()

getBoolean

protected boolean getBoolean(BooleanAttribute a,
                             GraphState gs)

getBranch

public Node getBranch()
Returns the first child of this node. The underlying tree structure is defined by the edges Graph.BRANCH_EDGE and Graph.SUCCESSOR_EDGE: The first child of a node is reached by traversing a Graph.BRANCH_EDGE in forward direction, its siblings are reached by traversing Graph.SUCCESSOR_EDGE in forward direction from sibling to sibling.

Returns:
the first child, or null

getBranchLength

public int getBranchLength()

getBranchNode

public Node getBranchNode(int index)
Returns the index-th child of this node. The underlying tree structure is defined by the edges Graph.BRANCH_EDGE and Graph.SUCCESSOR_EDGE.

Parameters:
index - an index
Returns:
the index-th child
See Also:
getBranch()

getBranchTail

public Node getBranchTail()

getByte

protected byte getByte(ByteAttribute a,
                       GraphState gs)

getChar

protected char getChar(CharAttribute a,
                       GraphState gs)

getCommonAncestor

public Node getCommonAncestor(Node n)

getCurrentGraphState

public final GraphState getCurrentGraphState()

getDirectChildCount

public int getDirectChildCount()

getDouble

protected double getDouble(DoubleAttribute a,
                           GraphState gs)

getEdgeAttributeAccessor

public AttributeAccessor getEdgeAttributeAccessor(Attribute attribute)

getEdgeAttributes

public Attribute[] getEdgeAttributes(Edge edge)

getEdgeBitsTo

public final int getEdgeBitsTo(Node target)

getEdgeTo

public final Edge getEdgeTo(Node target)

getExtentIndex

public int getExtentIndex()
Returns the extentIndex property of this node. This determines the index of the list of the Extent in which this node is inserted.

Returns:
insert node at tail or head of linked list of extent?

getFirst

public Node getFirst(int edgeBits)

getFirstEdge

public final Edge getFirstEdge()

getFloat

protected float getFloat(FloatAttribute a,
                         GraphState gs)

getGraph

public final GraphManager getGraph()

getId

public final long getId()
Returns a unique ID for this node. The IDs are serially counted up from zero for each node that is created and inserted into the graph. Nodes that are created but not inserted into the graph have an ID of -1. Nodes that were part of the graph, but were removed later on have an ID of -2.

Specified by:
getId in interface PersistenceCapable

getIndex

public int getIndex()
Returns the index of this node in the list of children of its parent. The underlying tree structure is defined by the edges Graph.BRANCH_EDGE and Graph.SUCCESSOR_EDGE.

Returns:
the child index of this node
See Also:
getBranch()

getInstantiator

public Instantiator getInstantiator()

getInt

protected int getInt(IntAttribute a,
                     GraphState gs)

getLayer

public int getLayer()

getLong

protected long getLong(LongAttribute a,
                       GraphState gs)

getManageableType

public final ManageableType getManageableType()
Specified by:
getManageableType in interface Manageable

getName

public final java.lang.String getName()
Returns the name of this node. Names are not unique and may be null. The graph of this node maintains a map from names to nodes, see GraphManager.getNodeForName(String).

Returns:
name of this node, may be null

getNeighbor

public final Node getNeighbor(Node start)
Specified by:
getNeighbor in class Edge

getNext

public final Edge getNext(Node parent)
Specified by:
getNext in class Edge

getNType

public final Node.NType getNType()

getNTypeImpl

protected Node.NType getNTypeImpl()
This method returns the Node.NType which describes the managed fields of the class of this node. This method has to be implemented in every concrete subclass.

Returns:
type describing the managed fields of the class of this node

getObject

protected java.lang.Object getObject(ObjectAttribute a,
                                     java.lang.Object placeIn,
                                     GraphState gs)

getOrCreateEdgeTo

public final Edge getOrCreateEdgeTo(Node target)

getOrNull

public java.lang.Object getOrNull(java.lang.Object key)

getPersistenceManager

public final PersistenceManager getPersistenceManager()
Specified by:
getPersistenceManager in interface PersistenceCapable

getPredecessor

public Node getPredecessor()
Returns the previous sibling of this node. The underlying tree structure is defined by the edges Graph.BRANCH_EDGE and Graph.SUCCESSOR_EDGE.

Returns:
the previous sibling
See Also:
getBranch()

getProvider

public SharedObjectProvider getProvider()
Specified by:
getProvider in interface Shareable

getShort

protected short getShort(ShortAttribute a,
                         GraphState gs)

getSource

public final Node getSource()
Specified by:
getSource in class Edge

getStamp

public int getStamp()
Description copied from interface: Manageable
Returns a stamp for this object. Each modification to this object increments the stamp. The initial stamp is non-negative.

Specified by:
getStamp in interface Manageable
Returns:
a stamp

getSuccessor

public Node getSuccessor()
Returns the next sibling of this node. The underlying tree structure is defined by the edges Graph.BRANCH_EDGE and Graph.SUCCESSOR_EDGE.

Returns:
the next sibling
See Also:
getBranch()

getSymbol

public int getSymbol()

getSymbolColor

public int getSymbolColor()

getTarget

public final Node getTarget()
Specified by:
getTarget in class Edge

getTransaction

public final Transaction getTransaction(boolean create)

getUserField

public Field getUserField(int index)
Specified by:
getUserField in interface UserFields

getUserFieldCount

public int getUserFieldCount()
Specified by:
getUserFieldCount in interface UserFields

getXClass

public final XClass getXClass()
Specified by:
getXClass in interface XObject

getXData

public final de.grogra.graph.impl.NodeData getXData()
Specified by:
getXData in interface XObject

hasName

public final boolean hasName(java.lang.String name)
Tests if this node has the specified name. I.e., both name and this node's name are null, or they consist of the same sequence of characters.

Parameters:
name - a name to test
Returns:
has this node the specified name?

initProvider

public void initProvider(SharedObjectProvider provider)
Specified by:
initProvider in interface Shareable

initXClass

public final void initXClass(XClass cls)
Specified by:
initXClass in interface XObject

insertBranchNode

public void insertBranchNode(int index,
                             Node node)

insertBranchNode

public void insertBranchNode(int index,
                             Node node,
                             Transaction xa)

instantiateGraph

public boolean instantiateGraph(int edges,
                                ArrayPath path,
                                Visitor v)

isAncestorOf

public boolean isAncestorOf(Node n)

isDirection

public boolean isDirection(Node source,
                           Node target)
Specified by:
isDirection in class Edge

isManagingInstance

public boolean isManagingInstance()

isMarked

public boolean isMarked()

isRoot

public boolean isRoot()

isSource

public boolean isSource(Node node)
Specified by:
isSource in class Edge

isTarget

public boolean isTarget(Node node)
Specified by:
isTarget in class Edge

manageableReadResolve

public Manageable manageableReadResolve()
Specified by:
manageableReadResolve in interface Manageable

manageableWriteReplace

public java.lang.Object manageableWriteReplace()
Specified by:
manageableWriteReplace in interface Manageable

newInstance

protected Node newInstance()
This method returns a new instance of the class of this node. This method has to be implemented in every concrete subclass.

Returns:
new instance of class of this node

paramString

protected java.lang.String paramString()
Computes the class-specific part of the string returned by toString() which shall be enclosed in brackets. This should be used to show important properties of this node.

Returns:
string describing some important properties of this node

removeAll

public final void removeAll(Transaction t)

removeEdgeBitsTo

public final void removeEdgeBitsTo(Node target,
                                   int edges,
                                   Transaction t)

removeFromChain

public void removeFromChain()

removeFromChain

public void removeFromChain(Transaction t)

removeReference

public void removeReference(SharedObjectReference ref)
Specified by:
removeReference in interface Shareable

setBranch

public void setBranch(Node c)

setBranch

public void setBranch(Node c,
                      Transaction xa)

setExtentIndex

public void setExtentIndex(int index)
Sets the extentIndex property of this node

Parameters:
index - new value for property
See Also:
getExtentIndex()

setGraphForDeserialization

public GraphManager setGraphForDeserialization(GraphManager mgr)
When a serialized stream containing references to already existing nodes is deserialized, the graph to use for resolving the id-based references has to be specified by this method. The invocation has to be in the thread which will be used for deserialization.

Parameters:
mgr - the graph to use for id-resolution within deserialization
Returns:
graph which has been used previously, possibly null

setLayer

public void setLayer(int layer)

setMark

public void setMark(boolean value)

setName

public void setName(java.lang.String name)
Sets the name of this node.

Parameters:
name - new name of node, may be null
See Also:
getName()

setSuccessor

public void setSuccessor(Node s)

setSuccessor

public void setSuccessor(Node s,
                         Transaction xa)

specialEdgeAdded

protected void specialEdgeAdded(Edge set,
                                Transaction t)

specialEdgeRefModified

protected void specialEdgeRefModified(Node ref,
                                      Node.NType.Field edgeField,
                                      PersistenceField field,
                                      int[] indices,
                                      Transaction t)

specialEdgeRemoved

protected void specialEdgeRemoved(Edge set,
                                  int old,
                                  Transaction t)

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

writeReplace

protected java.lang.Object writeReplace()
This method is used by object serialization.

Returns:
this node if it has no valid id, or a handle for the id
See Also:
Serializable