-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathItem.java
More file actions
40 lines (32 loc) · 1002 Bytes
/
Item.java
File metadata and controls
40 lines (32 loc) · 1002 Bytes
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
package treeSet;
import java.util.Objects;
public class Item implements Comparable<Item>{
private String description;
private int partNumber;
public Item(String description,int partNumber){
this.description=description;
this.partNumber=partNumber;
}
public String getDescription(){
return this.description;
}
public String toString(){
return "[description="+description+", partNumber="+partNumber+"]";
}
//equals·½·¨---------------------------------------------------
public boolean equals(Object otherObject){
if(this==otherObject) return true;
if(otherObject==null) return false;
if(getClass()!=otherObject.getClass()) return false;
Item other=(Item) otherObject;
return Objects.equals(description,other.description)&&partNumber==other.partNumber;
}
public int hashCode(){
//ObjectsÀàÉú³ÉhashCode
return Objects.hash(description,partNumber);
}
@Override
public int compareTo(Item other) {
return Integer.compare(partNumber, other.partNumber);
}
}