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

TransformerUtils
public class TransformerUtils (Code)
TransformerUtils provides reference implementations and utilities for the Transformer functor interface. The supplied transformers are:
  • Invoker - returns the result of a method call on the input object
  • Clone - returns a clone of the input object
  • Constant - always returns the same object
  • Closure - performs a Closure and returns the input object
  • Predicate - returns the result of the predicate as a Boolean
  • Factory - returns a new object from a factory
  • Chained - chains two or more transformers together
  • Switch - calls one transformer based on one or more predicates
  • SwitchMap - calls one transformer looked up from a Map
  • Instantiate - the Class input object is instantiated
  • Map - returns an object from a supplied Map
  • Null - always returns null
  • NOP - returns the input object, which should be immutable
  • Exception - always throws an exception
  • StringValue - returns a java.lang.String representation of the input object
All the supplied transformers are Serializable.
since:
   Commons Collections 3.0
version:
   $Revision: 155406 $ $Date: 2005-02-26 12:55:26 +0000 (Sat, 26 Feb 2005) $
author:
   Stephen Colebourne
author:
   James Carman



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

Method Summary
public static  TransformerasTransformer(Closure closure)
     Creates a Transformer that calls a Closure each time the transformer is used.
public static  TransformerasTransformer(Predicate predicate)
     Creates a Transformer that calls a Predicate each time the transformer is used.
public static  TransformerasTransformer(Factory factory)
     Creates a Transformer that calls a Factory each time the transformer is used.
public static  TransformerchainedTransformer(Transformer transformer1, Transformer transformer2)
     Create a new Transformer that calls two transformers, passing the result of the first into the second.
public static  TransformerchainedTransformer(Transformer[] transformers)
     Create a new Transformer that calls each transformer in turn, passing the result into the next transformer.
public static  TransformerchainedTransformer(Collection transformers)
     Create a new Transformer that calls each transformer in turn, passing the result into the next transformer.
public static  TransformercloneTransformer()
     Gets a transformer that returns a clone of the input object.
public static  TransformerconstantTransformer(Object constantToReturn)
     Creates a Transformer that will return the same object each time the transformer is used.
public static  TransformerexceptionTransformer()
     Gets a transformer that always throws an exception.
public static  TransformerinstantiateTransformer()
     Gets a Transformer that expects an input Class object that it will instantiate.
public static  TransformerinstantiateTransformer(Class[] paramTypes, Object[] args)
     Creates a Transformer that expects an input Class object that it will instantiate.
public static  TransformerinvokerTransformer(String methodName)
     Gets a Transformer that invokes a method on the input object. The method must have no parameters.
public static  TransformerinvokerTransformer(String methodName, Class[] paramTypes, Object[] args)
     Gets a Transformer that invokes a method on the input object. The method parameters are specified.
public static  TransformermapTransformer(Map map)
     Creates a Transformer that uses the passed in Map to transform the input object (as a simple lookup).
public static  TransformernopTransformer()
     Gets a transformer that returns the input object.
public static  TransformernullTransformer()
     Gets a transformer that always returns null.
public static  TransformerstringValueTransformer()
     Gets a transformer that returns a java.lang.String representation of the input object.
public static  TransformerswitchMapTransformer(Map objectsAndTransformers)
     Create a new Transformer that uses the input object as a key to find the transformer to call.
public static  TransformerswitchTransformer(Predicate predicate, Transformer trueTransformer, Transformer falseTransformer)
     Create a new Transformer that calls one of two transformers depending on the specified predicate.
public static  TransformerswitchTransformer(Predicate[] predicates, Transformer[] transformers)
     Create a new Transformer that calls one of the transformers depending on the predicates.
public static  TransformerswitchTransformer(Predicate[] predicates, Transformer[] transformers, Transformer defaultTransformer)
     Create a new Transformer that calls one of the transformers depending on the predicates.
public static  TransformerswitchTransformer(Map predicatesAndTransformers)
     Create a new Transformer that calls one of the transformers depending on the predicates.


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




Method Detail
asTransformer
public static Transformer asTransformer(Closure closure)(Code)
Creates a Transformer that calls a Closure each time the transformer is used. The transformer returns the input object.
See Also:   org.apache.commons.collections.functors.ClosureTransformer
Parameters:
  closure - the closure to run each time in the transformer, not null the transformer
throws:
  IllegalArgumentException - if the closure is null



asTransformer
public static Transformer asTransformer(Predicate predicate)(Code)
Creates a Transformer that calls a Predicate each time the transformer is used. The transformer will return either Boolean.TRUE or Boolean.FALSE.
See Also:   org.apache.commons.collections.functors.PredicateTransformer
Parameters:
  predicate - the predicate to run each time in the transformer, not null the transformer
throws:
  IllegalArgumentException - if the predicate is null



asTransformer
public static Transformer asTransformer(Factory factory)(Code)
Creates a Transformer that calls a Factory each time the transformer is used. The transformer will return the value returned by the factory.
See Also:   org.apache.commons.collections.functors.FactoryTransformer
Parameters:
  factory - the factory to run each time in the transformer, not null the transformer
throws:
  IllegalArgumentException - if the factory is null



chainedTransformer
public static Transformer chainedTransformer(Transformer transformer1, Transformer transformer2)(Code)
Create a new Transformer that calls two transformers, passing the result of the first into the second.
See Also:   org.apache.commons.collections.functors.ChainedTransformer
Parameters:
  transformer1 - the first transformer
Parameters:
  transformer2 - the second transformer the transformer
throws:
  IllegalArgumentException - if either transformer is null



chainedTransformer
public static Transformer chainedTransformer(Transformer[] transformers)(Code)
Create a new Transformer that calls each transformer in turn, passing the result into the next transformer.
See Also:   org.apache.commons.collections.functors.ChainedTransformer
Parameters:
  transformers - an array of transformers to chain the transformer
throws:
  IllegalArgumentException - if the transformers array is null
throws:
  IllegalArgumentException - if any transformer in the array is null



chainedTransformer
public static Transformer chainedTransformer(Collection transformers)(Code)
Create a new Transformer that calls each transformer in turn, passing the result into the next transformer. The ordering is that of the iterator() method on the collection.
See Also:   org.apache.commons.collections.functors.ChainedTransformer
Parameters:
  transformers - a collection of transformers to chain the transformer
throws:
  IllegalArgumentException - if the transformers collection is null
throws:
  IllegalArgumentException - if any transformer in the collection is null



cloneTransformer
public static Transformer cloneTransformer()(Code)
Gets a transformer that returns a clone of the input object. The input object will be cloned using one of these techniques (in order):



constantTransformer
public static Transformer constantTransformer(Object constantToReturn)(Code)
Creates a Transformer that will return the same object each time the transformer is used.
See Also:   org.apache.commons.collections.functors.ConstantTransformer
Parameters:
  constantToReturn - the constant object to return each time in the transformer the transformer.



exceptionTransformer
public static Transformer exceptionTransformer()(Code)
Gets a transformer that always throws an exception. This could be useful during testing as a placeholder.
See Also:   org.apache.commons.collections.functors.ExceptionTransformer the transformer



instantiateTransformer
public static Transformer instantiateTransformer()(Code)
Gets a Transformer that expects an input Class object that it will instantiate.
See Also:   org.apache.commons.collections.functors.InstantiateTransformer the transformer



instantiateTransformer
public static Transformer instantiateTransformer(Class[] paramTypes, Object[] args)(Code)
Creates a Transformer that expects an input Class object that it will instantiate. The constructor used is determined by the arguments specified to this method.
See Also:   org.apache.commons.collections.functors.InstantiateTransformer
Parameters:
  paramTypes - parameter types for the constructor, can be null
Parameters:
  args - the arguments to pass to the constructor, can be null the transformer
throws:
  IllegalArgumentException - if the paramTypes and args don't match



invokerTransformer
public static Transformer invokerTransformer(String methodName)(Code)
Gets a Transformer that invokes a method on the input object. The method must have no parameters. If the input object is null, null is returned.

For example, TransformerUtils.invokerTransformer("getName"); will call the getName/code> method on the input object to determine the transformer result.
See Also:   org.apache.commons.collections.functors.InvokerTransformer
Parameters:
  methodName - the method name to call on the input object, may not be null the transformer
throws:
  IllegalArgumentException - if the methodName is null.




invokerTransformer
public static Transformer invokerTransformer(String methodName, Class[] paramTypes, Object[] args)(Code)
Gets a Transformer that invokes a method on the input object. The method parameters are specified. If the input object is null, null is returned.
See Also:   org.apache.commons.collections.functors.InvokerTransformer
Parameters:
  methodName - the name of the method
Parameters:
  paramTypes - the parameter types
Parameters:
  args - the arguments the transformer
throws:
  IllegalArgumentException - if the method name is null
throws:
  IllegalArgumentException - if the paramTypes and args don't match



mapTransformer
public static Transformer mapTransformer(Map map)(Code)
Creates a Transformer that uses the passed in Map to transform the input object (as a simple lookup).
See Also:   org.apache.commons.collections.functors.MapTransformer
Parameters:
  map - the map to use to transform the objects the transformer
throws:
  IllegalArgumentException - if the map is null



nopTransformer
public static Transformer nopTransformer()(Code)
Gets a transformer that returns the input object. The input object should be immutable to maintain the contract of Transformer (although this is not checked).
See Also:   org.apache.commons.collections.functors.NOPTransformer the transformer



nullTransformer
public static Transformer nullTransformer()(Code)
Gets a transformer that always returns null.
See Also:   org.apache.commons.collections.functors.ConstantTransformer the transformer



stringValueTransformer
public static Transformer stringValueTransformer()(Code)
Gets a transformer that returns a java.lang.String representation of the input object. This is achieved via the toString method, null returns 'null'.
See Also:   org.apache.commons.collections.functors.StringValueTransformer the transformer



switchMapTransformer
public static Transformer switchMapTransformer(Map objectsAndTransformers)(Code)
Create a new Transformer that uses the input object as a key to find the transformer to call.

The Map consists of object keys and Transformer values. A transformer is called if the input object equals the key. If there is no match, the default transformer is called. The default transformer is set in the map using a null key. If no default is set, null will be returned in a default case.
See Also:   org.apache.commons.collections.functors.SwitchTransformer
Parameters:
  objectsAndTransformers - a map of objects to transformers the transformer
throws:
  IllegalArgumentException - if the map is null
throws:
  IllegalArgumentException - if the map is empty
throws:
  IllegalArgumentException - if any transformer in the map is null




switchTransformer
public static Transformer switchTransformer(Predicate predicate, Transformer trueTransformer, Transformer falseTransformer)(Code)
Create a new Transformer that calls one of two transformers depending on the specified predicate.
See Also:   org.apache.commons.collections.functors.SwitchTransformer
Parameters:
  predicate - the predicate to switch on
Parameters:
  trueTransformer - the transformer called if the predicate is true
Parameters:
  falseTransformer - the transformer called if the predicate is false the transformer
throws:
  IllegalArgumentException - if the predicate is null
throws:
  IllegalArgumentException - if either transformer is null



switchTransformer
public static Transformer switchTransformer(Predicate[] predicates, Transformer[] transformers)(Code)
Create a new Transformer that calls one of the transformers depending on the predicates. The transformer 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, null is returned.
See Also:   org.apache.commons.collections.functors.SwitchTransformer
Parameters:
  predicates - an array of predicates to check
Parameters:
  transformers - an array of transformers to call the transformer
throws:
  IllegalArgumentException - if the either array is null
throws:
  IllegalArgumentException - if the either array has 0 elements
throws:
  IllegalArgumentException - if any element in the arrays is null
throws:
  IllegalArgumentException - if the arrays are different sizes



switchTransformer
public static Transformer switchTransformer(Predicate[] predicates, Transformer[] transformers, Transformer defaultTransformer)(Code)
Create a new Transformer that calls one of the transformers depending on the predicates. The transformer 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 transformer is called. If the default transformer is null, null is returned.
See Also:   org.apache.commons.collections.functors.SwitchTransformer
Parameters:
  predicates - an array of predicates to check
Parameters:
  transformers - an array of transformers to call
Parameters:
  defaultTransformer - the default to call if no predicate matches, null means return null the transformer
throws:
  IllegalArgumentException - if the either array is null
throws:
  IllegalArgumentException - if the either array has 0 elements
throws:
  IllegalArgumentException - if any element in the arrays is null
throws:
  IllegalArgumentException - if the arrays are different sizes



switchTransformer
public static Transformer switchTransformer(Map predicatesAndTransformers)(Code)
Create a new Transformer that calls one of the transformers depending on the predicates.

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




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.