Streamlined hashcode. Added toString
This commit is contained in:
parent
98bec242eb
commit
0cdafb0804
|
@ -7,6 +7,7 @@ import java.util.Arrays;
|
||||||
*/
|
*/
|
||||||
public final class ByteArrayWrapper {
|
public final class ByteArrayWrapper {
|
||||||
private final byte[] data;
|
private final byte[] data;
|
||||||
|
private final int hashCode;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Makes a safe copy of the byte array, so that changes to the original do not affect the wrapper.
|
* Makes a safe copy of the byte array, so that changes to the original do not affect the wrapper.
|
||||||
|
@ -43,6 +44,7 @@ public final class ByteArrayWrapper {
|
||||||
} else {
|
} else {
|
||||||
this.data = data;
|
this.data = data;
|
||||||
}
|
}
|
||||||
|
this.hashCode = Arrays.hashCode(this.data);
|
||||||
}
|
}
|
||||||
|
|
||||||
public byte[] getBytes() {
|
public byte[] getBytes() {
|
||||||
|
@ -62,6 +64,11 @@ public final class ByteArrayWrapper {
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
// CANNOT be null, so we don't have to null check!
|
// CANNOT be null, so we don't have to null check!
|
||||||
return Arrays.hashCode(this.data);
|
return this.hashCode;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "ByteArrayWrapper [" + java.util.Arrays.toString(this.data) + "]";
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user