net.xqhs.graphs.matchingPlatform
Class TrackingGraph.Transaction

java.lang.Object
  extended by net.xqhs.graphs.matchingPlatform.TrackingGraph.Transaction
All Implemented Interfaces:
java.util.Map<GraphComponent,TrackingGraph.Operation>
Enclosing class:
TrackingGraph

public static class TrackingGraph.Transaction
extends java.lang.Object
implements java.util.Map<GraphComponent,TrackingGraph.Operation>

The class contains information on one or more changes (operations) to apply to a graph. Each change is a pair of a GraphComponent instance and one of TrackingGraph.Operation. The changes are not ordered in any guaranteed manner.

The implementation is optimized so that single-operation transactions are represented in a more simple manner. The conversion between single- and multi-operation transactions is done transparently.

The class implements most operations of Map, but some are available only if the transaction is multi-operation.

Author:
Andrei Olaru

Nested Class Summary
 
Nested classes/interfaces inherited from interface java.util.Map
java.util.Map.Entry<K,V>
 
Field Summary
(package private)  boolean empty
          true if the transaction is empty (no operation contained).
(package private)  java.util.Map<GraphComponent,TrackingGraph.Operation> multipleOperations
          For multi-operation transactions, the map of operations.
(package private)  boolean singleOperation
          true if and inly if it is single-operation (is not true for empty transactions).
(package private)  GraphComponent singleOperationComponent
          For single-operation transactions, the component contained in the operation.
(package private)  TrackingGraph.Operation singleOperationOperation
          For single-operation transactions, the operation to perform.
 
Constructor Summary
TrackingGraph.Transaction()
          Creates an empty transaction.
TrackingGraph.Transaction(GraphComponent component, TrackingGraph.Operation operation)
          Creates a single-operation transaction.
 
Method Summary
 void clear()
          Resets the transaction to an empty transaction.
protected  void compact()
          Compacts a multi-operation transaction in case it is in fact empty or single-operation.
 boolean containsKey(java.lang.Object key)
           
 boolean containsValue(java.lang.Object value)
          The method is unsupported.
 java.util.Set<java.util.Map.Entry<GraphComponent,TrackingGraph.Operation>> entrySet()
          Unsupported operation for empty or single-operation transactions.
 TrackingGraph.Operation get(java.lang.Object component)
           
 GraphComponent getComponent()
          For single-operation transactions only, retrieves the component contained in the operation.
 TrackingGraph.Operation getOperation()
          For single-operation transactions only, retrieves the operation to perform.
 boolean isEmpty()
           
 boolean isSingleOperation()
           
 java.util.Set<GraphComponent> keySet()
          Unsupported operation for empty or single-operation transactions.
 TrackingGraph.Operation put(GraphComponent component, TrackingGraph.Operation operation)
          Adds a new operation to the transaction.
 void putAll(java.util.Map<? extends GraphComponent,? extends TrackingGraph.Operation> operations)
           
 TrackingGraph.Transaction putR(GraphComponent component, TrackingGraph.Operation operation)
          The method is identical to #put(GraphComponent, Operation), with the exception that it returns the instance itself.
 TrackingGraph.Operation remove(java.lang.Object component)
           
 int size()
           
protected  void toMultipleOperations()
          Converts an empty or single-operation transaction into a multi-operation transaction.
 java.util.Map<GraphComponent,TrackingGraph.Operation> toOperationMap()
          Retrieves the operations in this transaction as a (copy) Map of GraphComponentTrackingGraph.Operation.
 java.lang.String toString()
           
 java.util.Collection<TrackingGraph.Operation> values()
          The method is unsupported.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Map
equals, hashCode
 

Field Detail

singleOperation

boolean singleOperation
true if and inly if it is single-operation (is not true for empty transactions).


empty

boolean empty
true if the transaction is empty (no operation contained).


singleOperationComponent

GraphComponent singleOperationComponent
For single-operation transactions, the component contained in the operation.


singleOperationOperation

TrackingGraph.Operation singleOperationOperation
For single-operation transactions, the operation to perform.


multipleOperations

java.util.Map<GraphComponent,TrackingGraph.Operation> multipleOperations
For multi-operation transactions, the map of operations.

Constructor Detail

TrackingGraph.Transaction

public TrackingGraph.Transaction(GraphComponent component,
                                 TrackingGraph.Operation operation)
Creates a single-operation transaction.

Parameters:
component - - the component contained in the operation.
operation - - the operation to perform.

TrackingGraph.Transaction

public TrackingGraph.Transaction()
Creates an empty transaction.

Method Detail

getComponent

public GraphComponent getComponent()
For single-operation transactions only, retrieves the component contained in the operation.

Returns:
the component.
Throws:
java.lang.UnsupportedOperationException - if the method is called for an empty or multi-operation transaction.

getOperation

public TrackingGraph.Operation getOperation()
For single-operation transactions only, retrieves the operation to perform.

Returns:
the operation.
Throws:
java.lang.UnsupportedOperationException - if the method is called for an empty or multi-operation transaction.

isSingleOperation

public boolean isSingleOperation()
Returns:
true if the transaction contains exactly one operation.

compact

protected void compact()
Compacts a multi-operation transaction in case it is in fact empty or single-operation.


toMultipleOperations

protected void toMultipleOperations()
Converts an empty or single-operation transaction into a multi-operation transaction.


put

public TrackingGraph.Operation put(GraphComponent component,
                                   TrackingGraph.Operation operation)
Adds a new operation to the transaction.

If the transaction was empty, it is now single-operation. If it was single-operation, it is now multi-operation.

Specified by:
put in interface java.util.Map<GraphComponent,TrackingGraph.Operation>

putR

public TrackingGraph.Transaction putR(GraphComponent component,
                                      TrackingGraph.Operation operation)
The method is identical to #put(GraphComponent, Operation), with the exception that it returns the instance itself.

Parameters:
component - - the component contained in the operation.
operation - - the operation to perform.
Returns:
the instance itself.

putAll

public void putAll(java.util.Map<? extends GraphComponent,? extends TrackingGraph.Operation> operations)
Specified by:
putAll in interface java.util.Map<GraphComponent,TrackingGraph.Operation>

get

public TrackingGraph.Operation get(java.lang.Object component)
Specified by:
get in interface java.util.Map<GraphComponent,TrackingGraph.Operation>

containsKey

public boolean containsKey(java.lang.Object key)
Specified by:
containsKey in interface java.util.Map<GraphComponent,TrackingGraph.Operation>

containsValue

public boolean containsValue(java.lang.Object value)
The method is unsupported.

Specified by:
containsValue in interface java.util.Map<GraphComponent,TrackingGraph.Operation>

values

public java.util.Collection<TrackingGraph.Operation> values()
The method is unsupported.

Specified by:
values in interface java.util.Map<GraphComponent,TrackingGraph.Operation>

clear

public void clear()
Resets the transaction to an empty transaction.

Specified by:
clear in interface java.util.Map<GraphComponent,TrackingGraph.Operation>

isEmpty

public boolean isEmpty()
Specified by:
isEmpty in interface java.util.Map<GraphComponent,TrackingGraph.Operation>

size

public int size()
Specified by:
size in interface java.util.Map<GraphComponent,TrackingGraph.Operation>

entrySet

public java.util.Set<java.util.Map.Entry<GraphComponent,TrackingGraph.Operation>> entrySet()
Unsupported operation for empty or single-operation transactions.

Specified by:
entrySet in interface java.util.Map<GraphComponent,TrackingGraph.Operation>

keySet

public java.util.Set<GraphComponent> keySet()
Unsupported operation for empty or single-operation transactions.

Specified by:
keySet in interface java.util.Map<GraphComponent,TrackingGraph.Operation>

remove

public TrackingGraph.Operation remove(java.lang.Object component)
Specified by:
remove in interface java.util.Map<GraphComponent,TrackingGraph.Operation>

toString

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

toOperationMap

public java.util.Map<GraphComponent,TrackingGraph.Operation> toOperationMap()
Retrieves the operations in this transaction as a (copy) Map of GraphComponentTrackingGraph.Operation.

Returns:
the operations.