Java Doc for ListUtils.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.ListUtils

ListUtils
public class ListUtils (Code)
Provides utility methods and decorators for List instances.
since:
   Commons Collections 1.0
version:
   $Revision: 348013 $ $Date: 2005-11-21 23:24:45 +0000 (Mon, 21 Nov 2005) $
author:
   Federico Barbieri
author:
   Peter Donald
author:
   Paul Jack
author:
   Stephen Colebourne
author:
   Neil O'Toole
author:
   Matthew Hawthorne


Field Summary
final public static  ListEMPTY_LIST
     An empty unmodifiable list.

Constructor Summary
public  ListUtils()
     ListUtils should not normally be instantiated.

Method Summary
public static  ListfixedSizeList(List list)
     Returns a fixed-sized list backed by the given list.
public static  inthashCodeForList(Collection list)
     Generates a hash code using the algorithm specified in java.util.List.hashCode .

This method is useful for implementing List when you cannot extend AbstractList.

public static  Listintersection(List list1, List list2)
     Returns a new list containing all elements that are contained in both given lists.
public static  booleanisEqualList(Collection list1, Collection list2)
     Tests two lists for value-equality as per the equality contract in java.util.List.equals(java.lang.Object) .

This method is useful for implementing List when you cannot extend AbstractList.

public static  ListlazyList(List list, Factory factory)
     Returns a "lazy" list whose elements will be created on demand.

When the index passed to the returned list's List.get(int) get method is greater than the list's size, then the factory will be used to create a new object and that object will be inserted at that index.

For instance:

 Factory factory = new Factory() {
 public Object create() {
 return new Date();
 }
 }
 List lazy = ListUtils.lazyList(new ArrayList(), factory);
 Object obj = lazy.get(3);
 
After the above code is executed, obj will contain a new Date instance.
public static  ListpredicatedList(List list, Predicate predicate)
     Returns a predicated (validating) list backed by the given list.
public static  ListremoveAll(Collection collection, Collection remove)
     Removes the elements in remove from collection.
public static  ListretainAll(Collection collection, Collection retain)
     Returns a List containing all the elements in collection that are also in retain.
public static  Listsubtract(List list1, List list2)
     Subtracts all elements in the second list from the first list, placing the results in a new list.
public static  Listsum(List list1, List list2)
     Returns the sum of the given lists.
public static  ListsynchronizedList(List list)
     Returns a synchronized list backed by the given list.
public static  ListtransformedList(List list, Transformer transformer)
     Returns a transformed list backed by the given list.

Each object is passed through the transformer as it is added to the List.

public static  ListtypedList(List list, Class type)
     Returns a typed list backed by the given list.
public static  Listunion(List list1, List list2)
     Returns a new list containing the second list appended to the first list.
public static  ListunmodifiableList(List list)
     Returns an unmodifiable list backed by the given list.

Field Detail
EMPTY_LIST
final public static List EMPTY_LIST(Code)
An empty unmodifiable list. This uses the Collections Collections implementation and is provided for completeness.




Constructor Detail
ListUtils
public ListUtils()(Code)
ListUtils should not normally be instantiated.




Method Detail
fixedSizeList
public static List fixedSizeList(List list)(Code)
Returns a fixed-sized list backed by the given list. Elements may not be added or removed from the returned list, but existing elements can be changed (for instance, via the List.set(intObject) method).
Parameters:
  list - the list whose size to fix, must not be null a fixed-size list backed by that list
throws:
  IllegalArgumentException - if the List is null



hashCodeForList
public static int hashCodeForList(Collection list)(Code)
Generates a hash code using the algorithm specified in java.util.List.hashCode .

This method is useful for implementing List when you cannot extend AbstractList. The method takes Collection instances to enable other collection types to use the List implementation algorithm.
See Also:   java.util.List.hashCode
Parameters:
  list - the list to generate the hashCode for, may be null the hash code




intersection
public static List intersection(List list1, List list2)(Code)
Returns a new list containing all elements that are contained in both given lists.
Parameters:
  list1 - the first list
Parameters:
  list2 - the second list the intersection of those two lists
throws:
  NullPointerException - if either list is null



isEqualList
public static boolean isEqualList(Collection list1, Collection list2)(Code)
Tests two lists for value-equality as per the equality contract in java.util.List.equals(java.lang.Object) .

This method is useful for implementing List when you cannot extend AbstractList. The method takes Collection instances to enable other collection types to use the List implementation algorithm.

The relevant text (slightly paraphrased as this is a static method) is:

Compares the two list objects for equality. Returns true if and only if both lists have the same size, and all corresponding pairs of elements in the two lists are equal. (Two elements e1 and e2 are equal if (e1==null ? e2==null : e1.equals(e2)).) In other words, two lists are defined to be equal if they contain the same elements in the same order. This definition ensures that the equals method works properly across different implementations of the List interface.
Note: The behaviour of this method is undefined if the lists are modified during the equals comparison.
See Also:   java.util.List
Parameters:
  list1 - the first list, may be null
Parameters:
  list2 - the second list, may be null whether the lists are equal by value comparison



lazyList
public static List lazyList(List list, Factory factory)(Code)
Returns a "lazy" list whose elements will be created on demand.

When the index passed to the returned list's List.get(int) get method is greater than the list's size, then the factory will be used to create a new object and that object will be inserted at that index.

For instance:

 Factory factory = new Factory() {
 public Object create() {
 return new Date();
 }
 }
 List lazy = ListUtils.lazyList(new ArrayList(), factory);
 Object obj = lazy.get(3);
 
After the above code is executed, obj will contain a new Date instance. Furthermore, that Date instance is the fourth element in the list. The first, second, and third element are all set to null.
Parameters:
  list - the list to make lazy, must not be null
Parameters:
  factory - the factory for creating new objects, must not be null a lazy list backed by the given list
throws:
  IllegalArgumentException - if the List or Factory is null



predicatedList
public static List predicatedList(List list, Predicate predicate)(Code)
Returns a predicated (validating) list backed by the given list.

Only objects that pass the test in the given predicate can be added to the list. Trying to add an invalid object results in an IllegalArgumentException. It is important not to use the original list after invoking this method, as it is a backdoor for adding invalid objects.
Parameters:
  list - the list to predicate, must not be null
Parameters:
  predicate - the predicate for the list, must not be null a predicated list backed by the given list
throws:
  IllegalArgumentException - if the List or Predicate is null




removeAll
public static List removeAll(Collection collection, Collection remove)(Code)
Removes the elements in remove from collection. That is, this method returns a list containing all the elements in c that are not in remove. The cardinality of an element e in the returned collection is the same as the cardinality of e in collection unless remove contains e, in which case the cardinality is zero. This method is useful if you do not wish to modify collection and thus cannot call collection.removeAll(remove);.
Parameters:
  collection - the collection from which items are removed (in the returned collection)
Parameters:
  remove - the items to be removed from the returned collection a List containing all the elements of c exceptany elements that also occur in remove.
throws:
  NullPointerException - if either parameter is null
since:
   Commons Collections 3.2



retainAll
public static List retainAll(Collection collection, Collection retain)(Code)
Returns a List containing all the elements in collection that are also in retain. The cardinality of an element e in the returned list is the same as the cardinality of e in collection unless retain does not contain e, in which case the cardinality is zero. This method is useful if you do not wish to modify the collection c and thus cannot call collection.retainAll(retain);.
Parameters:
  collection - the collection whose contents are the target of the #retailAll operation
Parameters:
  retain - the collection containing the elements to be retained in the returned collection a List containing all the elements of cthat occur at least once in retain.
throws:
  NullPointerException - if either parameter is null
since:
   Commons Collections 3.2



subtract
public static List subtract(List list1, List list2)(Code)
Subtracts all elements in the second list from the first list, placing the results in a new list.

This differs from List.removeAll(Collection) in that cardinality is respected; if list1 contains two occurrences of null and list2 only contains one occurrence, then the returned list will still contain one occurrence.
Parameters:
  list1 - the list to subtract from
Parameters:
  list2 - the list to subtract a new list containing the results
throws:
  NullPointerException - if either list is null




sum
public static List sum(List list1, List list2)(Code)
Returns the sum of the given lists. This is their intersection subtracted from their union.
Parameters:
  list1 - the first list
Parameters:
  list2 - the second list a new list containing the sum of those lists
throws:
  NullPointerException - if either list is null



synchronizedList
public static List synchronizedList(List list)(Code)
Returns a synchronized list backed by the given list.

You must manually synchronize on the returned buffer's iterator to avoid non-deterministic behavior:

 List list = ListUtils.synchronizedList(myList);
 synchronized (list) {
 Iterator i = list.iterator();
 while (i.hasNext()) {
 process (i.next());
 }
 }
 
This method uses the implementation in the decorators subpackage.
Parameters:
  list - the list to synchronize, must not be null a synchronized list backed by the given list
throws:
  IllegalArgumentException - if the list is null



transformedList
public static List transformedList(List list, Transformer transformer)(Code)
Returns a transformed list backed by the given list.

Each object is passed through the transformer as it is added to the List. It is important not to use the original list after invoking this method, as it is a backdoor for adding untransformed objects.
Parameters:
  list - the list to predicate, must not be null
Parameters:
  transformer - the transformer for the list, must not be null a transformed list backed by the given list
throws:
  IllegalArgumentException - if the List or Transformer is null




typedList
public static List typedList(List list, Class type)(Code)
Returns a typed list backed by the given list.

Only objects of the specified type can be added to the list.
Parameters:
  list - the list to limit to a specific type, must not be null
Parameters:
  type - the type of objects which may be added to the list a typed list backed by the specified list




union
public static List union(List list1, List list2)(Code)
Returns a new list containing the second list appended to the first list. The List.addAll(Collection) operation is used to append the two given lists into a new list.
Parameters:
  list1 - the first list
Parameters:
  list2 - the second list a new list containing the union of those lists
throws:
  NullPointerException - if either list is null



unmodifiableList
public static List unmodifiableList(List list)(Code)
Returns an unmodifiable list backed by the given list.

This method uses the implementation in the decorators subpackage.
Parameters:
  list - the list to make unmodifiable, must not be null an unmodifiable list backed by the given list
throws:
  IllegalArgumentException - if the list is null




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.