com.timeindexing.util
Class Grouper

java.lang.Object
  extended byjava.util.AbstractMap
      extended byjava.util.HashMap
          extended bycom.timeindexing.util.Grouper
All Implemented Interfaces:
java.lang.Cloneable, java.util.Map, java.io.Serializable

public class Grouper
extends java.util.HashMap
implements java.util.Map

This class represents a collection that has been grouped using a criteria specified as a Grouping object. The method getGroup() of Grouping returns an object which acts as the identifier for a group. Every object in the source collection which has the same value returned by getGroup() will be in the same group.

A Grouper is a kind of Map and can therefore be used in any context that accepts a Map.

As an example, consider taking a set of Path objects. The following will build a Grouper based on the length of the paths.

    Grouper grouper = new Grouper(pathSet, new Grouping() {
	        public Object getGroup(Object obj) {
		    Path path = (Path)obj;
		    return new Integer(path.length());
		}
	    });
 

The resulting Grouper will have keys which are the lengths of the paths, and the values will be a list of paths that have that length.

See Also:
Serialized Form

Nested Class Summary
 
Nested classes inherited from class java.util.Map
java.util.Map.Entry
 
Constructor Summary
protected Grouper()
          Only used internally.
  Grouper(java.util.Collection collection, Grouping grouping)
          This constructor takes a collection and a Grouping object and creates a grouper.
  Grouper(Grouper grouper, Grouping grouping)
          This constructor takes a grouper and a Grouping object and creates a sub grouper for each existing group in the grouper argumrnt.
 
Method Summary
 void add(java.lang.Object groupSpecifier, java.lang.Object obj)
          Add an element to a group.
 boolean doGrouping(java.util.Collection collection, Grouping grouping)
          Actually do the grouping.
 java.util.List getGroup(java.lang.Object groupSpecifier)
          Get the list of elements associated with a particular group.
 Grouper groupAGrouper(Grouping grouping)
          This takes a grouper and a Grouping object and creates a sub grouper for each existing group in the grouper argumrnt.
 
Methods inherited from class java.util.HashMap
clear, clone, containsKey, containsValue, entrySet, get, isEmpty, keySet, put, putAll, remove, size, values
 
Methods inherited from class java.util.AbstractMap
equals, hashCode, toString
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Map
clear, containsKey, containsValue, entrySet, equals, get, hashCode, isEmpty, keySet, put, putAll, remove, size, values
 

Constructor Detail

Grouper

public Grouper(java.util.Collection collection,
               Grouping grouping)
This constructor takes a collection and a Grouping object and creates a grouper.


Grouper

public Grouper(Grouper grouper,
               Grouping grouping)
This constructor takes a grouper and a Grouping object and creates a sub grouper for each existing group in the grouper argumrnt.


Grouper

protected Grouper()
Only used internally.

Method Detail

doGrouping

public boolean doGrouping(java.util.Collection collection,
                          Grouping grouping)
Actually do the grouping.


groupAGrouper

public Grouper groupAGrouper(Grouping grouping)
This takes a grouper and a Grouping object and creates a sub grouper for each existing group in the grouper argumrnt.


add

public void add(java.lang.Object groupSpecifier,
                java.lang.Object obj)
Add an element to a group.

Parameters:
groupSpecifier - the identifier for the group
obj - the object to add to the group

getGroup

public java.util.List getGroup(java.lang.Object groupSpecifier)
Get the list of elements associated with a particular group.

Parameters:
groupSpecifier - the identifier for the group