mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-04-12 10:46:25 +00:00
refactor Pairs
This commit is contained in:
@@ -10,8 +10,6 @@ package com.dfsek.terra.api.handle;
|
||||
import com.dfsek.terra.api.block.entity.BlockEntity;
|
||||
import com.dfsek.terra.api.block.state.BlockState;
|
||||
import com.dfsek.terra.api.entity.EntityType;
|
||||
import com.dfsek.terra.api.entity.Player;
|
||||
import com.dfsek.terra.api.util.generic.pair.Pair;
|
||||
import com.dfsek.terra.api.util.vector.Vector3;
|
||||
|
||||
|
||||
|
||||
@@ -1,63 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2020-2021 Polyhedral Development
|
||||
*
|
||||
* The Terra API is licensed under the terms of the MIT License. For more details,
|
||||
* reference the LICENSE file in the common/api directory.
|
||||
*/
|
||||
|
||||
package com.dfsek.terra.api.util.generic.pair;
|
||||
|
||||
import org.jetbrains.annotations.Contract;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
|
||||
public final class ImmutablePair<L, R> {
|
||||
private static final ImmutablePair<?, ?> NULL = new ImmutablePair<>(null, null);
|
||||
private final L left;
|
||||
private final R right;
|
||||
|
||||
private ImmutablePair(L left, R right) {
|
||||
this.left = left;
|
||||
this.right = right;
|
||||
}
|
||||
|
||||
@Contract("_, _ -> new")
|
||||
public static <L1, R1> ImmutablePair<L1, R1> of(L1 left, R1 right) {
|
||||
return new ImmutablePair<>(left, right);
|
||||
}
|
||||
|
||||
@Contract("-> new")
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <L1, R1> ImmutablePair<L1, R1> ofNull() {
|
||||
return (ImmutablePair<L1, R1>) NULL;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Contract("-> new")
|
||||
public Pair<L, R> mutable() {
|
||||
return Pair.of(left, right);
|
||||
}
|
||||
|
||||
public R getRight() {
|
||||
return right;
|
||||
}
|
||||
|
||||
public L getLeft() {
|
||||
return left;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(left, right);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if(!(obj instanceof ImmutablePair)) return false;
|
||||
|
||||
ImmutablePair<?, ?> that = (ImmutablePair<?, ?>) obj;
|
||||
return Objects.equals(this.left, that.left) && Objects.equals(this.right, that.right);
|
||||
}
|
||||
}
|
||||
@@ -13,40 +13,39 @@ import org.jetbrains.annotations.NotNull;
|
||||
import java.util.Objects;
|
||||
|
||||
|
||||
public class Pair<L, R> {
|
||||
private L left;
|
||||
private R right;
|
||||
public final class Pair<L, R> {
|
||||
private static final Pair<?, ?> NULL = new Pair<>(null, null);
|
||||
private final L left;
|
||||
private final R right;
|
||||
|
||||
private Pair(L left, R right) {
|
||||
this.left = left;
|
||||
this.right = right;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Contract("_, _ -> new")
|
||||
public static <L1, R1> Pair<L1, R1> of(L1 left, R1 right) {
|
||||
return new Pair<>(left, right);
|
||||
}
|
||||
|
||||
@Contract("-> new")
|
||||
public ImmutablePair<L, R> immutable() {
|
||||
return ImmutablePair.of(left, right);
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <L1, R1> Pair<L1, R1> ofNull() {
|
||||
return (Pair<L1, R1>) NULL;
|
||||
}
|
||||
|
||||
public L getLeft() {
|
||||
return left;
|
||||
}
|
||||
|
||||
public void setLeft(L left) {
|
||||
this.left = left;
|
||||
@NotNull
|
||||
@Contract("-> new")
|
||||
public Pair.Mutable<L, R> mutable() {
|
||||
return Mutable.of(left, right);
|
||||
}
|
||||
|
||||
public R getRight() {
|
||||
return right;
|
||||
}
|
||||
|
||||
public void setRight(R right) {
|
||||
this.right = right;
|
||||
public L getLeft() {
|
||||
return left;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -56,9 +55,57 @@ public class Pair<L, R> {
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if(!(obj instanceof Pair)) return false;
|
||||
|
||||
Pair<?, ?> that = (Pair<?, ?>) obj;
|
||||
if(!(obj instanceof Pair<?, ?> that)) return false;
|
||||
|
||||
return Objects.equals(this.left, that.left) && Objects.equals(this.right, that.right);
|
||||
}
|
||||
|
||||
public static class Mutable<L, R> {
|
||||
private L left;
|
||||
private R right;
|
||||
|
||||
private Mutable(L left, R right) {
|
||||
this.left = left;
|
||||
this.right = right;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Contract("_, _ -> new")
|
||||
public static <L1, R1> Pair.Mutable<L1, R1> of(L1 left, R1 right) {
|
||||
return new Mutable<>(left, right);
|
||||
}
|
||||
|
||||
@Contract("-> new")
|
||||
public Pair<L, R> immutable() {
|
||||
return Pair.of(left, right);
|
||||
}
|
||||
|
||||
public L getLeft() {
|
||||
return left;
|
||||
}
|
||||
|
||||
public void setLeft(L left) {
|
||||
this.left = left;
|
||||
}
|
||||
|
||||
public R getRight() {
|
||||
return right;
|
||||
}
|
||||
|
||||
public void setRight(R right) {
|
||||
this.right = right;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(left, right);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if(!(obj instanceof Mutable<?, ?> that)) return false;
|
||||
|
||||
return Objects.equals(this.left, that.left) && Objects.equals(this.right, that.right);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user