1 |
dl |
1.1 |
/* |
2 |
|
|
* Written by Doug Lea with assistance from members of JCP JSR-166 |
3 |
|
|
* Expert Group and released to the public domain, as explained at |
4 |
|
|
* http://creativecommons.org/publicdomain/zero/1.0/ |
5 |
|
|
*/ |
6 |
|
|
|
7 |
|
|
import java.util.Comparator; |
8 |
|
|
import java.io.Serializable; |
9 |
|
|
|
10 |
jsr166 |
1.2 |
/** |
11 |
|
|
* A simple element class for collections etc |
12 |
|
|
*/ |
13 |
dl |
1.1 |
public final class Item extends Number implements Comparable<Item>, Serializable { |
14 |
|
|
public final int value; |
15 |
|
|
public Item(int v) { value = v; } |
16 |
|
|
public Item(Item i) { value = i.value; } |
17 |
|
|
public Item(Integer i) { value = i.intValue(); } |
18 |
|
|
public static Item valueOf(int i) { return new Item(i); } |
19 |
|
|
|
20 |
|
|
public int intValue() { return value; } |
21 |
|
|
public long longValue() { return (long)value; } |
22 |
|
|
public float floatValue() { return (float)value; } |
23 |
|
|
public double doubleValue() { return (double)value; } |
24 |
|
|
|
25 |
|
|
public boolean equals(Object x) { |
26 |
|
|
return (x instanceof Item) && ((Item)x).value == value; |
27 |
|
|
} |
28 |
|
|
public boolean equals(int b) { |
29 |
|
|
return value == b; |
30 |
|
|
} |
31 |
|
|
public int compareTo(Item x) { |
32 |
jsr166 |
1.3 |
return Integer.compare(this.value, x.value); |
33 |
dl |
1.1 |
} |
34 |
|
|
public int compareTo(int b) { |
35 |
jsr166 |
1.3 |
return Integer.compare(this.value, b); |
36 |
dl |
1.1 |
} |
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 |
jsr166 |
1.3 |
return Integer.compare(x.value, y.value); |
42 |
dl |
1.1 |
} |
43 |
|
|
public static int compare(Item x, int b) { |
44 |
jsr166 |
1.3 |
return Integer.compare(x.value, b); |
45 |
dl |
1.1 |
} |
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 |
jsr166 |
1.3 |
return Integer.compare(x.value, y.value); |
51 |
dl |
1.1 |
} |
52 |
|
|
} |
53 |
|
|
} |