Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Transform Topic and Subscription to be Comparable #595

Merged
merged 1 commit into from
May 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}
}