com.claritysys.util
Class MapComparator

java.lang.Object
  extended by com.claritysys.util.MapComparator

public final class MapComparator
extends java.lang.Object

Compare two maps, returning a third map describing the state of all elements.

Used to determine the exact differences between two sets of items. For example, map a contains an older list of String employee names, and map b contains the newer list. The result of compare (a, b) will be a map of MapComparator.Entry items with the union (a + b), where each item is marked as ADDED, CHANGED, UNCHANGED, or REMOVED with respect to a.

The prune(Map) method will remove unchanged items, so only differences are left.

This could be used to generate a visual diff of source files, for example, if each item was keyed by line number.

Version:
$Revision: 2348 $

Nested Class Summary
static class MapComparator.Entry
          Adds a 'change flag' to the key-value relationship of Map.Entry.
 
Constructor Summary
MapComparator()
           
 
Method Summary
static java.util.Map compare(java.util.Map mapA, java.util.Map mapB)
          Return a Map of MapComparator.Entry objects based on a comparison of the elements in the two given maps.
static void dump(java.util.Map map)
          Dump the given map of Map.Entry objects to System.out.
static void prune(java.util.Map map)
          Remove any MapComparator.Entry.UNCHANGED entries from the given map.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MapComparator

public MapComparator()
Method Detail

prune

public static void prune(java.util.Map map)
Remove any MapComparator.Entry.UNCHANGED entries from the given map.

The passed Map is modified directly, no copy is made.

Parameters:
map - The map to prune.

compare

public static java.util.Map compare(java.util.Map mapA,
                                    java.util.Map mapB)
Return a Map of MapComparator.Entry objects based on a comparison of the elements in the two given maps.

Parameters:
mapA - The 'original' map of elements to compare.
mapB - The 'newer' map to compare mapA to.
Returns:
a Map of MapComparator.Entry objects, one for each element in both mapA and mapB (the union).

dump

public static void dump(java.util.Map map)
Dump the given map of Map.Entry objects to System.out.

Parameters:
map - The map to dump.


Copyright ? 2002 Clarity Systems Group, LLC. All Rights Reserved.