Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 198308 Details for
Bug 317785
[repository] Synchronization problem in mirror selection
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
General comparator test
TestComparator.java (text/x-java-source), 2.34 KB, created by
Walter Laan
on 2011-06-21 03:42:23 EDT
(
hide
)
Description:
General comparator test
Filename:
MIME Type:
Creator:
Walter Laan
Created:
2011-06-21 03:42:23 EDT
Size:
2.34 KB
patch
obsolete
>import java.util.Arrays; >import java.util.Comparator; >import java.util.List; > >public class TestComparator { > public static void main(String[] args) { > List<String> abc = Arrays.asList("a", "b", "c"); > testComparator(String.CASE_INSENSITIVE_ORDER, abc, false); > testComparator(new Comparator<Object>() { > @Override > public int compare(Object o1, Object o2) { > return -1; > } > }, abc, false); > } > > public static <T> void testComparator(Comparator<? super T> comparator, > List<T> sample, boolean consistentWithEquals) { > > for(T x : sample) { > for(T y : sample) { > int xyResult = comparator.compare(x, y); > int yxResult = comparator.compare(y, x); > // sgn(compare(x, y)) == -sgn(compare(y, x)) for all x and y. > assert Math.signum(xyResult) == -Math.signum(yxResult) : > String.format("sgn(compare(%1$s, %2$s)) != -sgn(compare(%2$s, %1$s))", x, y); > > for(T z : sample) { > int xzResult = comparator.compare(x, z); > int yzResult = comparator.compare(y, z); > // ((compare(x, y)>0) && (compare(y, z)>0)) implies compare(x, z)>0. > if(xyResult > 0) { > if(yzResult > 0) { > assert xzResult > 0 : String.format( > "((compare(%1$s, %2$s)>0) && (compare(%2$s, %3$s)>0)) but not compare(%1$s, %3$s)>0", x, y, z); > } > } > else if(xyResult == 0) { > // compare(x, y)==0 implies that sgn(compare(x, z))==sgn(compare(y, z)) for all z. > assert Math.signum(xzResult) == Math.signum(yzResult) : String.format( > "compare(%1$s, %2$s)==0 but not that sgn(compare(%1$s, %3$s))==sgn(compare(%2$s, %3$s))", x, y, z); > } > } > > // Optionally (compare(x, y)==0) == (x.equals(y)) > if(consistentWithEquals && xyResult == 0) { > assert x.equals(y) : String.format( > "compare(%1$s, %2$s)==0) == (%1$s.equals(%2$s)", x, y); > } > } > } > } >}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Raw
Actions:
View
Attachments on
bug 317785
:
172622
|
198111
|
198147
|
198271
| 198308