|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectnet.xqhs.util.config.Config
net.xqhs.util.logging.Unit
net.xqhs.graphs.graph.SimpleGraph
net.xqhs.graphs.matchingPlatform.TrackingGraph
public class TrackingGraph
The class implements a graph that applies changes incrementally, allowing their controlled propagation. Changes are
represented as TrackingGraph.Transaction
instances, representing a single or multiple changes per transaction.
There are two uses of the class -- as 'master' and 'shadow':
createShadow()
.
A shadow graph can never be modified directly, only by taking transactions from its master's transaction queue.
Nested Class Summary | |
---|---|
static class |
TrackingGraph.Operation
Types of operations on graphs available. |
static class |
TrackingGraph.Transaction
The class contains information on one or more changes (operations) to apply to a graph. |
Nested classes/interfaces inherited from class net.xqhs.graphs.graph.SimpleGraph |
---|
SimpleGraph.NodeData |
Nested classes/interfaces inherited from class net.xqhs.util.config.Config |
---|
net.xqhs.util.config.Config.ConfigLockedException |
Field Summary | |
---|---|
protected java.util.List<TrackingGraph.Transaction> |
history
If required by keepHistory , the history of all transactions. |
protected boolean |
isShadow
true if the graph is a shadow graph, false if it is not the shadow of any other graph. |
protected boolean |
keepHistory
true if a history should be kept of all performed transactions. |
protected java.util.concurrent.atomic.AtomicInteger |
sequence
The current sequence of the graph. |
protected java.util.List<java.util.Queue<TrackingGraph.Transaction>> |
shadowQueues
The set of transaction queues for the shadow graphs of this graph. |
protected java.util.Queue<TrackingGraph.Transaction> |
transactionQueue
Only for shadow graphs, the Queue of transactions to perform. |
Fields inherited from class net.xqhs.graphs.graph.SimpleGraph |
---|
EDGE_LINE, EDGE_SEPARATOR, EDGE_TARGET, edges, nodes |
Fields inherited from class net.xqhs.util.logging.Unit |
---|
DEFAULT_LEVEL, DEFAULT_UNIT_NAME |
Constructor Summary | |
---|---|
TrackingGraph()
Creates a new graph that is not the shadow of any other graph. |
|
TrackingGraph(java.util.Queue<TrackingGraph.Transaction> transactionsLink,
int initialSequence,
Graph initialGraph)
Creates a shadow graph, based on a transactions queue and, optionally, an initial sequence and an initial graph. |
Method Summary | |
---|---|
TrackingGraph |
add(GraphComponent component)
This is the only method that actually adds a component to the graph. |
TrackingGraph |
addAll(java.util.Collection<? extends GraphComponent> components)
Adds all the nodes and edges in the argument to the current graph, all in one transaction. |
protected void |
addTransaction(TrackingGraph.Transaction t)
Handles adding of new transactions to the history and to shadow graphs queues. |
TrackingGraph |
applyTransaction(TrackingGraph.Transaction t)
Public method allowing the application of an already created transaction to the graph. |
protected void |
applyTransactionInternal(TrackingGraph.Transaction t)
Internal method for applying a transaction to the graph. |
boolean |
canIncrement()
|
TrackingGraph |
createShadow()
Creates a new shadow graph of this graph, based on the current state of the graph. |
protected java.util.Queue<TrackingGraph.Transaction> |
createShadowQueue()
Creates a new shadow queue to be used by a shadow graph. |
java.util.Map<GraphComponent,TrackingGraph.Operation> |
getNextSequenceOperations()
Retrieves the operations that will be applied at the next sequence increment. |
int |
getSequence()
|
int |
incrementSequence()
Takes one transaction from the graph's transaction queue and applies it to the current state of the graph. |
int |
incrementSequence(int targetSequence)
Takes several transactions from the graph's transaction queue and applies them to the current state of the graph, in order to reach the target sequence number. |
int |
incrementSequenceFastForward()
Brings the graph up to date with its master graph, transaction by transaction. |
protected void |
incrementSequenceInternal()
Internal method that applies one transaction to the graph. |
boolean |
isShadow()
|
TrackingGraph |
keepHistory(boolean keep,
boolean clearHistory)
Sets history keeping. |
protected TrackingGraph |
performOperation(GraphComponent component,
TrackingGraph.Operation operation,
boolean externalCall)
Internal method for performing one operation upon the current state of the graph. |
SimpleGraph |
readFrom(java.io.InputStream input)
The current implementation does not support reading nodes and edges, but all the edges and nodes from a graph can be added with addAll(Collection) . |
TrackingGraph |
remove(GraphComponent component)
This is the only method that actually removes a component from the graph. |
TrackingGraph |
removeAll(java.util.Collection<? extends GraphComponent> components)
Removes all the nodes and edges in the argument from the current graph, all in one transaction. |
java.lang.String |
toString()
The method returns a string representation of the graph as rendered by TextGraphRepresentation with
default layout parameters. |
java.lang.String |
toString(java.lang.String branchSeparator,
java.lang.String separatorIncrement,
int limit)
The method returns a string representation of the graph as rendered by TextGraphRepresentation with the
specified parameters. |
java.lang.String |
toStringBasic()
Returns a basic string representation of the graph, as rendered by SimpleGraph.toString() . |
Methods inherited from class net.xqhs.graphs.graph.SimpleGraph |
---|
addEdge, addNode, computeDistancesFromUndirected, contains, getComponents, getEdges, getInEdges, getNodes, getNodesNamed, getOutEdges, getUnitName, m, n, removeEdge, removeNode, size, toDot |
Methods inherited from class net.xqhs.util.logging.Unit |
---|
compose, dbg, doExit, getDefaultUnitName, l, le, lf, li, lock, lockedR, lr, lr, lw, setLink, setLink, setLogDisplay, setLogEnsureNew, setLoggerClass, setLoggerType, setLoggerTypeClass, setLogLevel, setLogReporter, setUnitName, setUnitName |
Methods inherited from class net.xqhs.util.config.Config |
---|
build, ensureLocked, locked, lockedEx, makeDefaults |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
protected java.util.concurrent.atomic.AtomicInteger sequence
protected boolean isShadow
true
if the graph is a shadow graph, false
if it is not the shadow of any other graph.
protected java.util.Queue<TrackingGraph.Transaction> transactionQueue
Queue
of transactions to perform. The queue is created by the master graph.
protected java.util.List<java.util.Queue<TrackingGraph.Transaction>> shadowQueues
protected boolean keepHistory
true
if a history should be kept of all performed transactions.
protected java.util.List<TrackingGraph.Transaction> history
keepHistory
, the history of all transactions.
Constructor Detail |
---|
public TrackingGraph()
public TrackingGraph(java.util.Queue<TrackingGraph.Transaction> transactionsLink, int initialSequence, Graph initialGraph)
transactionsLink
- - the queue of transactions to apply to this graph.initialSequence
- - the initial sequence number.initialGraph
- - the graph containing the nodes and edges to add initially to this graph. Although the node and edge
instances will be the same, there will exist no other relation to the specified graph.Method Detail |
---|
public boolean isShadow()
true
if the graph is the shadow of another graph.public TrackingGraph createShadow()
While overriding this method may not be useful because a TrackingGraph
is returned, extending classes may
use createShadowQueue()
to get the shadow queue and create the graph themselves.
protected java.util.Queue<TrackingGraph.Transaction> createShadowQueue()
public TrackingGraph keepHistory(boolean keep, boolean clearHistory)
Turning off history keeping without clearing the history keeps the history so it can be continued with a new call instructing to keep the history without clearing it.
keep
- - true
if history should be kept as of this call; false
if history keeping
should be halted.clearHistory
- - true
if the history should be cleared with this call.
protected TrackingGraph performOperation(GraphComponent component, TrackingGraph.Operation operation, boolean externalCall)
If externalCall
is true
, the method also creates a new transaction with the operation
and adds it to shadow queues and to the history. Otherwise, these operations are handled elsewhere.
This method should be overridden by any extending classes needing to do anything with the newly added components. If it is the case, the overriding method should also check if they should throw the exception.
component
- - the component contained in the operation.operation
- - the operation to perform.externalCall
- - true
if the method is called by an add or remove method, and the transaction should be
added.
java.lang.UnsupportedOperationException
- if the operation is applied from the exterior, to a shadow graph.protected void addTransaction(TrackingGraph.Transaction t)
t
- - the transaction to add.public TrackingGraph applyTransaction(TrackingGraph.Transaction t)
t
- - the transaction to apply.
java.lang.UnsupportedOperationException
- if the method is called for a shadow graph.protected void applyTransactionInternal(TrackingGraph.Transaction t)
t
- - the transaction to apply.public TrackingGraph add(GraphComponent component)
SimpleGraph
add
in interface Graph
add
in class SimpleGraph
component
- - the component to add. Must be an implementation of GraphComponent
that the implementing
class can recognize.
public TrackingGraph addAll(java.util.Collection<? extends GraphComponent> components)
addAll
in interface Graph
addAll
in class SimpleGraph
components
- - the GraphComponent
instances to add.
public TrackingGraph remove(GraphComponent component)
SimpleGraph
remove
in interface Graph
remove
in class SimpleGraph
component
- - the component to remove. Must be an implementation of GraphComponent
that the implementing
class can recognize.
public TrackingGraph removeAll(java.util.Collection<? extends GraphComponent> components)
removeAll
in interface Graph
removeAll
in class SimpleGraph
components
- - the GraphComponent
instances to remove.
public int getSequence()
public boolean canIncrement()
true
if there are transactions in the transaction queue that can be applied to the current
state of the graph.
java.lang.IllegalStateException
- if the method is called on a graph that is not a shadow graph.public java.util.Map<GraphComponent,TrackingGraph.Operation> getNextSequenceOperations()
null
if the shadow is synchronized with its master.protected void incrementSequenceInternal()
public int incrementSequence()
FIXME: if there are no elements in the queue, the sequence is not incremented. should check for dsynchronization; is it possible?
java.lang.IllegalStateException
- if the method is called on a graph that is not a shadow graph.public int incrementSequence(int targetSequence)
targetSequence
- - the sequence number to reach before stopping.
targetSequence
.
java.lang.IllegalStateException
- if the method is called on a graph that is not a shadow graph.public int incrementSequenceFastForward()
java.lang.IllegalStateException
- if the method is called on a graph that is not a shadow graph.public SimpleGraph readFrom(java.io.InputStream input)
addAll(Collection)
.
readFrom
in class SimpleGraph
input
- - a stream to read from
SimpleGraph
instancepublic java.lang.String toString()
TextGraphRepresentation
with
default layout parameters.
A customized representation can be obtained by calling toString(String, String, int)
.
The basic string representation of the graph can be obtained by calling toStringBasic()
.
toString
in class SimpleGraph
public java.lang.String toString(java.lang.String branchSeparator, java.lang.String separatorIncrement, int limit)
TextGraphRepresentation
with the
specified parameters.
branchSeparator
- - see TextGraphRepresentation.setLayout(String, String, int)
.separatorIncrement
- - see TextGraphRepresentation.setLayout(String, String, int)
.limit
- - see TextGraphRepresentation.setLayout(String, String, int)
.
public java.lang.String toStringBasic()
SimpleGraph.toString()
.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |