mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-12 18:59:06 +01:00
Changed the root package from net.sf.briar to org.briarproject.
This commit is contained in:
34
briar-api/src/org/briarproject/api/Bytes.java
Normal file
34
briar-api/src/org/briarproject/api/Bytes.java
Normal file
@@ -0,0 +1,34 @@
|
||||
package org.briarproject.api;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
/** A wrapper around a byte array, to allow it to be stored in maps etc. */
|
||||
public class Bytes {
|
||||
|
||||
private final byte[] bytes;
|
||||
|
||||
private int hashCode = -1;
|
||||
|
||||
public Bytes(byte[] bytes) {
|
||||
this.bytes = bytes;
|
||||
}
|
||||
|
||||
public byte[] getBytes() {
|
||||
return bytes;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
// Thread-safe because if two or more threads check and update the
|
||||
// value, they'll calculate the same value
|
||||
if(hashCode == -1) hashCode = Arrays.hashCode(bytes);
|
||||
return hashCode;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if(o instanceof Bytes)
|
||||
return Arrays.equals(bytes, ((Bytes) o).bytes);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user