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.

Version:
$Revision: 1.8 $
Author:
Marko van Dooren

Field Summary
static java.lang.String CVS_REVISION
           
 
Constructor Summary
RobustMapVisitor()
           
 
Method Summary
 java.util.Map applyTo(java.util.Map map)
          public behavior

pre (\forall Map.Entry entry; map.entrySet().contains(entry);
isValidPair(entry.getKey(), entry.getValue()));

// The changes are applied to the given set and it is returned afterwards.
post \result == map;
post (* public void visit(Object) is called for all elements of
.
| 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.
abstract  void unvisit(java.lang.Object key, java.lang.Object value, java.lang.Object unvisitData)
          public behavior

pre isValidPair(key, value);
// unvisitData is the data returned by the visit method.
pre unvisitData == visit(key,value);

post (* the changes on , done by visit are undone *);
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)
          public behavior

pre isValidPair(key, value);

post (* returns Data which enables to undo what visit has done
in unvisit.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

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
public behavior

pre isValidPair(key, value);

post (* returns Data which enables to undo what visit has done
in unvisit. ()

signals (Exception) (* Something went wrong while visiting the elements. *);
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.

unvisit

public abstract void unvisit(java.lang.Object key,
                             java.lang.Object value,
                             java.lang.Object unvisitData)
public behavior

pre isValidPair(key, value);
// unvisitData is the data returned by the visit method.
pre unvisitData == visit(key,value);

post (* the changes on , done by visit are undone *);
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.

applyTo

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

pre (\forall Map.Entry entry; map.entrySet().contains(entry);
isValidPair(entry.getKey(), entry.getValue()));

// The changes are applied to the given set and it is returned afterwards.
post \result == map;
post (* public void visit(Object) is called for all elements of
.
| 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. *);

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.