4 |
|
* http://creativecommons.org/publicdomain/zero/1.0/ |
5 |
|
*/ |
6 |
|
|
7 |
– |
// A simple element class for collections etc |
7 |
|
import java.util.Comparator; |
8 |
|
import java.io.Serializable; |
9 |
|
|
10 |
+ |
/** |
11 |
+ |
* A simple element class for collections etc |
12 |
+ |
*/ |
13 |
|
public final class Item extends Number implements Comparable<Item>, Serializable { |
14 |
|
public final int value; |
15 |
|
public Item(int v) { value = v; } |
29 |
|
return value == b; |
30 |
|
} |
31 |
|
public int compareTo(Item x) { |
32 |
< |
int a = value, b = x.value; |
31 |
< |
return (a == b) ? 0 : (a < b) ? -1 : 1; |
32 |
> |
return Integer.compare(this.value, x.value); |
33 |
|
} |
34 |
|
public int compareTo(int b) { |
35 |
< |
int a = value; |
35 |
< |
return (a == b) ? 0 : (a < b) ? -1 : 1; |
35 |
> |
return Integer.compare(this.value, b); |
36 |
|
} |
37 |
|
|
38 |
|
public int hashCode() { return value; } |
39 |
|
public String toString() { return Integer.toString(value); } |
40 |
|
public static int compare(Item x, Item y) { |
41 |
< |
int a = x.value, b = y.value; |
42 |
< |
return (a == b) ? 0 : (a < b) ? -1 : 1; |
41 |
> |
return Integer.compare(x.value, y.value); |
42 |
|
} |
43 |
|
public static int compare(Item x, int b) { |
44 |
< |
int a = x.value; |
46 |
< |
return (a == b) ? 0 : (a < b) ? -1 : 1; |
47 |
< |
} |
48 |
< |
public static int compare(int a, Item y) { |
49 |
< |
int b = y.value; |
50 |
< |
return (a == b) ? 0 : (a < b) ? -1 : 1; |
51 |
< |
} |
52 |
< |
public static int compare(int a, int b) { |
53 |
< |
return (a == b) ? 0 : (a < b) ? -1 : 1; |
44 |
> |
return Integer.compare(x.value, b); |
45 |
|
} |
46 |
|
|
47 |
|
public static Comparator<Item> comparator() { return new Cpr(); } |
48 |
|
public static class Cpr implements Comparator<Item> { |
49 |
|
public int compare(Item x, Item y) { |
50 |
< |
int a = x.value, b = y.value; |
60 |
< |
return (a == b) ? 0 : (a < b) ? -1 : 1; |
50 |
> |
return Integer.compare(x.value, y.value); |
51 |
|
} |
52 |
|
} |
53 |
|
} |