mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-13 03:09:04 +01:00
Equals method must be symmetric and transitive.
This commit is contained in:
@@ -16,14 +16,14 @@ public class ContactId {
|
||||
return id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if(o instanceof ContactId) return id == ((ContactId) o).id;
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return id;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,37 +3,40 @@ package net.sf.briar.api.protocol;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
|
||||
public class Transport extends TreeMap<String, String> {
|
||||
|
||||
private static final long serialVersionUID = 4900420175715429560L;
|
||||
public class Transport {
|
||||
|
||||
private final TransportId id;
|
||||
private final TreeMap<String, String> properties;
|
||||
|
||||
public Transport(TransportId id, Map<String, String> p) {
|
||||
super(p);
|
||||
this.id = id;
|
||||
properties = new TreeMap<String, String>(p);
|
||||
}
|
||||
|
||||
public Transport(TransportId id) {
|
||||
super();
|
||||
this.id = id;
|
||||
properties = new TreeMap<String, String>();
|
||||
}
|
||||
|
||||
public TransportId getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return id.hashCode();
|
||||
public Map<String, String> getProperties() {
|
||||
return properties;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if(o instanceof Transport) {
|
||||
Transport t = (Transport) o;
|
||||
return id.equals(t.id) && super.equals(o);
|
||||
return id.equals(t.id) && properties.equals(t.properties);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return id.hashCode();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1207,7 +1207,7 @@ abstract class JdbcDatabase implements Database<Connection> {
|
||||
t = new Transport(id);
|
||||
transports.add(t);
|
||||
}
|
||||
t.put(rs.getString(2), rs.getString(3));
|
||||
t.getProperties().put(rs.getString(2), rs.getString(3));
|
||||
lastId = id;
|
||||
}
|
||||
rs.close();
|
||||
@@ -2763,7 +2763,7 @@ abstract class JdbcDatabase implements Database<Connection> {
|
||||
int batchSize = 0;
|
||||
for(Transport t : transports) {
|
||||
ps.setBytes(2, t.getId().getBytes());
|
||||
for(Entry<String, String> e1 : t.entrySet()) {
|
||||
for(Entry<String, String> e1 : t.getProperties().entrySet()) {
|
||||
ps.setString(3, e1.getKey());
|
||||
ps.setString(4, e1.getValue());
|
||||
ps.addBatch();
|
||||
|
||||
@@ -27,13 +27,13 @@ class GroupImpl implements Group {
|
||||
return publicKey;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
return o instanceof Group && id.equals(((Group) o).getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return id.hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
return o instanceof Group && id.equals(((Group) o).getId());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -71,13 +71,13 @@ class MessageImpl implements Message {
|
||||
return bodyLength;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
return o instanceof Message && id.equals(((Message) o).getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return id.hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
return o instanceof Message && id.equals(((Message) o).getId());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -148,7 +148,7 @@ class ProtocolWriterImpl implements ProtocolWriter {
|
||||
for(Transport p : t.getTransports()) {
|
||||
w.writeStructId(Types.TRANSPORT);
|
||||
w.writeBytes(p.getId().getBytes());
|
||||
w.writeMap(p);
|
||||
w.writeMap(p.getProperties());
|
||||
}
|
||||
w.writeListEnd();
|
||||
w.writeInt64(t.getTimestamp());
|
||||
|
||||
@@ -77,13 +77,13 @@ class TestMessage implements Message {
|
||||
return new ByteArrayInputStream(raw);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
return o instanceof Message && id.equals(((Message)o).getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return id.hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
return o instanceof Message && id.equals(((Message)o).getId());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@ import java.security.PrivateKey;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
|
||||
import net.sf.briar.BriarTestCase;
|
||||
import net.sf.briar.TestUtils;
|
||||
@@ -158,10 +159,11 @@ public class ConstantsTest extends BriarTestCase {
|
||||
for(int i = 0; i < MAX_TRANSPORTS; i++) {
|
||||
TransportId id = new TransportId(TestUtils.getRandomId());
|
||||
Transport t = new Transport(id);
|
||||
Map<String, String> m = t.getProperties();
|
||||
for(int j = 0; j < MAX_PROPERTIES_PER_TRANSPORT; j++) {
|
||||
String key = createRandomString(MAX_PROPERTY_LENGTH);
|
||||
String value = createRandomString(MAX_PROPERTY_LENGTH);
|
||||
t.put(key, value);
|
||||
m.put(key, value);
|
||||
}
|
||||
transports.add(t);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user