-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathItem.java
More file actions
88 lines (80 loc) · 1.96 KB
/
Item.java
File metadata and controls
88 lines (80 loc) · 1.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/**
* The Item class is designed to be used by Swing components that use a
* renderer to display an Object. Swing renderers rely on the toString()
* implementation to display a description of an Object. Separating
* the value and description properties gives increased flexibilty.
*
* The "description" property is used by the renderer. The "value"
* property is used for processing by the application.
*/
public class Item<V> implements Comparable<Item>
{
private V value;
private String description;
/**
* Create an Item object
*
* @param value an Object containing data used by the application
* @param description the text to be displayed by a renderer
*/
public Item(V value, String description)
{
this.value = value;
this.description = description;
}
/**
* Get the Object containing application data
*
* @returns the application data
*/
public V getValue()
{
return value;
}
/**
* Get the description of the value data
*
* @returns the description to be displayed by a renderer
*/
public String getDescription()
{
return description;
}
/**
* Implement the natural order for this class using the
* Description property
*
* @param item the other Item object to be used in the comparison
*/
public int compareTo(Item item)
{
return getDescription().compareTo(item.getDescription());
}
/**
* The Value property will be used to check for equality
*/
@Override
public boolean equals(Object object)
{
Item item = (Item)object;
return (item == null) ? false : value.equals(item.getValue());
}
/**
* The Value property will be used to determine the hashCode
*/
@Override
public int hashCode()
{
return value.hashCode();
}
/**
* The Description property will double as the toString representation.
*
* @return the description
*/
@Override
public String toString()
{
return description;
}
}