Changed Subscription equals to use also cleanSession flag in equality check

This commit is contained in:
andrea
2015-06-28 16:26:10 +02:00
parent 5416a87149
commit b8af814940
4 changed files with 54 additions and 26 deletions
@@ -72,33 +72,27 @@ public class Subscription implements Serializable {
}
@Override
public boolean equals(Object obj) {
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
final Subscription other = (Subscription) obj;
if (this.requestedQos != other.requestedQos) {
return false;
}
if ((this.clientId == null) ? (other.clientId != null) : !this.clientId.equals(other.clientId)) {
return false;
}
if ((this.topicFilter == null) ? (other.topicFilter != null) : !this.topicFilter.equals(other.topicFilter)) {
return false;
}
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Subscription that = (Subscription) o;
if (cleanSession != that.cleanSession) return false;
if (clientId != null ? !clientId.equals(that.clientId) : that.clientId != null) return false;
if (requestedQos != that.requestedQos) return false;
if (topicFilter != null ? !topicFilter.equals(that.topicFilter) : that.topicFilter != null) return false;
return true;
}
@Override
public int hashCode() {
int hash = 3;
hash = 37 * hash + (this.requestedQos != null ? this.requestedQos.hashCode() : 0);
hash = 37 * hash + (this.clientId != null ? this.clientId.hashCode() : 0);
hash = 37 * hash + (this.topicFilter != null ? this.topicFilter.hashCode() : 0);
return hash;
int result = requestedQos.hashCode();
result = 31 * result + (clientId != null ? clientId.hashCode() : 0);
result = 31 * result + (topicFilter != null ? topicFilter.hashCode() : 0);
result = 31 * result + (cleanSession ? 1 : 0);
return result;
}
/**
@@ -113,7 +113,7 @@ class TreeNode {
if (n.getToken().match(t)) {
//Create a copy of token, else if navigate 2 sibling it
//consumes 2 elements on the queue instead of one
n.matches(new LinkedBlockingQueue<Token>(tokens), matchingSubs);
n.matches(new LinkedBlockingQueue<>(tokens), matchingSubs);
//TODO don't create a copy n.matches(tokens, matchingSubs);
}
}
@@ -132,7 +132,7 @@ class TreeNode {
void removeClientSubscriptions(String clientID) {
//collect what to delete and then delete to avoid ConcurrentModification
List<Subscription> subsToRemove = new ArrayList<Subscription>();
List<Subscription> subsToRemove = new ArrayList<>();
for (Subscription s : m_subscriptions) {
if (s.clientId.equals(clientID)) {
subsToRemove.add(s);
@@ -185,7 +185,7 @@ class TreeNode {
* @return the set of subscriptions for the given client.
* */
Set<Subscription> findAllByClientID(String clientID) {
Set<Subscription> subs = new HashSet<Subscription>();
Set<Subscription> subs = new HashSet<>();
for (Subscription s : m_subscriptions) {
if (s.clientId.equals(clientID)) {
subs.add(s);