Use strings rather than hashes to identify transports. Dev task #64.

This commit is contained in:
akwizgran
2014-01-24 10:39:34 +00:00
parent 468db2a97b
commit 822392f9e7
26 changed files with 115 additions and 172 deletions

View File

@@ -1,21 +1,32 @@
package org.briarproject.api;
import java.util.Arrays;
import static org.briarproject.api.TransportPropertyConstants.MAX_TRANSPORT_ID_LENGTH;
/**
* Type-safe wrapper for a byte array that uniquely identifies a transport
* plugin.
* Type-safe wrapper for a string that uniquely identifies a transport plugin.
*/
public class TransportId extends UniqueId {
public class TransportId {
public TransportId(byte[] id) {
super(id);
private final String id;
public TransportId(String id) {
if(id.length() > MAX_TRANSPORT_ID_LENGTH || id.equals(""))
throw new IllegalArgumentException();
this.id = id;
}
public String getString() {
return id;
}
@Override
public boolean equals(Object o) {
if(o instanceof TransportId)
return Arrays.equals(id, ((TransportId) o).id);
if(o instanceof TransportId) return id.equals(((TransportId) o).id);
return false;
}
@Override
public int hashCode() {
return id.hashCode();
}
}