Java Doc for FixedOrderComparator.java in  » Library » Apache-common-Collections » org » apache » commons » collections » comparators » 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.comparators 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


java.lang.Object
   org.apache.commons.collections.comparators.FixedOrderComparator

FixedOrderComparator
public class FixedOrderComparator implements Comparator(Code)
A Comparator which imposes a specific order on a specific set of Objects. Objects are presented to the FixedOrderComparator in a specified order and subsequent calls to FixedOrderComparator.compare(Object,Object) compare yield that order. For example:
 String[] planets = {"Mercury", "Venus", "Earth", "Mars"};
 FixedOrderComparator distanceFromSun = new FixedOrderComparator(planets);
 Arrays.sort(planets);                     // Sort to alphabetical order
 Arrays.sort(planets, distanceFromSun);    // Back to original order
 

Once compare has been called, the FixedOrderComparator is locked and attempts to modify it yield an UnsupportedOperationException.

Instances of FixedOrderComparator are not synchronized. The class is not thread-safe at construction time, but it is thread-safe to perform multiple comparisons after all the setup operations are complete.
since:
   Commons Collections 3.0
version:
   $Revision: 155406 $ $Date: 2005-02-26 12:55:26 +0000 (Sat, 26 Feb 2005) $
author:
   David Leppik
author:
   Stephen Colebourne
author:
   Janek Bogucki



Field Summary
final public static  intUNKNOWN_AFTER
     Behavior when comparing unknown Objects: unknown objects compare as after known Objects.
final public static  intUNKNOWN_BEFORE
     Behavior when comparing unknown Objects: unknown objects compare as before known Objects.
final public static  intUNKNOWN_THROW_EXCEPTION
     Behavior when comparing unknown Objects: unknown objects cause a IllegalArgumentException to be thrown.

Constructor Summary
public  FixedOrderComparator()
     Constructs an empty FixedOrderComparator.
public  FixedOrderComparator(Object[] items)
     Constructs a FixedOrderComparator which uses the order of the given array to compare the objects.
public  FixedOrderComparator(List items)
     Constructs a FixedOrderComparator which uses the order of the given list to compare the objects.

Method Summary
public  booleanadd(Object obj)
     Adds an item, which compares as after all items known to the Comparator. If the item is already known to the Comparator, its old position is replaced with the new position.
Parameters:
  obj - the item to be added to the Comparator.
public  booleanaddAsEqual(Object existingObj, Object newObj)
     Adds a new item, which compares as equal to the given existing item.
protected  voidcheckLocked()
     Checks to see whether the comparator is now locked against further changes.
public  intcompare(Object obj1, Object obj2)
     Compares two objects according to the order of this Comparator.

It is important to note that this class will throw an IllegalArgumentException in the case of an unrecognised object.

public  intgetUnknownObjectBehavior()
     Gets the behavior for comparing unknown objects.
public  booleanisLocked()
     Returns true if modifications cannot be made to the FixedOrderComparator.
public  voidsetUnknownObjectBehavior(int unknownObjectBehavior)
     Sets the behavior for comparing unknown objects.

Field Detail
UNKNOWN_AFTER
final public static int UNKNOWN_AFTER(Code)
Behavior when comparing unknown Objects: unknown objects compare as after known Objects.



UNKNOWN_BEFORE
final public static int UNKNOWN_BEFORE(Code)
Behavior when comparing unknown Objects: unknown objects compare as before known Objects.



UNKNOWN_THROW_EXCEPTION
final public static int UNKNOWN_THROW_EXCEPTION(Code)
Behavior when comparing unknown Objects: unknown objects cause a IllegalArgumentException to be thrown. This is the default behavior.




Constructor Detail
FixedOrderComparator
public FixedOrderComparator()(Code)
Constructs an empty FixedOrderComparator.



FixedOrderComparator
public FixedOrderComparator(Object[] items)(Code)
Constructs a FixedOrderComparator which uses the order of the given array to compare the objects.

The array is copied, so later changes will not affect the comparator.
Parameters:
  items - the items that the comparator can compare in order
throws:
  IllegalArgumentException - if the array is null




FixedOrderComparator
public FixedOrderComparator(List items)(Code)
Constructs a FixedOrderComparator which uses the order of the given list to compare the objects.

The list is copied, so later changes will not affect the comparator.
Parameters:
  items - the items that the comparator can compare in order
throws:
  IllegalArgumentException - if the list is null





Method Detail
add
public boolean add(Object obj)(Code)
Adds an item, which compares as after all items known to the Comparator. If the item is already known to the Comparator, its old position is replaced with the new position.
Parameters:
  obj - the item to be added to the Comparator. true if obj has been added for the first time, false ifit was already known to the Comparator.
throws:
  UnsupportedOperationException - if a comparison has already been made



addAsEqual
public boolean addAsEqual(Object existingObj, Object newObj)(Code)
Adds a new item, which compares as equal to the given existing item.
Parameters:
  existingObj - an item already in the Comparator's set of known objects
Parameters:
  newObj - an item to be added to the Comparator's set ofknown objects true if newObj has been added for the first time, false ifit was already known to the Comparator.
throws:
  IllegalArgumentException - if existingObject is not in the Comparator's set of known objects.
throws:
  UnsupportedOperationException - if a comparison has already been made



checkLocked
protected void checkLocked()(Code)
Checks to see whether the comparator is now locked against further changes.
throws:
  UnsupportedOperationException - if the comparator is locked



compare
public int compare(Object obj1, Object obj2)(Code)
Compares two objects according to the order of this Comparator.

It is important to note that this class will throw an IllegalArgumentException in the case of an unrecognised object. This is not specified in the Comparator interface, but is the most appropriate exception.
Parameters:
  obj1 - the first object to compare
Parameters:
  obj2 - the second object to compare negative if obj1 is less, positive if greater, zero if equal
throws:
  IllegalArgumentException - if obj1 or obj2 are not known to this Comparator and an alternative behavior has not been setvia FixedOrderComparator.setUnknownObjectBehavior(int).




getUnknownObjectBehavior
public int getUnknownObjectBehavior()(Code)
Gets the behavior for comparing unknown objects. the flag for unknown behaviour - UNKNOWN_AFTER,UNKNOWN_BEFORE or UNKNOWN_THROW_EXCEPTION



isLocked
public boolean isLocked()(Code)
Returns true if modifications cannot be made to the FixedOrderComparator. FixedOrderComparators cannot be modified once they have performed a comparison. true if attempts to change the FixedOrderComparator yield anUnsupportedOperationException, false if it can be changed.



setUnknownObjectBehavior
public void setUnknownObjectBehavior(int unknownObjectBehavior)(Code)
Sets the behavior for comparing unknown objects.
Parameters:
  unknownObjectBehavior - the flag for unknown behaviour -UNKNOWN_AFTER, UNKNOWN_BEFORE or UNKNOWN_THROW_EXCEPTION
throws:
  UnsupportedOperationException - if a comparison has been performed
throws:
  IllegalArgumentException - if the unknown flag is not valid



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.