File tree Expand file tree Collapse file tree 4 files changed +27
-8
lines changed
main/java/org/cloudburstmc/nbt
test/java/org/cloudburstmc/nbt Expand file tree Collapse file tree 4 files changed +27
-8
lines changed Original file line number Diff line number Diff line change @@ -69,9 +69,12 @@ public boolean equals(Object o) {
6969
7070 @ Override
7171 public int hashCode () {
72- if (this .hashCodeGenerated ) return this .hashCode ;
73- int result = Objects .hash (super .hashCode (), type );
74- result = 31 * result + Arrays .deepHashCode (array );
72+ if (this .hashCodeGenerated )
73+ return this .hashCode ;
74+ int result = type .hashCode ();
75+ for (Object object : array ) {
76+ result = 31 * result + NbtUtils .hashCode (object );
77+ }
7578 this .hashCode = result ;
7679 this .hashCodeGenerated = true ;
7780 return result ;
Original file line number Diff line number Diff line change @@ -408,12 +408,14 @@ public boolean equals(Object o) {
408408 public int hashCode () {
409409 if (this .hashCodeGenerated )
410410 return this .hashCode ;
411- int h = 0 ;
412- for (Entry <String , Object > stringObjectEntry : this .map .entrySet ())
413- h += stringObjectEntry .hashCode ();
414- this .hashCode = h ;
411+ int result = 1 ;
412+ for (Entry <String , Object > stringObjectEntry : this .map .entrySet ()) {
413+ result = 31 * result + (stringObjectEntry .getKey ().hashCode ()
414+ ^ NbtUtils .hashCode (stringObjectEntry .getValue ()));
415+ }
416+ this .hashCode = result ;
415417 this .hashCodeGenerated = true ;
416- return h ;
418+ return result ;
417419 }
418420
419421 @ Override
Original file line number Diff line number Diff line change @@ -183,6 +183,19 @@ public static String printHexBinary(byte[] data) {
183183 return r .toString ();
184184 }
185185
186+ public static int hashCode (Object object ) {
187+ if (object instanceof byte []) {
188+ return Arrays .hashCode ((byte []) object );
189+ }
190+ if (object instanceof int []) {
191+ return Arrays .hashCode ((int []) object );
192+ }
193+ if (object instanceof long []) {
194+ return Arrays .hashCode ((long []) object );
195+ }
196+ return object .hashCode ();
197+ }
198+
186199 /**
187200 * Write each {@link java.lang.reflect.RecordComponent RecordComponent} from record that be marked {@link NBT} to the specified nbtMap
188201 *
Original file line number Diff line number Diff line change @@ -105,6 +105,7 @@ void networkTest() {
105105 try (NBTInputStream in = NbtUtils .createNetworkReader (bais )) {
106106 Object o = in .readTag ();
107107 Assertions .assertEquals (TEST_MAP , o );
108+ Assertions .assertEquals (TEST_MAP .hashCode (), o .hashCode ());
108109 } catch (Exception e ) {
109110 throw new AssertionError ("Error whilst decoding tag" , e );
110111 }
You can’t perform that action at this time.
0 commit comments