-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathContour.java
More file actions
121 lines (96 loc) · 2.21 KB
/
Copy pathContour.java
File metadata and controls
121 lines (96 loc) · 2.21 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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
package data;
import java.util.List;
import java.util.LinkedList;
import java.util.Iterator;
public class Contour implements Addr {
private List<Integer> list;
public Contour(){
list = new LinkedList<Integer>();
}
public Contour(Contour c){
list = new LinkedList<Integer>(c.list);
}
private List<Integer> getList(){
return list;
}
public void insertFront(Integer i){
list.add(0,i);
}
public void insertEnd(Integer i){
list.add(i);
}
public int hashCode(){
final int prime = 31;
int result = 1;
result = prime * result + ((list == null) ? 0 : list.hashCode());
return result;
}
public boolean equals(Object o){
if (this == o)
return true;
if (o == null)
return false;
if (getClass() != o.getClass())
return false;
Contour c = (Contour) o;
if ( list == null ){
if (c.getList() != null)
return false;
} else if (!list.equals(c.getList())){
return false;
}
return true;
}
public int compareTo(Addr addr) {
int classCompare = getClass().getName().compareTo(addr.getClass().getName());
if (classCompare != 0){
return classCompare;
}
Contour contour = (Contour) addr;
Iterator<Integer> l1 = list.iterator();
Iterator<Integer> l2 = contour.getList().iterator();
while( l1.hasNext() || l2.hasNext() ){
if(!l1.hasNext()) return -1;
if(!l2.hasNext()) return 1;
Integer ele1 = l1.next();
Integer ele2 = l2.next();
int res = ele1.compareTo(ele2);
if (res != 0){
return res;
}
}
return 0;
}
public Contour take(int k){
Contour newList = new Contour();
for(Integer i:list ){
k--;
newList.insertEnd(i);
if (k <= 0 ) break;
}
return newList;
}
public Contour tick(Integer ele, int k){
Contour newList = new Contour();
newList.list.addAll(list);
newList.insertFront(ele);
return newList.take(k);
}
public Boolean equals(Contour o){
return list.equals(o.list);
}
public String toString(){
return list.toString();
}
public static void main(String argv[]){
Contour con = new Contour();
Contour c1;
c1 = con.tick(45,1);
c1 = c1.tick(45,1);
c1 = c1.tick(45,1);
Contour t = new Contour(c1);
t.insertFront(1);
System.out.println(c1);
System.out.println(t);
}
}