ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/test/tck/Item.java
Revision: 1.1
Committed: Tue Jan 26 13:33:06 2021 UTC (3 years, 3 months ago) by dl
Branch: MAIN
Log Message:
Replace Integer with Item class

File Contents

# Content
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 // A simple element class for collections etc
8 import java.util.Comparator;
9 import java.io.Serializable;
10
11 public final class Item extends Number implements Comparable<Item>, Serializable {
12 public final int value;
13 public Item(int v) { value = v; }
14 public Item(Item i) { value = i.value; }
15 public Item(Integer i) { value = i.intValue(); }
16 public static Item valueOf(int i) { return new Item(i); }
17
18 public int intValue() { return value; }
19 public long longValue() { return (long)value; }
20 public float floatValue() { return (float)value; }
21 public double doubleValue() { return (double)value; }
22
23 public boolean equals(Object x) {
24 return (x instanceof Item) && ((Item)x).value == value;
25 }
26 public boolean equals(int b) {
27 return value == b;
28 }
29 public int compareTo(Item x) {
30 int a = value, b = x.value;
31 return (a == b) ? 0 : (a < b) ? -1 : 1;
32 }
33 public int compareTo(int b) {
34 int a = value;
35 return (a == b) ? 0 : (a < b) ? -1 : 1;
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;
43 }
44 public static int compare(Item x, int b) {
45 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;
54 }
55
56 public static Comparator<Item> comparator() { return new Cpr(); }
57 public static class Cpr implements Comparator<Item> {
58 public int compare(Item x, Item y) {
59 int a = x.value, b = y.value;
60 return (a == b) ? 0 : (a < b) ? -1 : 1;
61 }
62 }
63 }