ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/test/tck/Item.java
Revision: 1.3
Committed: Wed Jan 27 02:26:33 2021 UTC (3 years, 2 months ago) by jsr166
Branch: MAIN
CVS Tags: HEAD
Changes since 1.2: +5 -17 lines
Log Message:
use Integer.compare; delete public static int compare(int a, int b)

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 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; }
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 return Integer.compare(this.value, x.value);
33 }
34 public int compareTo(int b) {
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 return Integer.compare(x.value, y.value);
42 }
43 public static int compare(Item x, int b) {
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 return Integer.compare(x.value, y.value);
51 }
52 }
53 }