|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--gishur.core.CursorAdapter | +--gishur.graph.core.GraphCursor | +--gishur.graph.core.TraverseAlgorithmCursor
This class should be used to implement Graph
-Traversals. Although it
extends the GraphCursor
class, backward navigation is realized just
as simple 'n-1' forward steps from the beginning. If one likes to traverse
a graph and then navigate on the traversal, one should use the
TraverseCursor
in conjunction with this class.
The implementation of new algorithms should be easy; just overwrite the
selectFirst()
and selectNext(...)
methods
properly. In order to make backward navigation possible, one should also
overwrite the rollback(...)
-methods. A simple execution
of the algorithm can be performed via execute()
, otherwise it can be
used like a normal GraphCursor
.
A TraverseAlgorithmCursor
makes property entries on the
GraphElements
under a special prefix. Via setting 'local'
properties one can make more temporary entries on the traversed elements.
These entries should also be removed by backward stepping
(see rollback(...)
). The local entries with the local keys
"next"
and "prev"
are written and removed
automatically. They can be read via the various
getProperty(...)
-methods.
Constructor Summary | |
protected |
TraverseAlgorithmCursor(Graph g)
Constructor. |
Method Summary | |
void |
addFilter(Filter f)
Adds a Filter to the Filter -pipeline so that the
move of the Cursor will furthermore happen on only these elments
which are not filtered out by f and the other
registered Filters . |
void |
bottom()
Sets the Cursor to the last element. |
java.lang.String |
cursorID()
Returns the cursor id. |
protected GraphCursor |
edges(Node n)
Returns a GraphCursor , that enumerates the connected
Edges of the specified Node . |
java.lang.Object |
element()
Returns the element to which this Cursor points at the moment. |
void |
execute()
Executes the TraverseAlgorithmCursor , that means, the
cursor traverses the whole Graph to the end. |
boolean |
getBoolProperty(GraphElement e,
java.lang.String key)
Method to get a property value which is not an object, but a boolean . |
double |
getDoubleProperty(GraphElement e,
java.lang.String key)
Method to get a property value which is not an object, but a double . |
Edge |
getEdgeProperty(GraphElement e,
java.lang.String key)
Returns a property value like getProperty(gishur.graph.core.GraphElement, java.lang.String) which is casted
to Edge , if this is possible, otherwise null . |
float |
getFloatProperty(GraphElement e,
java.lang.String key)
Method to get a property value which is not an object, but a float . |
GraphElement |
getGraphElementProperty(GraphElement e,
java.lang.String key)
Returns a property value like getProperty(gishur.graph.core.GraphElement, java.lang.String) which is casted
to GraphElement , if this is possible, otherwise null . |
int |
getIntProperty(GraphElement e,
java.lang.String key)
Method to get a property value which is not an object, but an int . |
long |
getLongProperty(GraphElement e,
java.lang.String key)
Method to get a property value which is not an object, but a long . |
Node |
getNodeProperty(GraphElement e,
java.lang.String key)
Returns a property value like getProperty(gishur.graph.core.GraphElement, java.lang.String) which is casted
to Node , if this is possible, otherwise null . |
java.lang.Object |
getProperty(GraphElement e,
java.lang.String key)
Returns a property value stored locally at the given GraphElement
specific to this TraverseAlgorithmCursor , specified by
key . |
short |
getShortProperty(GraphElement e,
java.lang.String key)
Method to get a property value which is not an object, but a short . |
Graph |
graph()
Returns the Graph , on which the Cursor works. |
GraphElement |
graphElement()
Returns the element under the actual position as an GraphElement ,
if this is possible (i.e. the position is valid and points to an
GraphElement . |
protected boolean |
hasProperty(GraphElement e,
java.lang.String key)
Returns true , if a property with the given key specific to
this TraverseAlgorithmCursor exists. |
protected GraphCursor |
inEdges(Node n)
Returns a GraphCursor , that enumerates the incoming
Edges of the specified Node . |
protected void |
initStructures()
Initializes data structures. |
protected GraphCursor |
inNodes(GraphElement e)
Returns a GraphCursor , that enumerates the source Nodes
of the incoming Edges of the specified Node or
Edge . |
void |
invalidate()
Sets the Cursor to an invalid position. |
int |
length()
Returns the number of elements in the underlying structure of this Cursor . |
protected GraphCursor |
nodes(GraphElement e)
Returns a GraphCursor , that enumerates the (other) Nodes
of the connected Edges of the specified Node or
Edge . |
protected GraphCursor |
outEdges(Node n)
Returns a GraphCursor , that enumerates the outgoing
Edges of the specified Node . |
protected GraphCursor |
outNodes(GraphElement e)
Returns a GraphCursor , that enumerates the target Nodes
of the outgoing Edges of the specified Node or
Edge . |
void |
relative(int step)
Moves the Cursor step positions within the underlying
structure. |
void |
removeFilter(Filter f)
Removes f from the Filter pipeline of this
GraphCursor . |
protected java.lang.Object |
removeProperty(GraphElement e,
java.lang.String key)
Removes the property defined by key specific to
this TraverseAlgorithmCursor and returns its value.
|
protected void |
rollback(GraphElement e)
Makes the last traverse step (see selectNext(gishur.graph.core.GraphElement) ) undone.
|
protected abstract GraphElement |
selectFirst()
Selects the first GraphElement of the Graph according to the
traversal strategy. |
protected abstract GraphElement |
selectNext(GraphElement e)
Selects the next GraphElement of the Graph after the given
according to the traversal strategy.
|
void |
set(GraphElement e)
Sets the TraverseAlgorithmCursor to a new (start) element.
|
protected void |
setProperty(GraphElement e,
java.lang.String key,
boolean value)
Sets a boolean -value as value . |
protected void |
setProperty(GraphElement e,
java.lang.String key,
double value)
Sets a double -value as value . |
protected void |
setProperty(GraphElement e,
java.lang.String key,
float value)
Sets a float -value as value . |
protected void |
setProperty(GraphElement e,
java.lang.String key,
int value)
Sets an int -value as value . |
protected void |
setProperty(GraphElement e,
java.lang.String key,
long value)
Sets a long -value as value . |
protected void |
setProperty(GraphElement e,
java.lang.String key,
java.lang.Object value)
Sets a property of the given GraphElement specific to
this TraverseAlgorithmCursor , specified by the
String key to the given value . |
protected void |
setProperty(GraphElement e,
java.lang.String key,
short value)
Sets a short -value as value . |
java.lang.String |
toString()
Overrides java.lang.Object.toString() . |
boolean |
valid()
Checks if the Cursor's actual position is valid. |
Methods inherited from class gishur.graph.core.GraphCursor |
edge, filter, isEdge, isNode, node, validElement |
Methods inherited from class gishur.core.CursorAdapter |
getBookmark, hasMoreElements, next, next, nextElement, prev, prev, set, set, top |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
protected TraverseAlgorithmCursor(Graph g)
TraverseAlgorithmCursor
should be invalid.
This cannot be done securly by this class. Be shure
to call invalidate()
at the end of subclass-constructors!Method Detail |
public java.lang.String toString()
java.lang.Object.toString()
.toString
in class java.lang.Object
Object.toString()
public java.lang.String cursorID()
protected void initStructures()
protected abstract GraphElement selectFirst()
GraphElement
of the Graph
according to the
traversal strategy. Filtering will be done after this method.
This method must be overwritten properly.GraphElement
according to the travesal.protected abstract GraphElement selectNext(GraphElement e)
GraphElement
of the Graph
after the given
according to the traversal strategy.
The given GraphElement
specifies the step/position to step from.
(This has nothing to do with the Cursor
position!)
This method must be overwritten properly.e
- the actual GraphElement
GraphElement
according to the travesal.protected void rollback(GraphElement e)
selectNext(gishur.graph.core.GraphElement)
) undone.
The given GraphElement
specifies the step/position to
make undone. (This has nothing to do with the Cursor
position!)
This method should be overwritten properly. Otherwise a
GraphException
will be thrown, if a function needs to call this
method; the cursor can only be used as enumeration.e
- the actual GraphElement
public void set(GraphElement e)
TraverseAlgorithmCursor
to a new (start) element.
This method should be overwritten properly. Otherwise a
GraphException
will be thrown.set
in class GraphCursor
e
- the new GraphElement
to set the cursor topublic Graph graph()
Graph
, on which the Cursor
works.graph
in class GraphCursor
Graph
, on which the Cursor
works.public java.lang.Object element()
Cursor
points at the moment.Cursor
public GraphElement graphElement()
GraphElement
,
if this is possible (i.e. the position is valid and points to an
GraphElement
.graphElement
in class GraphCursor
GraphElement
public void relative(int step)
Cursor
step
positions within the underlying
structure.step
- the number of elements to movepublic boolean valid()
Cursor's
actual position is valid.true
, if the Cursor
points to a
valid position, and false
otherwisepublic void invalidate()
Cursor
to an invalid position.public int length()
Cursor
.public void bottom()
Cursor
to the last element.bottom
in class CursorAdapter
public void execute()
TraverseAlgorithmCursor
, that means, the
cursor traverses the whole Graph
to the end.public void addFilter(Filter f)
Filter
to the Filter
-pipeline so that the
move of the Cursor
will furthermore happen on only these elments
which are not filtered out by f
and the other
registered Filters
. If f==null
nothing
happens and the method returns.addFilter
in class GraphCursor
f
- the new Filter
to add to the pipelinepublic void removeFilter(Filter f)
f
from the Filter
pipeline of this
GraphCursor
. If f==null
or f
is
not part of the Filter
pipe, the method returns
effectiveless.removeFilter
in class GraphCursor
f
- the Filter
to removeprotected final GraphCursor outEdges(Node n)
GraphCursor
, that enumerates the outgoing
Edges
of the specified Node
.n
- the given Node
GraphCursor
, that enumerates the outgoing
Edges
protected final GraphCursor inEdges(Node n)
GraphCursor
, that enumerates the incoming
Edges
of the specified Node
.n
- the given Node
GraphCursor
, that enumerates the incoming
Edges
protected final GraphCursor edges(Node n)
GraphCursor
, that enumerates the connected
Edges
of the specified Node
.n
- the given Node
GraphCursor
, that enumerates the connected
Edges
protected final GraphCursor outNodes(GraphElement e)
GraphCursor
, that enumerates the target Nodes
of the outgoing Edges
of the specified Node
or
Edge
.e
- the given Node
or Edge
GraphCursor
protected final GraphCursor inNodes(GraphElement e)
GraphCursor
, that enumerates the source Nodes
of the incoming Edges
of the specified Node
or
Edge
.e
- the given Node
or Edge
GraphCursor
protected final GraphCursor nodes(GraphElement e)
GraphCursor
, that enumerates the (other) Nodes
of the connected Edges
of the specified Node
or
Edge
.e
- the given Node
or Edge
GraphCursor
protected void setProperty(GraphElement e, java.lang.String key, java.lang.Object value)
GraphElement
specific to
this
TraverseAlgorithmCursor
, specified by the
String key
to the given value
.e
- the GraphElement
, where the property should be storedkey
- the key-string specifying the property to changevalue
- the value to set as propertyjava.lang.NullPointerExecption
- if key
or value
is null
protected boolean hasProperty(GraphElement e, java.lang.String key)
true
, if a property with the given key specific to
this
TraverseAlgorithmCursor
exists.e
- the GraphElement
, where the property should be storedkey
- the key valuetrue
if the specified property is containedpublic java.lang.Object getProperty(GraphElement e, java.lang.String key)
GraphElement
specific to this
TraverseAlgorithmCursor
, specified by
key
.e
- the GraphElement
, where the property should be storedkey
- the key-string specifying the property to returnkey
or null
, if
no such key has been foundprotected java.lang.Object removeProperty(GraphElement e, java.lang.String key)
key
specific to
this
TraverseAlgorithmCursor
and returns its value.
If the given key
does not specify a valid property,
null
will be returned.e
- the GraphElement
, where the property should be storedkey
- the key specifying the property to removeprotected void setProperty(GraphElement e, java.lang.String key, int value)
int
-value as value
.protected void setProperty(GraphElement e, java.lang.String key, short value)
short
-value as value
.protected void setProperty(GraphElement e, java.lang.String key, long value)
long
-value as value
.protected void setProperty(GraphElement e, java.lang.String key, float value)
float
-value as value
.protected void setProperty(GraphElement e, java.lang.String key, double value)
double
-value as value
.protected void setProperty(GraphElement e, java.lang.String key, boolean value)
boolean
-value as value
.public int getIntProperty(GraphElement e, java.lang.String key)
int
.e
- the GraphElement
, where the property should be storedkey
- the key-string specifying the property to returnkey
public short getShortProperty(GraphElement e, java.lang.String key)
short
.e
- the GraphElement
, where the property should be storedkey
- the key-string specifying the property to returnkey
public long getLongProperty(GraphElement e, java.lang.String key)
long
.e
- the GraphElement
, where the property should be storedkey
- the key-string specifying the property to returnkey
public float getFloatProperty(GraphElement e, java.lang.String key)
float
.e
- the GraphElement
, where the property should be storedkey
- the key-string specifying the property to returnkey
public double getDoubleProperty(GraphElement e, java.lang.String key)
double
.e
- the GraphElement
, where the property should be storedkey
- the key-string specifying the property to returnkey
public boolean getBoolProperty(GraphElement e, java.lang.String key)
boolean
.e
- the GraphElement
, where the property should be storedkey
- the key-string specifying the property to returnkey
public GraphElement getGraphElementProperty(GraphElement e, java.lang.String key)
getProperty(gishur.graph.core.GraphElement, java.lang.String)
which is casted
to GraphElement
, if this is possible, otherwise null
.e
- the GraphElement
, where the property should be storedkey
- the key-string specifying the property to returnGraphElement
stored with key key
public Node getNodeProperty(GraphElement e, java.lang.String key)
getProperty(gishur.graph.core.GraphElement, java.lang.String)
which is casted
to Node
, if this is possible, otherwise null
.e
- the GraphElement
, where the property should be storedkey
- the key-string specifying the property to returnNode
stored with key key
public Edge getEdgeProperty(GraphElement e, java.lang.String key)
getProperty(gishur.graph.core.GraphElement, java.lang.String)
which is casted
to Edge
, if this is possible, otherwise null
.e
- the GraphElement
, where the property should be storedkey
- the key-string specifying the property to returnEdge
stored with key key
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |