Java Doc for IteratorUtils.java in  » Library » Apache-common-Collections » org » apache » commons » collections » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Library » Apache common Collections » org.apache.commons.collections 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


java.lang.Object
   org.apache.commons.collections.IteratorUtils

IteratorUtils
public class IteratorUtils (Code)
Provides static utility methods and decorators for Iterator instances. The implementations are provided in the iterators subpackage.

WARNING: Due to human error certain binary incompatabilities were introduced between Commons Collections 2.1 and 3.0. The class remained source and test compatible, so if you can recompile all your classes and dependencies everything is OK. Those methods which are binary incompatible are marked as such, together with alternate solutions that are binary compatible against versions 2.1.1 and 3.1.
since:
   Commons Collections 2.1
version:
   $Revision: 405920 $ $Date: 2006-05-12 23:48:04 +0100 (Fri, 12 May 2006) $
author:
   Stephen Colebourne
author:
   Phil Steitz



Field Summary
final public static  ResettableIteratorEMPTY_ITERATOR
     An iterator over no elements.
final public static  ResettableListIteratorEMPTY_LIST_ITERATOR
     A list iterator over no elements.
final public static  MapIteratorEMPTY_MAP_ITERATOR
     A map iterator over no elements.
final public static  OrderedIteratorEMPTY_ORDERED_ITERATOR
     An ordered iterator over no elements.
final public static  OrderedMapIteratorEMPTY_ORDERED_MAP_ITERATOR
     An ordered map iterator over no elements.

Constructor Summary
public  IteratorUtils()
     IteratorUtils is not normally instantiated.

Method Summary
public static  ResettableIteratorarrayIterator(Object[] array)
     Gets an iterator over an object array.
public static  ResettableIteratorarrayIterator(Object array)
     Gets an iterator over an object or primitive array.
public static  ResettableIteratorarrayIterator(Object[] array, int start)
     Gets an iterator over the end part of an object array.
public static  ResettableIteratorarrayIterator(Object array, int start)
     Gets an iterator over the end part of an object or primitive array.
public static  ResettableIteratorarrayIterator(Object[] array, int start, int end)
     Gets an iterator over part of an object array.
public static  ResettableIteratorarrayIterator(Object array, int start, int end)
     Gets an iterator over part of an object or primitive array.
public static  ResettableListIteratorarrayListIterator(Object[] array)
     Gets a list iterator over an object array.
public static  ResettableListIteratorarrayListIterator(Object array)
     Gets a list iterator over an object or primitive array.
public static  ResettableListIteratorarrayListIterator(Object[] array, int start)
     Gets a list iterator over the end part of an object array.
public static  ResettableListIteratorarrayListIterator(Object array, int start)
     Gets a list iterator over the end part of an object or primitive array.
public static  ResettableListIteratorarrayListIterator(Object[] array, int start, int end)
     Gets a list iterator over part of an object array.
public static  ResettableListIteratorarrayListIterator(Object array, int start, int end)
     Gets a list iterator over part of an object or primitive array.
public static  EnumerationasEnumeration(Iterator iterator)
     Gets an enumeration that wraps an iterator.
public static  IteratorasIterator(Enumeration enumeration)
     Gets an iterator that provides an iterator view of the given enumeration.
public static  IteratorasIterator(Enumeration enumeration, Collection removeCollection)
     Gets an iterator that provides an iterator view of the given enumeration that will remove elements from the specified collection.
public static  IteratorchainedIterator(Iterator iterator1, Iterator iterator2)
     Gets an iterator that iterates through two Iterator s one after another.
public static  IteratorchainedIterator(Iterator[] iterators)
     Gets an iterator that iterates through an array of Iterator s one after another.
public static  IteratorchainedIterator(Collection iterators)
     Gets an iterator that iterates through a collections of Iterator s one after another.
public static  IteratorcollatedIterator(Comparator comparator, Iterator iterator1, Iterator iterator2)
     Gets an iterator that provides an ordered iteration over the elements contained in a collection of ordered Iterator s.

Given two ordered Iterator s A and B, the Iterator.next method will return the lesser of A.next() and B.next().

The comparator is optional.

public static  IteratorcollatedIterator(Comparator comparator, Iterator[] iterators)
     Gets an iterator that provides an ordered iteration over the elements contained in an array of Iterator s.

Given two ordered Iterator s A and B, the Iterator.next method will return the lesser of A.next() and B.next() and so on.

The comparator is optional.

public static  IteratorcollatedIterator(Comparator comparator, Collection iterators)
     Gets an iterator that provides an ordered iteration over the elements contained in a collection of Iterator s.

Given two ordered Iterator s A and B, the Iterator.next method will return the lesser of A.next() and B.next() and so on.

The comparator is optional.

public static  ResettableIteratoremptyIterator()
     Gets an empty iterator.
public static  ResettableListIteratoremptyListIterator()
     Gets an empty list iterator.
public static  MapIteratoremptyMapIterator()
     Gets an empty map iterator.
public static  OrderedIteratoremptyOrderedIterator()
     Gets an empty ordered iterator.
public static  OrderedMapIteratoremptyOrderedMapIterator()
     Gets an empty ordered map iterator.
public static  IteratorfilteredIterator(Iterator iterator, Predicate predicate)
     Gets an iterator that filters another iterator.
public static  ListIteratorfilteredListIterator(ListIterator listIterator, Predicate predicate)
     Gets a list iterator that filters another list iterator.
public static  IteratorgetIterator(Object obj)
     Gets a suitable Iterator for the given object.
public static  ResettableIteratorloopingIterator(Collection coll)
     Gets an iterator that loops continuously over the supplied collection.
public static  ResettableListIteratorloopingListIterator(List list)
     Gets an iterator that loops continuously over the supplied list.
public static  IteratorobjectGraphIterator(Object root, Transformer transformer)
     Gets an iterator that operates over an object graph.

This iterator can extract multiple objects from a complex tree-like object graph. The iteration starts from a single root object. It uses a Transformer to extract the iterators and elements. Its main benefit is that no intermediate List is created.

For example, consider an object graph:

 |- Branch -- Leaf
 |         \- Leaf
 |- Tree |         /- Leaf
 |       |- Branch -- Leaf
 Forest |                 \- Leaf
 |       |- Branch -- Leaf
 |       |         \- Leaf
 |- Tree |         /- Leaf
 |- Branch -- Leaf
 |- Branch -- Leaf
The following Transformer, used in this class, will extract all the Leaf objects without creating a combined intermediate list:
 public Object transform(Object input) {
 if (input instanceof Forest) {
 return ((Forest) input).treeIterator();
 }
 if (input instanceof Tree) {
 return ((Tree) input).branchIterator();
 }
 if (input instanceof Branch) {
 return ((Branch) input).leafIterator();
 }
 if (input instanceof Leaf) {
 return input;
 }
 throw new ClassCastException();
 }

Internally, iteration starts from the root object.

public static  ResettableIteratorsingletonIterator(Object object)
     Gets a singleton iterator.
public static  ListIteratorsingletonListIterator(Object object)
     Gets a singleton list iterator.
public static  Object[]toArray(Iterator iterator)
     Gets an array based on an iterator.

As the wrapped Iterator is traversed, an ArrayList of its values is created.

public static  Object[]toArray(Iterator iterator, Class arrayClass)
     Gets an array based on an iterator.

As the wrapped Iterator is traversed, an ArrayList of its values is created.

public static  ListtoList(Iterator iterator)
     Gets a list based on an iterator.

As the wrapped Iterator is traversed, an ArrayList of its values is created.

public static  ListtoList(Iterator iterator, int estimatedSize)
     Gets a list based on an iterator.

As the wrapped Iterator is traversed, an ArrayList of its values is created.

public static  ListIteratortoListIterator(Iterator iterator)
     Gets a list iterator based on a simple iterator.
public static  IteratortransformedIterator(Iterator iterator, Transformer transform)
     Gets an iterator that transforms the elements of another iterator.
public static  IteratorunmodifiableIterator(Iterator iterator)
     Gets an immutable version of an Iterator .
public static  ListIteratorunmodifiableListIterator(ListIterator listIterator)
     Gets an immutable version of a ListIterator .
public static  MapIteratorunmodifiableMapIterator(MapIterator mapIterator)
     Gets an immutable version of a MapIterator .

Field Detail
EMPTY_ITERATOR
final public static ResettableIterator EMPTY_ITERATOR(Code)
An iterator over no elements.

WARNING: This constant is binary incompatible with Commons Collections 2.1 and 2.1.1. Use EmptyIterator.INSTANCE for compatability with Commons Collections 2.1.1.




EMPTY_LIST_ITERATOR
final public static ResettableListIterator EMPTY_LIST_ITERATOR(Code)
A list iterator over no elements.

WARNING: This constant is binary incompatible with Commons Collections 2.1 and 2.1.1. Use EmptyListIterator.INSTANCE for compatability with Commons Collections 2.1.1.




EMPTY_MAP_ITERATOR
final public static MapIterator EMPTY_MAP_ITERATOR(Code)
A map iterator over no elements.



EMPTY_ORDERED_ITERATOR
final public static OrderedIterator EMPTY_ORDERED_ITERATOR(Code)
An ordered iterator over no elements.



EMPTY_ORDERED_MAP_ITERATOR
final public static OrderedMapIterator EMPTY_ORDERED_MAP_ITERATOR(Code)
An ordered map iterator over no elements.




Constructor Detail
IteratorUtils
public IteratorUtils()(Code)
IteratorUtils is not normally instantiated.




Method Detail
arrayIterator
public static ResettableIterator arrayIterator(Object[] array)(Code)
Gets an iterator over an object array.

WARNING: This method is binary incompatible with Commons Collections 2.1 and 2.1.1. Use new ArrayIterator(array) for compatability.
Parameters:
  array - the array over which to iterate an iterator over the array
throws:
  NullPointerException - if array is null




arrayIterator
public static ResettableIterator arrayIterator(Object array)(Code)
Gets an iterator over an object or primitive array.

This method will handle primitive arrays as well as object arrays. The primitives will be wrapped in the appropriate wrapper class.
Parameters:
  array - the array over which to iterate an iterator over the array
throws:
  IllegalArgumentException - if the array is not an array
throws:
  NullPointerException - if array is null




arrayIterator
public static ResettableIterator arrayIterator(Object[] array, int start)(Code)
Gets an iterator over the end part of an object array.

WARNING: This method is binary incompatible with Commons Collections 2.1 and 2.1.1. Use new ArrayIterator(array,start) for compatability.
Parameters:
  array - the array over which to iterate
Parameters:
  start - the index to start iterating at an iterator over part of the array
throws:
  IndexOutOfBoundsException - if start is less than zero or greaterthan the length of the array
throws:
  NullPointerException - if array is null




arrayIterator
public static ResettableIterator arrayIterator(Object array, int start)(Code)
Gets an iterator over the end part of an object or primitive array.

This method will handle primitive arrays as well as object arrays. The primitives will be wrapped in the appropriate wrapper class.
Parameters:
  array - the array over which to iterate
Parameters:
  start - the index to start iterating at an iterator over part of the array
throws:
  IllegalArgumentException - if the array is not an array
throws:
  IndexOutOfBoundsException - if start is less than zero or greaterthan the length of the array
throws:
  NullPointerException - if array is null




arrayIterator
public static ResettableIterator arrayIterator(Object[] array, int start, int end)(Code)
Gets an iterator over part of an object array.

WARNING: This method is binary incompatible with Commons Collections 2.1 and 2.1.1. Use new ArrayIterator(array,start,end) for compatability.
Parameters:
  array - the array over which to iterate
Parameters:
  start - the index to start iterating at
Parameters:
  end - the index to finish iterating at an iterator over part of the array
throws:
  IndexOutOfBoundsException - if array bounds are invalid
throws:
  IllegalArgumentException - if end is before start
throws:
  NullPointerException - if array is null




arrayIterator
public static ResettableIterator arrayIterator(Object array, int start, int end)(Code)
Gets an iterator over part of an object or primitive array.

This method will handle primitive arrays as well as object arrays. The primitives will be wrapped in the appropriate wrapper class.
Parameters:
  array - the array over which to iterate
Parameters:
  start - the index to start iterating at
Parameters:
  end - the index to finish iterating at an iterator over part of the array
throws:
  IllegalArgumentException - if the array is not an array
throws:
  IndexOutOfBoundsException - if array bounds are invalid
throws:
  IllegalArgumentException - if end is before start
throws:
  NullPointerException - if array is null




arrayListIterator
public static ResettableListIterator arrayListIterator(Object[] array)(Code)
Gets a list iterator over an object array.
Parameters:
  array - the array over which to iterate a list iterator over the array
throws:
  NullPointerException - if array is null



arrayListIterator
public static ResettableListIterator arrayListIterator(Object array)(Code)
Gets a list iterator over an object or primitive array.

This method will handle primitive arrays as well as object arrays. The primitives will be wrapped in the appropriate wrapper class.
Parameters:
  array - the array over which to iterate a list iterator over the array
throws:
  IllegalArgumentException - if the array is not an array
throws:
  NullPointerException - if array is null




arrayListIterator
public static ResettableListIterator arrayListIterator(Object[] array, int start)(Code)
Gets a list iterator over the end part of an object array.
Parameters:
  array - the array over which to iterate
Parameters:
  start - the index to start iterating at a list iterator over part of the array
throws:
  IndexOutOfBoundsException - if start is less than zero
throws:
  NullPointerException - if array is null



arrayListIterator
public static ResettableListIterator arrayListIterator(Object array, int start)(Code)
Gets a list iterator over the end part of an object or primitive array.

This method will handle primitive arrays as well as object arrays. The primitives will be wrapped in the appropriate wrapper class.
Parameters:
  array - the array over which to iterate
Parameters:
  start - the index to start iterating at a list iterator over part of the array
throws:
  IllegalArgumentException - if the array is not an array
throws:
  IndexOutOfBoundsException - if start is less than zero
throws:
  NullPointerException - if array is null




arrayListIterator
public static ResettableListIterator arrayListIterator(Object[] array, int start, int end)(Code)
Gets a list iterator over part of an object array.
Parameters:
  array - the array over which to iterate
Parameters:
  start - the index to start iterating at
Parameters:
  end - the index to finish iterating at a list iterator over part of the array
throws:
  IndexOutOfBoundsException - if array bounds are invalid
throws:
  IllegalArgumentException - if end is before start
throws:
  NullPointerException - if array is null



arrayListIterator
public static ResettableListIterator arrayListIterator(Object array, int start, int end)(Code)
Gets a list iterator over part of an object or primitive array.

This method will handle primitive arrays as well as object arrays. The primitives will be wrapped in the appropriate wrapper class.
Parameters:
  array - the array over which to iterate
Parameters:
  start - the index to start iterating at
Parameters:
  end - the index to finish iterating at a list iterator over part of the array
throws:
  IllegalArgumentException - if the array is not an array
throws:
  IndexOutOfBoundsException - if array bounds are invalid
throws:
  IllegalArgumentException - if end is before start
throws:
  NullPointerException - if array is null




asEnumeration
public static Enumeration asEnumeration(Iterator iterator)(Code)
Gets an enumeration that wraps an iterator.
Parameters:
  iterator - the iterator to use, not null a new enumeration
throws:
  NullPointerException - if iterator is null



asIterator
public static Iterator asIterator(Enumeration enumeration)(Code)
Gets an iterator that provides an iterator view of the given enumeration.
Parameters:
  enumeration - the enumeration to use a new iterator



asIterator
public static Iterator asIterator(Enumeration enumeration, Collection removeCollection)(Code)
Gets an iterator that provides an iterator view of the given enumeration that will remove elements from the specified collection.
Parameters:
  enumeration - the enumeration to use
Parameters:
  removeCollection - the collection to remove elements from a new iterator



chainedIterator
public static Iterator chainedIterator(Iterator iterator1, Iterator iterator2)(Code)
Gets an iterator that iterates through two Iterator s one after another.
Parameters:
  iterator1 - the first iterators to use, not null
Parameters:
  iterator2 - the first iterators to use, not null a combination iterator over the iterators
throws:
  NullPointerException - if either iterator is null



chainedIterator
public static Iterator chainedIterator(Iterator[] iterators)(Code)
Gets an iterator that iterates through an array of Iterator s one after another.
Parameters:
  iterators - the iterators to use, not null or empty or contain nulls a combination iterator over the iterators
throws:
  NullPointerException - if iterators array is null or contains a null



chainedIterator
public static Iterator chainedIterator(Collection iterators)(Code)
Gets an iterator that iterates through a collections of Iterator s one after another.
Parameters:
  iterators - the iterators to use, not null or empty or contain nulls a combination iterator over the iterators
throws:
  NullPointerException - if iterators collection is null or contains a null
throws:
  ClassCastException - if the iterators collection contains the wrong object type



collatedIterator
public static Iterator collatedIterator(Comparator comparator, Iterator iterator1, Iterator iterator2)(Code)
Gets an iterator that provides an ordered iteration over the elements contained in a collection of ordered Iterator s.

Given two ordered Iterator s A and B, the Iterator.next method will return the lesser of A.next() and B.next().

The comparator is optional. If null is specified then natural order is used.
Parameters:
  comparator - the comparator to use, may be null for natural order
Parameters:
  iterator1 - the first iterators to use, not null
Parameters:
  iterator2 - the first iterators to use, not null a combination iterator over the iterators
throws:
  NullPointerException - if either iterator is null




collatedIterator
public static Iterator collatedIterator(Comparator comparator, Iterator[] iterators)(Code)
Gets an iterator that provides an ordered iteration over the elements contained in an array of Iterator s.

Given two ordered Iterator s A and B, the Iterator.next method will return the lesser of A.next() and B.next() and so on.

The comparator is optional. If null is specified then natural order is used.
Parameters:
  comparator - the comparator to use, may be null for natural order
Parameters:
  iterators - the iterators to use, not null or empty or contain nulls a combination iterator over the iterators
throws:
  NullPointerException - if iterators array is null or contains a null




collatedIterator
public static Iterator collatedIterator(Comparator comparator, Collection iterators)(Code)
Gets an iterator that provides an ordered iteration over the elements contained in a collection of Iterator s.

Given two ordered Iterator s A and B, the Iterator.next method will return the lesser of A.next() and B.next() and so on.

The comparator is optional. If null is specified then natural order is used.
Parameters:
  comparator - the comparator to use, may be null for natural order
Parameters:
  iterators - the iterators to use, not null or empty or contain nulls a combination iterator over the iterators
throws:
  NullPointerException - if iterators collection is null or contains a null
throws:
  ClassCastException - if the iterators collection contains the wrong object type




emptyIterator
public static ResettableIterator emptyIterator()(Code)
Gets an empty iterator.

This iterator is a valid iterator object that will iterate over nothing.

WARNING: This method is binary incompatible with Commons Collections 2.1 and 2.1.1. Use EmptyIterator.INSTANCE for compatability with Commons Collections 2.1.1. an iterator over nothing




emptyListIterator
public static ResettableListIterator emptyListIterator()(Code)
Gets an empty list iterator.

This iterator is a valid list iterator object that will iterate over nothing.

WARNING: This method is binary incompatible with Commons Collections 2.1 and 2.1.1. Use EmptyListIterator.INSTANCE for compatability with Commons Collections 2.1.1. a list iterator over nothing




emptyMapIterator
public static MapIterator emptyMapIterator()(Code)
Gets an empty map iterator.

This iterator is a valid map iterator object that will iterate over nothing. a map iterator over nothing




emptyOrderedIterator
public static OrderedIterator emptyOrderedIterator()(Code)
Gets an empty ordered iterator.

This iterator is a valid iterator object that will iterate over nothing. an ordered iterator over nothing




emptyOrderedMapIterator
public static OrderedMapIterator emptyOrderedMapIterator()(Code)
Gets an empty ordered map iterator.

This iterator is a valid map iterator object that will iterate over nothing. a map iterator over nothing




filteredIterator
public static Iterator filteredIterator(Iterator iterator, Predicate predicate)(Code)
Gets an iterator that filters another iterator.

The returned iterator will only return objects that match the specified filtering predicate.
Parameters:
  iterator - the iterator to use, not null
Parameters:
  predicate - the predicate to use as a filter, not null a new filtered iterator
throws:
  NullPointerException - if either parameter is null




filteredListIterator
public static ListIterator filteredListIterator(ListIterator listIterator, Predicate predicate)(Code)
Gets a list iterator that filters another list iterator.

The returned iterator will only return objects that match the specified filtering predicate.
Parameters:
  listIterator - the list iterator to use, not null
Parameters:
  predicate - the predicate to use as a filter, not null a new filtered iterator
throws:
  NullPointerException - if either parameter is null




getIterator
public static Iterator getIterator(Object obj)(Code)
Gets a suitable Iterator for the given object.

This method can handles objects as follows

  • null - empty iterator
  • Iterator - returned directly
  • Enumeration - wrapped
  • Collection - iterator from collection returned
  • Map - values iterator returned
  • Dictionary - values (elements) enumeration returned as iterator
  • array - iterator over array returned
  • object with iterator() public method accessed by reflection
  • object - singleton iterator

Parameters:
  obj - the object to convert to an iterator a suitable iterator, never null



loopingIterator
public static ResettableIterator loopingIterator(Collection coll)(Code)
Gets an iterator that loops continuously over the supplied collection.

The iterator will only stop looping if the remove method is called enough times to empty the collection, or if the collection is empty to start with.
Parameters:
  coll - the collection to iterate over, not null a new looping iterator
throws:
  NullPointerException - if the collection is null




loopingListIterator
public static ResettableListIterator loopingListIterator(List list)(Code)
Gets an iterator that loops continuously over the supplied list.

The iterator will only stop looping if the remove method is called enough times to empty the list, or if the list is empty to start with.
Parameters:
  list - the list to iterate over, not null a new looping iterator
throws:
  NullPointerException - if the list is null
since:
   Commons Collections 3.2




objectGraphIterator
public static Iterator objectGraphIterator(Object root, Transformer transformer)(Code)
Gets an iterator that operates over an object graph.

This iterator can extract multiple objects from a complex tree-like object graph. The iteration starts from a single root object. It uses a Transformer to extract the iterators and elements. Its main benefit is that no intermediate List is created.

For example, consider an object graph:

 |- Branch -- Leaf
 |         \- Leaf
 |- Tree |         /- Leaf
 |       |- Branch -- Leaf
 Forest |                 \- Leaf
 |       |- Branch -- Leaf
 |       |         \- Leaf
 |- Tree |         /- Leaf
 |- Branch -- Leaf
 |- Branch -- Leaf
The following Transformer, used in this class, will extract all the Leaf objects without creating a combined intermediate list:
 public Object transform(Object input) {
 if (input instanceof Forest) {
 return ((Forest) input).treeIterator();
 }
 if (input instanceof Tree) {
 return ((Tree) input).branchIterator();
 }
 if (input instanceof Branch) {
 return ((Branch) input).leafIterator();
 }
 if (input instanceof Leaf) {
 return input;
 }
 throw new ClassCastException();
 }

Internally, iteration starts from the root object. When next is called, the transformer is called to examine the object. The transformer will return either an iterator or an object. If the object is an Iterator, the next element from that iterator is obtained and the process repeats. If the element is an object it is returned.

Under many circumstances, linking Iterators together in this manner is more efficient (and convenient) than using nested for loops to extract a list.
Parameters:
  root - the root object to start iterating from, null results in an empty iterator
Parameters:
  transformer - the transformer to use, see above, null uses no effect transformer a new object graph iterator
since:
   Commons Collections 3.1




singletonIterator
public static ResettableIterator singletonIterator(Object object)(Code)
Gets a singleton iterator.

This iterator is a valid iterator object that will iterate over the specified object.

WARNING: This method is binary incompatible with Commons Collections 2.1 and 2.1.1. Use new SingletonIterator(object) for compatability.
Parameters:
  object - the single object over which to iterate a singleton iterator over the object




singletonListIterator
public static ListIterator singletonListIterator(Object object)(Code)
Gets a singleton list iterator.

This iterator is a valid list iterator object that will iterate over the specified object.
Parameters:
  object - the single object over which to iterate a singleton list iterator over the object




toArray
public static Object[] toArray(Iterator iterator)(Code)
Gets an array based on an iterator.

As the wrapped Iterator is traversed, an ArrayList of its values is created. At the end, this is converted to an array.
Parameters:
  iterator - the iterator to use, not null an array of the iterator contents
throws:
  NullPointerException - if iterator parameter is null




toArray
public static Object[] toArray(Iterator iterator, Class arrayClass)(Code)
Gets an array based on an iterator.

As the wrapped Iterator is traversed, an ArrayList of its values is created. At the end, this is converted to an array.
Parameters:
  iterator - the iterator to use, not null
Parameters:
  arrayClass - the class of array to create an array of the iterator contents
throws:
  NullPointerException - if iterator parameter is null
throws:
  NullPointerException - if arrayClass is null
throws:
  ClassCastException - if the arrayClass is invalid




toList
public static List toList(Iterator iterator)(Code)
Gets a list based on an iterator.

As the wrapped Iterator is traversed, an ArrayList of its values is created. At the end, the list is returned.
Parameters:
  iterator - the iterator to use, not null a list of the iterator contents
throws:
  NullPointerException - if iterator parameter is null




toList
public static List toList(Iterator iterator, int estimatedSize)(Code)
Gets a list based on an iterator.

As the wrapped Iterator is traversed, an ArrayList of its values is created. At the end, the list is returned.
Parameters:
  iterator - the iterator to use, not null
Parameters:
  estimatedSize - the initial size of the ArrayList a list of the iterator contents
throws:
  NullPointerException - if iterator parameter is null
throws:
  IllegalArgumentException - if the size is less than 1




toListIterator
public static ListIterator toListIterator(Iterator iterator)(Code)
Gets a list iterator based on a simple iterator.

As the wrapped Iterator is traversed, a LinkedList of its values is cached, permitting all required operations of ListIterator.
Parameters:
  iterator - the iterator to use, not null a new iterator
throws:
  NullPointerException - if iterator parameter is null




transformedIterator
public static Iterator transformedIterator(Iterator iterator, Transformer transform)(Code)
Gets an iterator that transforms the elements of another iterator.

The transformation occurs during the next() method and the underlying iterator is unaffected by the transformation.
Parameters:
  iterator - the iterator to use, not null
Parameters:
  transform - the transform to use, not null a new transforming iterator
throws:
  NullPointerException - if either parameter is null




unmodifiableIterator
public static Iterator unmodifiableIterator(Iterator iterator)(Code)
Gets an immutable version of an Iterator . The returned object will always throw an UnsupportedOperationException for the Iterator.remove method.
Parameters:
  iterator - the iterator to make immutable an immutable version of the iterator



unmodifiableListIterator
public static ListIterator unmodifiableListIterator(ListIterator listIterator)(Code)
Gets an immutable version of a ListIterator . The returned object will always throw an UnsupportedOperationException for the Iterator.remove , ListIterator.add and ListIterator.set methods.
Parameters:
  listIterator - the iterator to make immutable an immutable version of the iterator



unmodifiableMapIterator
public static MapIterator unmodifiableMapIterator(MapIterator mapIterator)(Code)
Gets an immutable version of a MapIterator . The returned object will always throw an UnsupportedOperationException for the Iterator.remove , MapIterator.setValue(Object) methods.
Parameters:
  mapIterator - the iterator to make immutable an immutable version of the iterator



Methods inherited from java.lang.Object
native protected Object clone() throws CloneNotSupportedException(Code)(Java Doc)
public boolean equals(Object obj)(Code)(Java Doc)
protected void finalize() throws Throwable(Code)(Java Doc)
final native public Class getClass()(Code)(Java Doc)
native public int hashCode()(Code)(Java Doc)
final native public void notify()(Code)(Java Doc)
final native public void notifyAll()(Code)(Java Doc)
public String toString()(Code)(Java Doc)
final native public void wait(long timeout) throws InterruptedException(Code)(Java Doc)
final public void wait(long timeout, int nanos) throws InterruptedException(Code)(Java Doc)
final public void wait() throws InterruptedException(Code)(Java Doc)

www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.