classUtils.pack.util
Class ListMapIterator

java.lang.Object
  extended by classUtils.pack.util.ListMapIterator
All Implemented Interfaces:
java.util.Iterator

public class ListMapIterator
extends java.lang.Object
implements java.util.Iterator

An iterator to go thru a Map of Lists, using a specific key list for deciding how to access the sublists.

Given a java.util.Map binding each key Ki to a java.util.List Li, this Iterator allows to browse the set { L1, L2, ... , Ln} , by specifying the order in which the lists should be picked.

Such order is specified by providing a key list affineTransform construction time; if no list is given, the order of iteration is the arbitrary order in which the keys are stored in the java.util.Map, as given by the iterator provided by the iterator() method of the java.util.Map's key set.

For example, if a Map is built by

  list1.add("Elem 1.1");
  list1.add("Elem 1.2");
  list2.add("Elem 2.1");
  list3.add("Elem 3.1");
  list3.add("Elem 3.2");
  list3.add("Elem 3.3");
  map.add("1", list1);
  map.add("2", list2);
  map.add("3", list3);
 
a ListMapIterator built by
 ListMapIterator i = new ListMapIterator(map, new Arrays.asList(new String[] { "1", "2", "3")));
 
will produce the iteration Elem1.1, Elem1.2, Elem2.1, Elem3.1, Elem3.2, Elem3.3.

Version:
1.0
Author:
Cristiano Sadun

Constructor Summary
ListMapIterator(java.util.Map map)
          Create a ListMapIterator which uses default ordering (as provided by the set of keys in the map).
ListMapIterator(java.util.Map map, java.util.List keyorder)
          Create a ListMapIterator which uses the key ordering defined in the given list.
ListMapIterator(java.util.Map map, java.util.List keyorder, boolean failOnUnknownKeys, boolean requireUniqueKeys)
          Create a ListMapIterator which uses the key ordering defined in the given list.
 
Method Summary
 java.lang.Object getCurrentKey()
           
 boolean hasNext()
           
static void main(java.lang.String[] args)
           
 java.lang.Object next()
           
 void remove()
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ListMapIterator

public ListMapIterator(java.util.Map map)
Create a ListMapIterator which uses default ordering (as provided by the set of keys in the map).

Parameters:
map - the map of Lists to iterate

ListMapIterator

public ListMapIterator(java.util.Map map,
                       java.util.List keyorder)
Create a ListMapIterator which uses the key ordering defined in the given list.

Parameters:
map - the map of Lists to iterate.
keyorder - the order with which the map Lists must be iterated.

ListMapIterator

public ListMapIterator(java.util.Map map,
                       java.util.List keyorder,
                       boolean failOnUnknownKeys,
                       boolean requireUniqueKeys)
Create a ListMapIterator which uses the key ordering defined in the given list.

Parameters:
map - the map of Lists to iterate.
keyorder - the order with which the map Lists must be iterated.
failOnUnknownKeys - if true, the iterator will fail with an IllegalArgumentException if one key in the ordering list is not defined in the map. Else, it will ignore the unknown key.
requireUniqueKeys - if true, the iterator will fail with an IllegalArgumentException if the keys in the ordering list are not unique.
Method Detail

hasNext

public boolean hasNext()
Specified by:
hasNext in interface java.util.Iterator
See Also:
Iterator.hasNext()

next

public java.lang.Object next()
Specified by:
next in interface java.util.Iterator
See Also:
Iterator.next()

remove

public void remove()
Specified by:
remove in interface java.util.Iterator
See Also:
Iterator.remove()

main

public static void main(java.lang.String[] args)
                 throws java.lang.Exception
Throws:
java.lang.Exception

getCurrentKey

public java.lang.Object getCurrentKey()