Skip to content

Commit 1d24f3a

Browse files
author
Yang Guo
committed
fix wrong ordered smaller number is on the top
1 parent 7c23df6 commit 1d24f3a

File tree

3 files changed

+8
-24
lines changed

3 files changed

+8
-24
lines changed

platform-core/src/main/java/com/flow/platform/core/queue/PriorityMessage.java

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
*/
2626
public class PriorityMessage extends Message implements PriorityQueueItem {
2727

28-
private long priority;
28+
private Long priority;
2929

3030
public static PriorityMessage create(byte[] content, long priority) {
3131
MessageProperties properties = new MessageProperties();
@@ -42,20 +42,12 @@ public PriorityMessage(byte[] body, MessageProperties messageProperties, long pr
4242
}
4343

4444
@Override
45-
public long getPriority() {
45+
public Long getPriority() {
4646
return this.priority;
4747
}
4848

4949
@Override
5050
public int compareTo(PriorityQueueItem o) {
51-
if (o.getPriority() > priority) {
52-
return -1;
53-
}
54-
55-
if (o.getPriority() < priority) {
56-
return 1;
57-
}
58-
59-
return 0;
51+
return o.getPriority().compareTo(getPriority());
6052
}
6153
}

platform-queue/src/main/java/com/flow/platform/queue/DefaultQueueMessage.java

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,15 @@ public class DefaultQueueMessage implements PriorityQueueItem {
2323

2424
private final byte[] body;
2525

26-
private long priority;
26+
private Long priority;
2727

28-
public DefaultQueueMessage(byte[] body, Integer priority) {
28+
public DefaultQueueMessage(byte[] body, Long priority) {
2929
this.body = body;
3030
this.priority = priority;
3131
}
3232

3333
@Override
34-
public long getPriority() {
34+
public Long getPriority() {
3535
return priority;
3636
}
3737

@@ -42,14 +42,6 @@ public byte[] getBody() {
4242

4343
@Override
4444
public int compareTo(PriorityQueueItem o) {
45-
if (o.getPriority() > priority) {
46-
return -1;
47-
}
48-
49-
if (o.getPriority() < priority) {
50-
return 1;
51-
}
52-
53-
return 0;
45+
return o.getPriority().compareTo(getPriority());
5446
}
5547
}

platform-queue/src/main/java/com/flow/platform/queue/PriorityQueueItem.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
*/
2222
public interface PriorityQueueItem extends Comparable<PriorityQueueItem> {
2323

24-
long getPriority();
24+
Long getPriority();
2525

2626
byte[] getBody();
2727
}

0 commit comments

Comments
 (0)