Java Doc for BeanComparator.java in  » Byte-Code » Cojen » org » cojen » util » 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 » Byte Code » Cojen » org.cojen.util 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


java.lang.Object
   org.cojen.util.BeanComparator

BeanComparator
public class BeanComparator implements Comparator,Serializable(Code)
A highly customizable, high-performance Comparator, designed specifically for advanced sorting of JavaBeans. BeanComparators contain dynamically auto-generated code and perform as well as hand written Comparators.

BeanComparator instances are immutable; order customization methods return new BeanComparators with refined rules. Calls to customizers can be chained together to read like a formula. The following example produces a Comparator that orders Threads by name, thread group name, and reverse priority.

 Comparator c = BeanComparator.forClass(Thread.class)
 .orderBy("name")
 .orderBy("threadGroup.name")
 .orderBy("-priority");
 
The results of sorting Threads using this Comparator and displaying the results in a table may look like this:

namethreadGroup.namepriority
daemonappGroup9
mainmain5
mainsecureGroup5
sweepermain1
Thread-0main5
Thread-1main5
workerappGroup8
workerappGroup5
workersecureGroup8
workersecureGroup5

An equivalent Thread ordering Comparator may be specified as:

 Comparator c = BeanComparator.forClass(Thread.class)
 .orderBy("name")
 .orderBy("threadGroup")
 .using(BeanComparator.forClass(ThreadGroup.class).orderBy("name"))
 .orderBy("priority")
 .reverse();
 
The current implementation of BeanComparator has been optimized for fast construction and execution of BeanComparators. For maximum performance, however, save and re-use BeanComparators wherever possible.

Even though BeanComparator makes use of auto-generated code, instances are fully Serializable, as long as all passed in Comparators are also Serializable.
author:
   Brian S O'Neill





Method Summary
public  BeanComparatorcaseSensitive()
     Override the collator and compare just the last order-by property using String.compareTo(String) String.compareTo , if it is of type String.
public  BeanComparatorcollate(Comparator c)
     Set a Comparator for ordering Strings, which is passed on to all BeanComparators derived from this one.
public  intcompare(Object obj1, Object obj2)
    
public  booleanequals(Object obj)
     Compares BeanComparators for equality based on their imposed ordering. Returns true only if the given object is a BeanComparater and it can be determined without a doubt that the ordering is identical.
public static  BeanComparatorforClass(Class clazz)
     Get or create a new BeanComparator for beans of the given type.
public  inthashCode()
    
public  BeanComparatornullHigh()
     Set the order of comparisons against null as being high (the default) on just the last BeanComparator.orderBy order-by property.
public  BeanComparatornullLow()
     Set the order of comparisons against null as being low on just the last BeanComparator.orderBy order-by property.
public  BeanComparatororderBy(String propertyName)
     Add an order-by property to produce a more refined Comparator.
public  BeanComparatorreverse()
     Toggle reverse-order option on just the last BeanComparator.orderBy order-by property.
public  BeanComparatorusing(Comparator c)
     Specifiy a Comparator to use on just the last BeanComparator.orderBy order-by property.



Method Detail
caseSensitive
public BeanComparator caseSensitive()(Code)
Override the collator and compare just the last order-by property using String.compareTo(String) String.compareTo , if it is of type String. If no order-by properties have been specified then this call is ineffective.

A BeanComparator.using using Comparator disables this setting. Passing null to the using method will re-enable a case-sensitive setting.




collate
public BeanComparator collate(Comparator c)(Code)
Set a Comparator for ordering Strings, which is passed on to all BeanComparators derived from this one. By default, String are compared using String.CASE_INSENSITIVE_ORDER . Passing null for a collator will cause all String comparisons to use String.compareTo(String) String.compareTo .

A BeanComparator.using using Comparator disables this setting. Passing null to the using method will re-enable a collator.
Parameters:
  c - Comparator to use for ordering all Strings. Passing nullcauses all Strings to be ordered byString.compareTo(String) String.compareTo.




compare
public int compare(Object obj1, Object obj2) throws ClassCastException(Code)



equals
public boolean equals(Object obj)(Code)
Compares BeanComparators for equality based on their imposed ordering. Returns true only if the given object is a BeanComparater and it can be determined without a doubt that the ordering is identical. Because equality testing is dependent on the behavior of the equals methods of any 'using' Comparators and/or collators, false may be returned even though ordering is in fact identical.



forClass
public static BeanComparator forClass(Class clazz)(Code)
Get or create a new BeanComparator for beans of the given type. Without any BeanComparator.orderBy order-by properties specified, the returned BeanComparator can only order against null beans (null is BeanComparator.nullHigh high by default), and treats all other comparisons as equal.



hashCode
public int hashCode()(Code)



nullHigh
public BeanComparator nullHigh()(Code)
Set the order of comparisons against null as being high (the default) on just the last BeanComparator.orderBy order-by property. If no order-by properties have been specified, then null high order is applied to the compared beans. Null high order is the default for consistency with the high ordering of Float.NaN NaN by Float.compareTo(Float) Float .

Calling 'nullHigh, reverse' is equivalent to calling 'reverse, nullLow'.




nullLow
public BeanComparator nullLow()(Code)
Set the order of comparisons against null as being low on just the last BeanComparator.orderBy order-by property. If no order-by properties have been specified, then null low order is applied to the compared beans.

Calling 'reverse, nullLow' is equivalent to calling 'nullHigh, reverse'.




orderBy
public BeanComparator orderBy(String propertyName) throws IllegalArgumentException(Code)
Add an order-by property to produce a more refined Comparator. If the property does not return a Comparable object when BeanComparator.compare compare is called on the returned comparator, the property is ignored. Call BeanComparator.using using on the returned BeanComparator to specify a Comparator to use for this property instead.

The specified propery name may refer to sub-properties using a dot notation. For example, if the bean being compared contains a property named "info" of type "Information", and "Information" contains a property named "text", then ordering by the info text can be specified by "info.text". Sub-properties of sub-properties may be refered to as well, a.b.c.d.e etc.

If property type is a primitive, ordering is the same as for its Comparable object peer. Primitive booleans are ordered false low, true high. Floating point primitves are ordered exactly the same way as Float.compareTo(Float) Float.compareTo and Double.compareTo(Double) Double.compareTo .

As a convenience, property names may have a '-' or '+' character prefix to specify sort order. A prefix of '-' indicates that the property is to be sorted in reverse (descending). By default, properties are sorted in ascending order, and so a prefix of '+' has no effect.

Any previously applied BeanComparator.reverse reverse-order , BeanComparator.nullHighnull-order and BeanComparator.caseSensitive case-sensitive settings are not carried over, and are reset to the defaults for this order-by property.
throws:
  IllegalArgumentException - when property doesn't exist or cannotbe read.




reverse
public BeanComparator reverse()(Code)
Toggle reverse-order option on just the last BeanComparator.orderBy order-by property. By default, order is ascending. If no order-by properties have been specified, then reverse order is applied to the compared beans.



using
public BeanComparator using(Comparator c)(Code)
Specifiy a Comparator to use on just the last BeanComparator.orderBy order-by property. This is good for comparing properties that are not Comparable or for applying special ordering rules for a property. If no order-by properties have been specified, then Comparator is applied to the compared beans.

Any previously applied String BeanComparator.caseSensitive case-sensitive or BeanComparator.collate collator settings are overridden by this Comparator. If property values being compared are primitive, they are converted to their object peers before being passed to the Comparator.
Parameters:
  c - Comparator to use on the last order-by property. Passing nullrestores the default comparison for the last order-by property.




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.