mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-12 18:59:06 +01:00
Use strings rather than hashes to identify transports. Dev task #64.
This commit is contained in:
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user