net.sf.jga.fn.comparison

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 » Development » jga Generic Algorithms » net.sf.jga.fn.comparison 
net.sf.jga.fn.comparison
Provides Functors and Predicates that compare values of various types.

As of the 0.6 release, this package is in a state of transition. The forces at work are

  1. the comparision mechanism in Java, ie, the Comparable and Comparator interfaces.
  2. a desire to simplify the design so that a particular comparison method, eg, Less, is embodied in a single class.
  3. a desire to preserve type-safety.
  4. a desire to preserve convenience of default constructors.
In the previous releases, there were two functors that provided for a single comparison method -- one that was restricted to Comparable arguments, and one that used (and therefore required at construction) a Comparator. There was no relationship between the restricted version, which was named for the specific comparison operator (ie, Less.java) and the version that required a Comparator, which was named with a '-Comp' suffix (ie, LessComp.java).

To create a relationship between the two versions would have required that the '-Comp' version be the base class. To derive the -Comp version from the Comparable version would have had the effect of imposing a restriction in the base class that the derived class relaxes (this violates substitutabiliy).

Ideally, there would be one class: it would have to use a Comparator as implementation in order to be universally applicable, but the default constructor could provide some sort of default Comparator. Unfortunately, there really is no useful comparator that can be applied globally. The most common case that we can support, however, would be that Comparable objects be compare via their compareTo() method, as the ComparableComparator does. For this to work, we would need to ensure that the default constructor could only be called when the parm type of the functor implements Comparable. Java cannot enforce this restriction.

What we can do is define a subclass that has a more restrictive bound than the base class. Throughout this package, classes that need to support Comparable objects via a default Comparator define a public static subclass that imposes the additional generic bound and provides the correct default constructor. I've created a convention by which all of the subclasses are named for the bound they impose, so in this package, to use a comparison operator for Comparable types requires the use of the Comparable subclass. For example, to compare some arbitrary class for which a Comparator is available, you might use a Less object, and pass the Comparator at construction. To compare String objects, you would use Less.Comparable, whose default constructor passes a default Comparator to the base Less constructor.

So, the upshot of all this is that in the next release, we will be able to partially resolve the competing forces. The comparison functors will support all types of java objects using both comparison mechinisms with a single primary class for each comparison operation (the nested subclasses are de-emphasized -- they are an unfortunate implementation detail necessary to work around a limitation in generic java). The final versions preserve type-safety and the cost in inconvenience is not too great, as there is still a default constructor, it has simply been moved to the nested subclass in order to restrict its usage to appropriate generified types. In the next release:

  • The default constructor in the base classes will be removed.
  • The '-Comp' versions will be removed.
Both of these changes are deferred for one release in order to avoid breaking code without warning.
Java Source File NameTypeComment
Between.javaClass Unary Predicate that returns TRUE when its argument is between two given values.
ComparatorFn.javaClass Functor wrapper around Comparator object.
ComparisonFunctors.javaClass Static factory methods for the functors in the Comparison package.

Copyright © 2006 David A.

EqualEqual.javaClass Binary Predicate that returns TRUE for object arguments x and y when x == y using the built-in == operator.

Copyright © 2002-2005 David A.

Equality.javaClass Marker interface for those predicates that provide some sort of a test for equality.
author:
   David A.
EqualTo.javaClass Binary Predicate that returns TRUE for object arguments x and y when x == y using the built-in equals() method or an optional Comparator given at construction.
Greater.javaClass Binary Predicate that returns TRUE for arguments x and y when x > y.
GreaterEqual.javaClass Binary Predicate that returns TRUE for arguments x and y when x >= y.
Less.javaClass Binary Predicate that returns TRUE for arguments x and y when x < y.
LessEqual.javaClass Binary Predicate that returns TRUE for arguments x and y when x <= y.
Max.javaClass Binary Functor that returns the greater of two object arguments x and y.
Min.javaClass Binary Functor that returns the lesser of two object arguments x and y.
NotEqualEqual.javaClass Binary Predicate that returns TRUE for object arguments x and y when x != y using the built-in != operator.

Copyright © 2002-2005 David A.

NotEqualTo.javaClass Binary Predicate that returns TRUE for object arguments x and y when x != y using the built-in equals() method or an optional Comparator given at construction.
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.