org.jutil.java.collections
Class RobustMapVisitor

java.lang.Object
  |
  +--org.jutil.java.collections.RobustMapVisitor
All Implemented Interfaces:
MapOperator

public abstract class RobustMapVisitor
extends java.lang.Object
implements MapOperator

A robust visitor of maps. The code in visit is performed for each element pair in the visited map.

In addition to the functionality of MapVisitor, RobustMapVisitor allows the visit method to throw an exception. It also has support for undoing the changes done before the exception occurred.

See RobustVisitor for more information.


Field Summary
static java.lang.String CVS_REVISION
           
 
Constructor Summary
RobustMapVisitor()
           
 
Method Summary
 java.util.Map applyTo(java.util.Map map)
          Perform the visitation defined in public void visit(Object) on .
abstract  void unvisit(java.lang.Object key, java.lang.Object value, java.lang.Object unvisitData)
          This method will be called when the visit method has raised an exception for some key,value pair which was visited after ,.
abstract  java.lang.Object visit(java.lang.Object key, java.lang.Object value)
          The code to be applied to all element pairs of a map.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.jutil.java.collections.MapOperator
isValidPair
 

Field Detail

CVS_REVISION

public static final java.lang.String CVS_REVISION
Constructor Detail

RobustMapVisitor

public RobustMapVisitor()
Method Detail

visit

public abstract java.lang.Object visit(java.lang.Object key,
                                       java.lang.Object value)
                                throws java.lang.Exception
The code to be applied to all element pairs of a map.

Parameters:
key - The key of the element pair the code should be applied to.
element - The value of the element pair the code should be applied to.

Specifications:
public behavior
requires isValidPair(key,value);
ensures (* returns Data which enables to undo what visit has done in unvisit. () signals (Exception) (* Something went wrong while visiting the elements. *);

unvisit

public abstract void unvisit(java.lang.Object key,
                             java.lang.Object value,
                             java.lang.Object unvisitData)
This method will be called when the visit method has raised an exception for some key,value pair which was visited after ,. The implementation should undo whatever visit did on the , pair. For that, can be used.

Specifications:
public behavior
requires isValidPair(key,value);
requires unvisitData == visit(key,value);
ensures (* the changes on <key>,<value> done by visit are undone *);

applyTo

public final java.util.Map applyTo(java.util.Map map)
                            throws java.lang.Exception,
                                   java.util.ConcurrentModificationException

Perform the visitation defined in public void visit(Object) on . The contents of is not changed.

The collection is returned, so that further operations can be applied to it inline.

Parameters:
map - The collection to perform this visitation on. This can be null.

Specifications:
public behavior
requires ( \forall Map.Entry entry; map.entrySet().contains(entry); isValidPair(entry.getKey(),entry.getValue()));
ensures \result == map;
ensures (* <code>public void visit(Object)</code> is called for all elements of <map>. | for all k, for all v: (map.containsKey(k) and (map.get(k) = v)) ==> visit(k, v) *);
signals (ConcurrentModificationException) (* The collection was modified while visiting the map. *);
signals (Exception) (* Something has gone wrong while visiting the map. *);