11package world .bentobox .bentobox .util ;
22
33
4- import org .eclipse .jdt .annotation .NonNull ;
5-
64/**
7- * Class to store pairs of objects, e.g. coordinates
5+ * Class to store pairs of objects, e.g. coordinates.
6+ * This could be done now as a record, but due to legacy code referencing it, it stays as a class.
7+ * @author tastybento
88 *
99 * @param <X> the x part of the pair
1010 * @param <Z> the z part of the pair
11- * @author tastybento
1211 */
13- public record Pair <X , Z >(X x , Z z ) {
12+ public class Pair <X , Z > {
13+ public final X x ;
14+ public final Z z ;
15+
1416 /**
1517 * Static factory method to create a Pair.
16- *
1718 * @param x the x part
1819 * @param z the z part
1920 * @return a new Pair containing x and z
@@ -22,10 +23,14 @@ public static <X, Z> Pair<X, Z> of(X x, Z z) {
2223 return new Pair <>(x , z );
2324 }
2425
26+ public Pair (X x , Z z ) {
27+ this .x = x ;
28+ this .z = z ;
29+ }
30+
2531
2632 /**
2733 * Returns X element as key.
28- *
2934 * @return X element
3035 */
3136 public X getKey () {
@@ -35,7 +40,6 @@ public X getKey() {
3540
3641 /**
3742 * Returns Z element as value.
38- *
3943 * @return Z element
4044 */
4145 public Z getValue () {
@@ -47,10 +51,22 @@ public Z getValue() {
4751 * @see java.lang.Object#toString()
4852 */
4953 @ Override
50- public @ NonNull String toString () {
54+ public String toString () {
5155 return "Pair [x=" + x + ", z=" + z + "]" ;
5256 }
5357
58+ /* (non-Javadoc)
59+ * @see java.lang.Object#hashCode()
60+ */
61+ @ Override
62+ public int hashCode () {
63+ final int prime = 31 ;
64+ int result = 1 ;
65+ result = prime * result + ((x == null ) ? 0 : x .hashCode ());
66+ result = prime * result + ((z == null ) ? 0 : z .hashCode ());
67+ return result ;
68+ }
69+
5470 /* (non-Javadoc)
5571 * @see java.lang.Object#equals(java.lang.Object)
5672 */
@@ -62,17 +78,27 @@ public boolean equals(Object obj) {
6278 if (obj == null ) {
6379 return false ;
6480 }
65- if (!(obj instanceof Pair <?, ?>( Object x1 , Object z1 ) )) {
81+ if (!(obj instanceof Pair <?, ?> other )) {
6682 return false ;
6783 }
6884 if (x == null ) {
69- return false ;
70- } else if (!x .equals (x1 )) {
85+ if (other .x != null ) {
86+ return false ;
87+ }
88+ } else if (!x .equals (other .x )) {
7189 return false ;
7290 }
7391 if (z == null ) {
74- return false ;
75- } else return z .equals (z1 );
92+ return other .z == null ;
93+ } else return z .equals (other .z );
94+ }
95+
96+ public X x () {
97+ return x ;
7698 }
7799
100+ public Z z () {
101+ return z ;
102+ }
103+
78104}
0 commit comments