org.jutil.java.collections
Class MapVisitor

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

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

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

MapVisitor is very much like Visitor. The main difference is that the visit now has 2 arguments: a key and a value.

Version:
$Revision: 1.8 $
Author:
Jan Dockx, Jamal Said, Pieter Bekaert, Marko van Dooren

Field Summary
static java.lang.String CVS_REVISION
           
 
Constructor Summary
MapVisitor()
           
 
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()));

// code>public void visit(Object) is called for all elements of
post (* for all k, for all v: (map.containsKey(k) and (map.get(k) = v) ==> visit(k, v) *)
// The changes are applied to the given set and it is returned afterwards.
post \result == map;

signals (ConcurrentModificationException) (* The collection was modified while performing the visit.
abstract  void visit(java.lang.Object key, java.lang.Object value)
          public behavior

pre isValidPair(key, 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
 

Field Detail

CVS_REVISION

public static final java.lang.String CVS_REVISION
Constructor Detail

MapVisitor

public MapVisitor()
Method Detail

visit

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

pre isValidPair(key, value);
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.

applyTo

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

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

// code>public void visit(Object) is called for all elements of
post (* for all k, for all v: (map.containsKey(k) and (map.get(k) = v) ==> visit(k, v) *)
// The changes are applied to the given set and it is returned afterwards.
post \result == map;

signals (ConcurrentModificationException) (* The collection was modified while performing the visit. *);

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.