harmony-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Richard Liang <richard.lian...@gmail.com>
Subject Re: [classlib][luni] Is fully comply with Comparator.compare(T, T) necessary (Re JIRA harmony 1026)
Date Wed, 02 Aug 2006 07:04:57 GMT

Spark Shen wrote:
> I constructed a MockComparator as below:
> public static class MockComparator<T> implements Comparator<T> {
>        public int compare(T o1, T o2) {
>            if(null == o1) return -1;
>            if(o1.equals(o2)) {
>                return 0;
>            }
>            return 1;
>        }
> }
> This comparator regards null as the smallest object and TreeMap uses 
> this Comparator as a null-tolerable comparator.
> And this comparator is used to test the behavior of TreeMap.headMap() 
> when the input is null.
> Since null is recognized as smallest, the expected length of the 
> returned SortedMap of TreeMap.headMap(null) will be zero.
> My point here is that, under this situation, the MockComparator does 
> not care about the order of non-null objects, it just know
> null is always smaller. So, is it acceptable that - in this 
> comparator, compare method does not judge the order of all the 
> non-null objects?
> (does not comply with doc of comparator.compare)
What will happen when both o1 and o2 are null?

My understanding about mocked objects is that: we could only implement 
some necessary logic, but the logic must be compliant with the 
specification. Correct me if I'm wrong. Thanks a lot.

Best regards,
> Best regards

Richard Liang
China Software Development Lab, IBM 

Terms of use : http://incubator.apache.org/harmony/mailing.html
To unsubscribe, e-mail: harmony-dev-unsubscribe@incubator.apache.org
For additional commands, e-mail: harmony-dev-help@incubator.apache.org

View raw message