From fde66a1bd7eccf1978f32c2f19c2a2eb3338c333 Mon Sep 17 00:00:00 2001 From: Hendrix-Shen Date: Sat, 8 Jun 2024 23:39:03 +0800 Subject: [PATCH] Use commons-lang3 Signed-off-by: Hendrix-Shen --- magiclib-core/build.gradle | 1 + .../util/collect/tuple/ImmutablePair.java | 72 ---------------- .../util/collect/tuple/ImmutableTriple.java | 56 ------------- .../util/collect/tuple/MutablePair.java | 83 ------------------- .../util/collect/tuple/MutableTriple.java | 71 ---------------- .../magiclib/util/collect/tuple/Pair.java | 53 ------------ .../magiclib/util/collect/tuple/Triple.java | 51 ------------ .../magiclib/util/mixin/MixinInternals.java | 4 +- magiclib-core/gradle.properties | 1 + 9 files changed, 4 insertions(+), 388 deletions(-) delete mode 100644 magiclib-core/common/src/main/java/top/hendrixshen/magiclib/util/collect/tuple/ImmutablePair.java delete mode 100644 magiclib-core/common/src/main/java/top/hendrixshen/magiclib/util/collect/tuple/ImmutableTriple.java delete mode 100644 magiclib-core/common/src/main/java/top/hendrixshen/magiclib/util/collect/tuple/MutablePair.java delete mode 100644 magiclib-core/common/src/main/java/top/hendrixshen/magiclib/util/collect/tuple/MutableTriple.java delete mode 100644 magiclib-core/common/src/main/java/top/hendrixshen/magiclib/util/collect/tuple/Pair.java delete mode 100644 magiclib-core/common/src/main/java/top/hendrixshen/magiclib/util/collect/tuple/Triple.java diff --git a/magiclib-core/build.gradle b/magiclib-core/build.gradle index 27e4254e..3e8c63cb 100644 --- a/magiclib-core/build.gradle +++ b/magiclib-core/build.gradle @@ -64,6 +64,7 @@ subprojects { annotationProcessor("org.projectlombok:lombok:${project.property("dependencies.lombok_version")}") // Other + compileOnly("org.apache.commons:commons-lang3:${project.property("dependencies.apache_common_lang3_version")}") compileOnly("com.google.code.gson:gson:${project.property("dependencies.gson_version")}") compileOnly("com.google.guava:guava:${project.property("dependencies.guava_version")}") compileOnly("org.jetbrains:annotations:${project.property("dependencies.jetbrains_annotations_version")}") diff --git a/magiclib-core/common/src/main/java/top/hendrixshen/magiclib/util/collect/tuple/ImmutablePair.java b/magiclib-core/common/src/main/java/top/hendrixshen/magiclib/util/collect/tuple/ImmutablePair.java deleted file mode 100644 index 672d2b19..00000000 --- a/magiclib-core/common/src/main/java/top/hendrixshen/magiclib/util/collect/tuple/ImmutablePair.java +++ /dev/null @@ -1,72 +0,0 @@ -package top.hendrixshen.magiclib.util.collect.tuple; - -import org.jetbrains.annotations.Contract; -import org.jetbrains.annotations.NotNull; - -import java.util.Map; -import java.util.Objects; - -public class ImmutablePair extends Pair { - private static final ImmutablePair[] EMPTY_ARRAY = {}; - @SuppressWarnings("rawtypes") - private static final ImmutablePair NULL = new ImmutablePair<>(null, null); - - private final L left; - private final R right; - - @Contract("_, _ -> new") - public static @NotNull Pair of(L left, R right) { - return new ImmutablePair<>(Objects.requireNonNull(left, "left"), - Objects.requireNonNull(right, "right")); - } - - @Contract("_ -> new") - public static @NotNull Pair of(Map.Entry pair) { - return pair == null ? ImmutablePair.nullPair() : new ImmutablePair<>(pair.getKey(), pair.getValue()); - } - - @Contract("_, _ -> new") - public static @NotNull Pair ofNullable(L left, R right) { - return new ImmutablePair<>(left, right); - } - - @Contract("_ -> new") - public static @NotNull Pair left(L left) { - return ImmutablePair.ofNullable(left, null); - } - - public static @NotNull Pair right(R right) { - return ImmutablePair.ofNullable(null, right); - } - - @SuppressWarnings("unchecked") - public static ImmutablePair[] emptyArray() { - return (ImmutablePair[]) ImmutablePair.EMPTY_ARRAY; - } - - @SuppressWarnings("unchecked") - public static ImmutablePair nullPair() { - return ImmutablePair.NULL; - } - - public ImmutablePair(L left, R right) { - super(); - this.left = left; - this.right = right; - } - - @Override - public L getLeft() { - return this.left; - } - - @Override - public R getRight() { - return this.right; - } - - @Override - public R setValue(R value) { - throw new UnsupportedOperationException(); - } -} diff --git a/magiclib-core/common/src/main/java/top/hendrixshen/magiclib/util/collect/tuple/ImmutableTriple.java b/magiclib-core/common/src/main/java/top/hendrixshen/magiclib/util/collect/tuple/ImmutableTriple.java deleted file mode 100644 index 71fcfcd9..00000000 --- a/magiclib-core/common/src/main/java/top/hendrixshen/magiclib/util/collect/tuple/ImmutableTriple.java +++ /dev/null @@ -1,56 +0,0 @@ -package top.hendrixshen.magiclib.util.collect.tuple; - -import org.jetbrains.annotations.NotNull; - -import java.util.Objects; - -public class ImmutableTriple extends Triple { - private static final ImmutableTriple[] EMPTY_ARRAY = {}; - @SuppressWarnings("rawtypes") - private static final ImmutableTriple NULL = new ImmutableTriple<>(null, null, null); - - private final L left; - private final M middle; - private final R right; - - public static @NotNull ImmutableTriple of(L left, M middle, R right) { - return new ImmutableTriple<>(Objects.requireNonNull(left, "left"), - Objects.requireNonNull(middle, "middle"), - Objects.requireNonNull(right, "right")); - } - - public static @NotNull ImmutableTriple ofNullable(L left, M middle, R right) { - return new ImmutableTriple<>(left, middle, right); - } - - @SuppressWarnings("unchecked") - public static ImmutableTriple[] emptyArray() { - return (ImmutableTriple[]) ImmutableTriple.EMPTY_ARRAY; - } - - @SuppressWarnings("unchecked") - public static ImmutableTriple nullPair() { - return ImmutableTriple.NULL; - } - - private ImmutableTriple(L left, M middle, R right) { - this.left = left; - this.middle = middle; - this.right = right; - } - - @Override - public L getLeft() { - return this.left; - } - - @Override - public M getMiddle() { - return this.middle; - } - - @Override - public R getRight() { - return this.right; - } -} diff --git a/magiclib-core/common/src/main/java/top/hendrixshen/magiclib/util/collect/tuple/MutablePair.java b/magiclib-core/common/src/main/java/top/hendrixshen/magiclib/util/collect/tuple/MutablePair.java deleted file mode 100644 index a5070968..00000000 --- a/magiclib-core/common/src/main/java/top/hendrixshen/magiclib/util/collect/tuple/MutablePair.java +++ /dev/null @@ -1,83 +0,0 @@ -package top.hendrixshen.magiclib.util.collect.tuple; - -import org.jetbrains.annotations.Contract; -import org.jetbrains.annotations.NotNull; - -import java.util.Map; -import java.util.Objects; - -public class MutablePair extends Pair { - private static final MutablePair[] EMPTY_ARRAY = {}; - @SuppressWarnings("rawtypes") - private static final MutablePair NULL = new MutablePair<>(null, null); - - private L left; - private R right; - - @Contract("_, _ -> new") - public static @NotNull Pair of(L left, R right) { - return new MutablePair<>(Objects.requireNonNull(left), Objects.requireNonNull(right)); - } - - @Contract("_ -> new") - public static @NotNull Pair of(Map.Entry pair) { - return pair == null ? MutablePair.nullPair() : new MutablePair<>(pair.getKey(), pair.getValue()); - } - - @Contract("_, _ -> new") - public static @NotNull Pair ofNullable(L left, R right) { - return new MutablePair<>(left, right); - } - - @Contract("_ -> new") - public static @NotNull Pair left(L left) { - return MutablePair.ofNullable(left, null); - } - - public static @NotNull Pair right(R right) { - return MutablePair.ofNullable(null, right); - } - - @SuppressWarnings("unchecked") - public static MutablePair[] emptyArray() { - return (MutablePair[]) MutablePair.EMPTY_ARRAY; - } - - @SuppressWarnings("unchecked") - public static MutablePair nullPair() { - return MutablePair.NULL; - } - - public MutablePair(L left, R right) { - super(); - this.left = left; - this.right = right; - } - - @Override - public L getLeft() { - return this.left; - } - - @Override - public R getRight() { - return this.right; - } - - @Override - public void setLeft(L left) { - this.left = left; - } - - @Override - public void setRight(R right) { - this.right = right; - } - - @Override - public R setValue(R value) { - R result = this.getRight(); - this.setRight(value); - return result; - } -} diff --git a/magiclib-core/common/src/main/java/top/hendrixshen/magiclib/util/collect/tuple/MutableTriple.java b/magiclib-core/common/src/main/java/top/hendrixshen/magiclib/util/collect/tuple/MutableTriple.java deleted file mode 100644 index 3b7e787d..00000000 --- a/magiclib-core/common/src/main/java/top/hendrixshen/magiclib/util/collect/tuple/MutableTriple.java +++ /dev/null @@ -1,71 +0,0 @@ -package top.hendrixshen.magiclib.util.collect.tuple; - -import org.jetbrains.annotations.NotNull; - -import java.util.Objects; - -public class MutableTriple extends Triple { - private static final MutableTriple[] EMPTY_ARRAY = {}; - @SuppressWarnings("rawtypes") - private static final MutableTriple NULL = new MutableTriple<>(null, null, null); - - private L left; - private M middle; - private R right; - - public static @NotNull MutableTriple of(L left, M middle, R right) { - return new MutableTriple<>(Objects.requireNonNull(left, "left"), - Objects.requireNonNull(middle, "middle"), - Objects.requireNonNull(right, "right")); - } - - public static @NotNull MutableTriple ofNullable(L left, M middle, R right) { - return new MutableTriple<>(left, middle, right); - } - - @SuppressWarnings("unchecked") - public static MutableTriple[] emptyArray() { - return (MutableTriple[]) MutableTriple.EMPTY_ARRAY; - } - - @SuppressWarnings("unchecked") - public static MutableTriple nullPair() { - return MutableTriple.NULL; - } - - private MutableTriple(L left, M middle, R right) { - this.left = left; - this.middle = middle; - this.right = right; - } - - @Override - public L getLeft() { - return this.left; - } - - @Override - public M getMiddle() { - return this.middle; - } - - @Override - public R getRight() { - return this.right; - } - - @Override - public void setLeft(L left) { - this.left = left; - } - - @Override - public void setMiddle(M middle) { - this.middle = middle; - } - - @Override - public void setRight(R right) { - this.right = right; - } -} diff --git a/magiclib-core/common/src/main/java/top/hendrixshen/magiclib/util/collect/tuple/Pair.java b/magiclib-core/common/src/main/java/top/hendrixshen/magiclib/util/collect/tuple/Pair.java deleted file mode 100644 index 446d7be9..00000000 --- a/magiclib-core/common/src/main/java/top/hendrixshen/magiclib/util/collect/tuple/Pair.java +++ /dev/null @@ -1,53 +0,0 @@ -package top.hendrixshen.magiclib.util.collect.tuple; - -import java.util.Map; -import java.util.Objects; - -public abstract class Pair implements Map.Entry { - public abstract L getLeft(); - - public abstract R getRight(); - - public void setLeft(L left) { - throw new UnsupportedOperationException(); - } - - public void setRight(R right) { - throw new UnsupportedOperationException(); - } - - @Override - public L getKey() { - return this.getLeft(); - } - - @Override - public R getValue() { - return this.getRight(); - } - - @Override - public int hashCode() { - return Objects.hashCode(this.getLeft()) ^ - Objects.hashCode(this.getRight()); - } - - @Override - public boolean equals(Object o) { - if (o == this) { - return true; - } - - if (o instanceof Map.Entry) { - Map.Entry other = (Map.Entry) o; - return Objects.equals(this.getKey(), other.getKey()) && Objects.equals(this.getValue(), other.getValue()); - } - - return false; - } - - @Override - public String toString() { - return "(" + this.getLeft() + ',' + this.getRight() + ')'; - } -} diff --git a/magiclib-core/common/src/main/java/top/hendrixshen/magiclib/util/collect/tuple/Triple.java b/magiclib-core/common/src/main/java/top/hendrixshen/magiclib/util/collect/tuple/Triple.java deleted file mode 100644 index f7573da2..00000000 --- a/magiclib-core/common/src/main/java/top/hendrixshen/magiclib/util/collect/tuple/Triple.java +++ /dev/null @@ -1,51 +0,0 @@ -package top.hendrixshen.magiclib.util.collect.tuple; - -import java.util.Objects; - -public abstract class Triple { - public abstract L getLeft(); - - public abstract M getMiddle(); - - public abstract R getRight(); - - public void setLeft(L left) { - throw new UnsupportedOperationException(); - } - - public void setMiddle(M middle) { - throw new UnsupportedOperationException(); - } - - public void setRight(R right) { - throw new UnsupportedOperationException(); - } - - @Override - public int hashCode() { - return Objects.hashCode(this.getLeft()) ^ - Objects.hashCode(this.getMiddle()) ^ - Objects.hashCode(this.getRight()); - } - - @Override - public boolean equals(Object obj) { - if (obj == this) { - return true; - } - - if (obj instanceof Triple) { - final Triple other = (Triple) obj; - return Objects.equals(this.getLeft(), other.getLeft()) - && Objects.equals(this.getMiddle(), other.getMiddle()) - && Objects.equals(this.getRight(), other.getRight()); - } - - return false; - } - - @Override - public String toString() { - return "(" + this.getLeft() + ',' + this.getMiddle() + ',' + this.getRight() + ')'; - } -} diff --git a/magiclib-core/common/src/main/java/top/hendrixshen/magiclib/util/mixin/MixinInternals.java b/magiclib-core/common/src/main/java/top/hendrixshen/magiclib/util/mixin/MixinInternals.java index f13be668..28489918 100644 --- a/magiclib-core/common/src/main/java/top/hendrixshen/magiclib/util/mixin/MixinInternals.java +++ b/magiclib-core/common/src/main/java/top/hendrixshen/magiclib/util/mixin/MixinInternals.java @@ -1,5 +1,7 @@ package top.hendrixshen.magiclib.util.mixin; +import org.apache.commons.lang3.tuple.ImmutablePair; +import org.apache.commons.lang3.tuple.Pair; import org.jetbrains.annotations.NotNull; import org.objectweb.asm.tree.ClassNode; import org.spongepowered.asm.mixin.MixinEnvironment; @@ -11,8 +13,6 @@ import org.spongepowered.asm.mixin.transformer.ext.ITargetClassContext; import top.hendrixshen.magiclib.util.ReflectionUtil; import top.hendrixshen.magiclib.util.collect.ValueContainer; -import top.hendrixshen.magiclib.util.collect.tuple.ImmutablePair; -import top.hendrixshen.magiclib.util.collect.tuple.Pair; import java.util.List; import java.util.Map; diff --git a/magiclib-core/gradle.properties b/magiclib-core/gradle.properties index dfecf572..3ce671e2 100644 --- a/magiclib-core/gradle.properties +++ b/magiclib-core/gradle.properties @@ -8,6 +8,7 @@ mod.version=0.8 # Dependency Versions dependencies.asm_version=9.7 +dependencies.apache_common_lang3_version=3.14.0 dependencies.gson_version=2.11.0 dependencies.guava_version=33.2.1-jre dependencies.log4j_version=2.23.1