File tree Expand file tree Collapse file tree 3 files changed +36
-4
lines changed
src/main/java/at/favre/lib/bytes Expand file tree Collapse file tree 3 files changed +36
-4
lines changed Original file line number Diff line number Diff line change @@ -1880,8 +1880,7 @@ public boolean equalsContent(Bytes other) {
18801880 @ Override
18811881 public int hashCode () {
18821882 if (hashCodeCache == 0 ) {
1883- hashCodeCache = Arrays .hashCode (byteArray );
1884- hashCodeCache = 31 * hashCodeCache + (byteOrder != null ? byteOrder .hashCode () : 0 );
1883+ hashCodeCache = Util .hashCode (internalArray (), byteOrder ());
18851884 }
18861885 return hashCodeCache ;
18871886 }
Original file line number Diff line number Diff line change @@ -126,6 +126,11 @@ public MutableBytes secureWipe(SecureRandom random) {
126126 return this ;
127127 }
128128
129+ @ Override
130+ public int hashCode () {
131+ return Util .hashCode (internalArray (), byteOrder ());
132+ }
133+
129134 /**
130135 * Factory creating mutable byte types
131136 */
Original file line number Diff line number Diff line change 2121
2222package at .favre .lib .bytes ;
2323
24- import java .io .*;
24+ import java .io .ByteArrayOutputStream ;
25+ import java .io .DataInput ;
26+ import java .io .File ;
27+ import java .io .IOException ;
28+ import java .io .InputStream ;
2529import java .nio .ByteBuffer ;
30+ import java .nio .ByteOrder ;
2631import java .nio .file .Files ;
27- import java .util .*;
32+ import java .util .ArrayList ;
33+ import java .util .Arrays ;
34+ import java .util .Collection ;
35+ import java .util .HashMap ;
36+ import java .util .Iterator ;
37+ import java .util .List ;
38+ import java .util .Map ;
39+ import java .util .NoSuchElementException ;
40+ import java .util .Objects ;
41+ import java .util .Random ;
42+ import java .util .UUID ;
2843
2944/**
3045 * Common Util methods to convert or modify byte arrays
@@ -489,6 +504,19 @@ static ByteBuffer getBytesFromUUID(UUID uuid) {
489504 return bb ;
490505 }
491506
507+ /**
508+ * Hashcode implementation for a byte array and given byte order
509+ *
510+ * @param byteArray
511+ * @param byteOrder
512+ * @return hashCode
513+ */
514+ static int hashCode (byte [] byteArray , ByteOrder byteOrder ) {
515+ int result = Arrays .hashCode (byteArray );
516+ result = 31 * result + (byteOrder != null ? byteOrder .hashCode () : 0 );
517+ return result ;
518+ }
519+
492520 /*
493521 =================================================================================================
494522 Copyright 2011 Twitter, Inc.
You can’t perform that action at this time.
0 commit comments