How I can find line 4,1 and 6 in example below?
And is the use of Collection.sort() with Comparator reasonable in this case?
a - b - c - d
1.) 6 8 16 18
2.) 38 40 55 57
3.) 6 8 25 27
4.) 1 5 11 15
5.) 6 8 3 5
6.) 9 12 19 22
7.) 18 20 1 3
8.) 23 25 15 17
Example on the top is a List with object meets following criteria:
- every object contains 4 integer(a,b,c,d),
- every object in the list is unique,
- a < b and c < d.
Below is not working example, but my way of thinking, how I can expect comparator to work for finding expected object.
public class Row_Filter implements Comparable<Row_Filter>{
int a,b,c,d;
public Row_Filter(int a, int b, int c, int d) {
this.a = a; this.b = b; this.c = c; this.d = d;
}
static class FilterAccordingAB implements Comparator<Row_Filter> {
public int compare(Row_Filter o1, Row_Filter o2) {
return o2.a - o1.b+1;
}
}
static class FilterAccordingCD implements Comparator<Row_Filter> {
public int compare(Row_Filter o1, Row_Filter o2) {
return o2.c - o1.d+1;
}
}
static class FilterAccordingABCD implements Comparator<Row_Filter> {
public int compare(Row_Filter o1, Row_Filter o2) {
FilterAccordingAB abF=null; FilterAccordingCD cdF=null;
if((abF.compare(o1, o2)==0) && (cdF.compare(o1, o2)==0)){
return 1;
}
return -1;
}
}
}