Skip to content

Commit a6f8ee7

Browse files
Moved compareTo to CprSimple
1 parent 8a9c522 commit a6f8ee7

File tree

2 files changed

+11
-10
lines changed

2 files changed

+11
-10
lines changed

src/Tests/Test_CFixedMinHeap.java

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ public void returnOrderedItems() {
166166
}
167167
}
168168

169-
class CItem extends CprSimple<String> implements Comparable<CItem> {
169+
class CItem extends CprSimple<String> {
170170
public CItem(String value, int priority) {
171171
super(value, priority);
172172
}
@@ -179,12 +179,4 @@ public void setPriority(int i) {
179179
public String toString() {
180180
return value.toString() + " " + Priority();
181181
}
182-
183-
@Override
184-
public int compareTo(CItem o) {
185-
final int diff = o._priority - _priority;
186-
if (0 != diff)
187-
return diff;
188-
return o.value.compareTo(value);
189-
}
190182
}

src/YASL/Collectors/Heap/CprSimple.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package YASL.Collectors.Heap;
22

3-
public class CprSimple<T> implements IPrioritizedItem<T> {
3+
public class CprSimple<T> implements IPrioritizedItem<T>, Comparable<CprSimple<T>> {
44
public final T value;
55
protected int _priority;
66

@@ -18,4 +18,13 @@ public int Priority() {
1818
public T Value() {
1919
return value;
2020
}
21+
22+
@SuppressWarnings("unchecked")
23+
@Override
24+
public int compareTo(CprSimple<T> o) {
25+
final int diff = o._priority - _priority;
26+
if (0 != diff)
27+
return diff;
28+
return ((Comparable<T>) o.value).compareTo(value);
29+
}
2130
}

0 commit comments

Comments
 (0)