public final class MapComparator
extends java.lang.Object
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.
Modifier and Type | Class and Description |
---|---|
static class |
MapComparator.Entry
Adds a 'change flag' to the key-value relationship of Map.Entry.
|
Constructor and Description |
---|
MapComparator() |
Modifier and Type | Method and Description |
---|---|
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.
|
public static void prune(java.util.Map map)
The passed Map is modified directly, no copy is made.
map
- The map to prune.public static java.util.Map compare(java.util.Map mapA, java.util.Map mapB)
mapA
- The 'original' map of elements to compare.mapB
- The 'newer' map to compare mapA to.public static void dump(java.util.Map map)
map
- The map to dump.Copyright ? 2002 Clarity Systems Group, LLC. All Rights Reserved.