Skip to content

Commit

Permalink
Transform Topic and Subscription to be Comparable (#595)
Browse files Browse the repository at this point in the history
  • Loading branch information
andsel authored May 2, 2021
1 parent c94b6c3 commit e56c403
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
/**
* Maintain the information about which Topic a certain ClientID is subscribed and at which QoS
*/
public final class Subscription implements Serializable {
public final class Subscription implements Serializable, Comparable<Subscription> {

private static final long serialVersionUID = -3383457629635732794L;
private final MqttQoS requestedQos; // max QoS acceptable
Expand Down Expand Up @@ -92,4 +92,13 @@ public Subscription clone() {
return null;
}
}

@Override
public int compareTo(Subscription o) {
int compare = this.clientId.compareTo(o.clientId);
if (compare != 0) {
return compare;
}
return this.topicFilter.compareTo(o.topicFilter);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class Topic implements Serializable {
public class Topic implements Serializable, Comparable<Topic> {

private static final Logger LOG = LoggerFactory.getLogger(Topic.class);

Expand Down Expand Up @@ -215,4 +215,8 @@ public int hashCode() {
return topic.hashCode();
}

@Override
public int compareTo(Topic o) {
return topic.compareTo(o.topic);
}
}

0 comments on commit e56c403

Please sign in to comment.