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

ClosureUtils
public class ClosureUtils (Code)
ClosureUtils provides reference implementations and utilities for the Closure functor interface. The supplied closures are:
  • Invoker - invokes a method on the input object
  • For - repeatedly calls a closure for a fixed number of times
  • While - repeatedly calls a closure while a predicate is true
  • DoWhile - repeatedly calls a closure while a predicate is true
  • Chained - chains two or more closures together
  • Switch - calls one closure based on one or more predicates
  • SwitchMap - calls one closure looked up from a Map
  • Transformer - wraps a Transformer as a Closure
  • NOP - does nothing
  • Exception - always throws an exception
All the supplied closures are Serializable.
since:
   Commons Collections 3.0
version:
   $Revision: 375766 $ $Date: 2006-02-07 23:10:36 +0000 (Tue, 07 Feb 2006) $
author:
   Stephen Colebourne
author:
   Matt Benson



Constructor Summary
public  ClosureUtils()
     This class is not normally instantiated.

Method Summary
public static  ClosureasClosure(Transformer transformer)
     Creates a Closure that calls a Transformer each time it is called.
public static  ClosurechainedClosure(Closure closure1, Closure closure2)
     Create a new Closure that calls two Closures, passing the result of the first into the second.
public static  ClosurechainedClosure(Closure[] closures)
     Create a new Closure that calls each closure in turn, passing the result into the next closure.
public static  ClosurechainedClosure(Collection closures)
     Create a new Closure that calls each closure in turn, passing the result into the next closure.
public static  ClosuredoWhileClosure(Closure closure, Predicate predicate)
     Creates a Closure that will call the closure once and then repeatedly until the predicate returns false.
public static  ClosureexceptionClosure()
     Gets a Closure that always throws an exception.
public static  ClosureforClosure(int count, Closure closure)
     Creates a Closure that will call the closure count times.
public static  ClosureifClosure(Predicate predicate, Closure trueClosure)
     Create a new Closure that calls another closure based on the result of the specified predicate.
public static  ClosureifClosure(Predicate predicate, Closure trueClosure, Closure falseClosure)
     Create a new Closure that calls one of two closures depending on the specified predicate.
public static  ClosureinvokerClosure(String methodName)
     Creates a Closure that will invoke a specific method on the closure's input object by reflection.
public static  ClosureinvokerClosure(String methodName, Class[] paramTypes, Object[] args)
     Creates a Closure that will invoke a specific method on the closure's input object by reflection.
public static  ClosurenopClosure()
     Gets a Closure that will do nothing.
public static  ClosureswitchClosure(Predicate[] predicates, Closure[] closures)
     Create a new Closure that calls one of the closures depending on the predicates.

The closure at array location 0 is called if the predicate at array location 0 returned true.

public static  ClosureswitchClosure(Predicate[] predicates, Closure[] closures, Closure defaultClosure)
     Create a new Closure that calls one of the closures depending on the predicates.

The closure at array location 0 is called if the predicate at array location 0 returned true.

public static  ClosureswitchClosure(Map predicatesAndClosures)
     Create a new Closure that calls one of the closures depending on the predicates.
public static  ClosureswitchMapClosure(Map objectsAndClosures)
     Create a new Closure that uses the input object as a key to find the closure to call.
public static  ClosurewhileClosure(Predicate predicate, Closure closure)
     Creates a Closure that will call the closure repeatedly until the predicate returns false.


Constructor Detail
ClosureUtils
public ClosureUtils()(Code)
This class is not normally instantiated.




Method Detail
asClosure
public static Closure asClosure(Transformer transformer)(Code)
Creates a Closure that calls a Transformer each time it is called. The transformer will be called using the closure's input object. The transformer's result will be ignored.
See Also:   org.apache.commons.collections.functors.TransformerClosure
Parameters:
  transformer - the transformer to run each time in the closure, null means nop the closure



chainedClosure
public static Closure chainedClosure(Closure closure1, Closure closure2)(Code)
Create a new Closure that calls two Closures, passing the result of the first into the second.
See Also:   org.apache.commons.collections.functors.ChainedClosure
Parameters:
  closure1 - the first closure
Parameters:
  closure2 - the second closure the chained closure
throws:
  IllegalArgumentException - if either closure is null



chainedClosure
public static Closure chainedClosure(Closure[] closures)(Code)
Create a new Closure that calls each closure in turn, passing the result into the next closure.
See Also:   org.apache.commons.collections.functors.ChainedClosure
Parameters:
  closures - an array of closures to chain the chained closure
throws:
  IllegalArgumentException - if the closures array is null
throws:
  IllegalArgumentException - if any closure in the array is null



chainedClosure
public static Closure chainedClosure(Collection closures)(Code)
Create a new Closure that calls each closure in turn, passing the result into the next closure. The ordering is that of the iterator() method on the collection.
See Also:   org.apache.commons.collections.functors.ChainedClosure
Parameters:
  closures - a collection of closures to chain the chained closure
throws:
  IllegalArgumentException - if the closures collection is null
throws:
  IllegalArgumentException - if the closures collection is empty
throws:
  IllegalArgumentException - if any closure in the collection is null



doWhileClosure
public static Closure doWhileClosure(Closure closure, Predicate predicate)(Code)
Creates a Closure that will call the closure once and then repeatedly until the predicate returns false.
See Also:   org.apache.commons.collections.functors.WhileClosure
Parameters:
  closure - the closure to call repeatedly, not null
Parameters:
  predicate - the predicate to use as an end of loop test, not null the do-while closure
throws:
  IllegalArgumentException - if either argument is null



exceptionClosure
public static Closure exceptionClosure()(Code)
Gets a Closure that always throws an exception. This could be useful during testing as a placeholder.
See Also:   org.apache.commons.collections.functors.ExceptionClosure the closure



forClosure
public static Closure forClosure(int count, Closure closure)(Code)
Creates a Closure that will call the closure count times.

A null closure or zero count returns the NOPClosure.
See Also:   org.apache.commons.collections.functors.ForClosure
Parameters:
  count - the number of times to loop
Parameters:
  closure - the closure to call repeatedly the for closure




ifClosure
public static Closure ifClosure(Predicate predicate, Closure trueClosure)(Code)
Create a new Closure that calls another closure based on the result of the specified predicate.
See Also:   org.apache.commons.collections.functors.IfClosure
Parameters:
  predicate - the validating predicate
Parameters:
  trueClosure - the closure called if the predicate is true the if closure
throws:
  IllegalArgumentException - if the predicate is null
throws:
  IllegalArgumentException - if the closure is null
since:
   Commons Collections 3.2



ifClosure
public static Closure ifClosure(Predicate predicate, Closure trueClosure, Closure falseClosure)(Code)
Create a new Closure that calls one of two closures depending on the specified predicate.
See Also:   org.apache.commons.collections.functors.IfClosure
Parameters:
  predicate - the predicate to switch on
Parameters:
  trueClosure - the closure called if the predicate is true
Parameters:
  falseClosure - the closure called if the predicate is false the switch closure
throws:
  IllegalArgumentException - if the predicate is null
throws:
  IllegalArgumentException - if either closure is null



invokerClosure
public static Closure invokerClosure(String methodName)(Code)
Creates a Closure that will invoke a specific method on the closure's input object by reflection.
See Also:   org.apache.commons.collections.functors.InvokerTransformer
See Also:   org.apache.commons.collections.functors.TransformerClosure
Parameters:
  methodName - the name of the method the invoker closure
throws:
  IllegalArgumentException - if the method name is null



invokerClosure
public static Closure invokerClosure(String methodName, Class[] paramTypes, Object[] args)(Code)
Creates a Closure that will invoke a specific method on the closure's input object by reflection.
See Also:   org.apache.commons.collections.functors.InvokerTransformer
See Also:   org.apache.commons.collections.functors.TransformerClosure
Parameters:
  methodName - the name of the method
Parameters:
  paramTypes - the parameter types
Parameters:
  args - the arguments the invoker closure
throws:
  IllegalArgumentException - if the method name is null
throws:
  IllegalArgumentException - if the paramTypes and args don't match



nopClosure
public static Closure nopClosure()(Code)
Gets a Closure that will do nothing. This could be useful during testing as a placeholder.
See Also:   org.apache.commons.collections.functors.NOPClosure the closure



switchClosure
public static Closure switchClosure(Predicate[] predicates, Closure[] closures)(Code)
Create a new Closure that calls one of the closures depending on the predicates.

The closure at array location 0 is called if the predicate at array location 0 returned true. Each predicate is evaluated until one returns true.
See Also:   org.apache.commons.collections.functors.SwitchClosure
Parameters:
  predicates - an array of predicates to check, not null
Parameters:
  closures - an array of closures to call, not null the switch closure
throws:
  IllegalArgumentException - if the either array is null
throws:
  IllegalArgumentException - if any element in the arrays is null
throws:
  IllegalArgumentException - if the arrays are different sizes




switchClosure
public static Closure switchClosure(Predicate[] predicates, Closure[] closures, Closure defaultClosure)(Code)
Create a new Closure that calls one of the closures depending on the predicates.

The closure at array location 0 is called if the predicate at array location 0 returned true. Each predicate is evaluated until one returns true. If no predicates evaluate to true, the default closure is called.
See Also:   org.apache.commons.collections.functors.SwitchClosure
Parameters:
  predicates - an array of predicates to check, not null
Parameters:
  closures - an array of closures to call, not null
Parameters:
  defaultClosure - the default to call if no predicate matches the switch closure
throws:
  IllegalArgumentException - if the either array is null
throws:
  IllegalArgumentException - if any element in the arrays is null
throws:
  IllegalArgumentException - if the arrays are different sizes




switchClosure
public static Closure switchClosure(Map predicatesAndClosures)(Code)
Create a new Closure that calls one of the closures depending on the predicates.

The Map consists of Predicate keys and Closure values. A closure is called if its matching predicate returns true. Each predicate is evaluated until one returns true. If no predicates evaluate to true, the default closure is called. The default closure is set in the map with a null key. The ordering is that of the iterator() method on the entryset collection of the map.
See Also:   org.apache.commons.collections.functors.SwitchClosure
Parameters:
  predicatesAndClosures - a map of predicates to closures the switch closure
throws:
  IllegalArgumentException - if the map is null
throws:
  IllegalArgumentException - if the map is empty
throws:
  IllegalArgumentException - if any closure in the map is null
throws:
  ClassCastException - if the map elements are of the wrong type




switchMapClosure
public static Closure switchMapClosure(Map objectsAndClosures)(Code)
Create a new Closure that uses the input object as a key to find the closure to call.

The Map consists of object keys and Closure values. A closure is called if the input object equals the key. If there is no match, the default closure is called. The default closure is set in the map using a null key.
See Also:   org.apache.commons.collections.functors.SwitchClosure
Parameters:
  objectsAndClosures - a map of objects to closures the closure
throws:
  IllegalArgumentException - if the map is null
throws:
  IllegalArgumentException - if the map is empty
throws:
  IllegalArgumentException - if any closure in the map is null




whileClosure
public static Closure whileClosure(Predicate predicate, Closure closure)(Code)
Creates a Closure that will call the closure repeatedly until the predicate returns false.
See Also:   org.apache.commons.collections.functors.WhileClosure
Parameters:
  predicate - the predicate to use as an end of loop test, not null
Parameters:
  closure - the closure to call repeatedly, not null the while closure
throws:
  IllegalArgumentException - if either argument 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.