commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Duncan Jones (JIRA)" <j...@apache.org>
Subject [jira] [Resolved] (LANG-827) CompareToBuilder's doc doesn't specify precedence of fields it uses in performing comparisons
Date Mon, 29 Sep 2014 12:05:34 GMT

     [ https://issues.apache.org/jira/browse/LANG-827?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]

Duncan Jones resolved LANG-827.
-------------------------------
       Resolution: Implemented
    Fix Version/s:     (was: Patch Needed)
                   3.4
         Assignee: Duncan Jones

I've added two paragraphs to the class Javadoc:

bq. Values are compared in the order they are appended to the builder. If any comparison returns
a non-zero result, then that value will be the result returned by {{toComparison()}} and all
subsequent comparisons are skipped.

and

bq. The reflective methods compare object fields in the order returned by {{Class.getDeclaredFields()}}.
The fields of the class are compared first, followed by those of its parent classes (in order
from the bottom to the top of the class hierarchy).


Author: djones
Date: Mon Sep 29 12:02:11 2014
New Revision: 1628165

URL: http://svn.apache.org/r1628165
Log:
Fix for LANG-827: CompareToBuilder's doc doesn't specify precedence of fields it uses in performing
comparisons

Modified:
    commons/proper/lang/trunk/src/changes/changes.xml
    commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/builder/CompareToBuilder.java

> CompareToBuilder's doc doesn't specify precedence of fields it uses in performing comparisons
> ---------------------------------------------------------------------------------------------
>
>                 Key: LANG-827
>                 URL: https://issues.apache.org/jira/browse/LANG-827
>             Project: Commons Lang
>          Issue Type: Improvement
>          Components: lang.builder.*
>    Affects Versions: 3.1
>            Reporter: david cogen
>            Assignee: Duncan Jones
>              Labels: documentation
>             Fix For: 3.4
>
>
> The doc does not specify in what order the fields declared using append() are applied.
So if for example I use CompareToBuilder to build a comparator for a class Complex (2 doubles),
and I use append(c.real) followed by append(c.imag), does the comparison consider the real
or imaginary part "more important" for the final result of the comparison.
> And similarly, the reflection versions also don't specify the order of the fields they
consider.
> Yes, I can experiment to determine the behavior. Which I am about to do. But I am not
comfortable relying on experimentally-determined, undocumented behavior for correcteness.
Which is why I classified this as Major priority, not Minor or Trivial.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Mime
View raw message