From 96858e0e8687ed9a7dd089f92460662a9ea8ee58 Mon Sep 17 00:00:00 2001 From: MrMicky Date: Wed, 10 Oct 2018 22:41:50 +0200 Subject: [PATCH] Remove Apache Commons Lang and unnecessary Guava usages --- build.gradle | 1 - src/main/java/com/mojang/datafixers/DSL.java | 15 +++--- .../mojang/datafixers/DataFixerBuilder.java | 3 +- .../com/mojang/datafixers/DataFixerUpper.java | 4 +- .../com/mojang/datafixers/FunctionType.java | 1 - .../com/mojang/datafixers/RewriteResult.java | 3 +- .../java/com/mojang/datafixers/Typed.java | 2 +- .../com/mojang/datafixers/TypedOptic.java | 4 +- .../com/mojang/datafixers/functions/Fold.java | 6 +-- .../datafixers/functions/PointFree.java | 9 +++- .../datafixers/functions/PointFreeRule.java | 11 ++-- .../com/mojang/datafixers/optics/Optic.java | 1 - .../com/mojang/datafixers/optics/Optics.java | 12 ++--- .../optics/profunctors/TraversalP.java | 4 +- .../com/mojang/datafixers/schemas/Schema.java | 10 ++-- .../com/mojang/datafixers/types/Type.java | 6 +-- .../types/families/RecursiveTypeFamily.java | 6 +-- .../types/templates/CompoundList.java | 4 +- .../datafixers/types/templates/List.java | 4 +- .../types/templates/RecursivePoint.java | 3 +- .../types/templates/TaggedChoice.java | 11 ++-- .../com/mojang/datafixers/util/Triple.java | 54 +++++++++++++++++++ 22 files changed, 113 insertions(+), 61 deletions(-) create mode 100644 src/main/java/com/mojang/datafixers/util/Triple.java diff --git a/build.gradle b/build.gradle index 9c7b9e55..2d99d0a1 100644 --- a/build.gradle +++ b/build.gradle @@ -37,7 +37,6 @@ dependencies { compile 'com.google.code.gson:gson:2.8.0' compile 'org.apache.logging.log4j:log4j-api:2.8.1' compile 'com.google.guava:guava:21.0' - compile 'org.apache.commons:commons-lang3:3.5' compile 'it.unimi.dsi:fastutil:7.1.0' } diff --git a/src/main/java/com/mojang/datafixers/DSL.java b/src/main/java/com/mojang/datafixers/DSL.java index be9d3f51..7378044e 100644 --- a/src/main/java/com/mojang/datafixers/DSL.java +++ b/src/main/java/com/mojang/datafixers/DSL.java @@ -2,11 +2,10 @@ // Licensed under the MIT license. package com.mojang.datafixers; -import com.google.common.collect.Maps; import com.mojang.datafixers.util.Either; import com.mojang.datafixers.util.Pair; +import com.mojang.datafixers.util.Triple; import com.mojang.datafixers.util.Unit; -import com.mojang.datafixers.kinds.App2; import com.mojang.datafixers.schemas.Schema; import com.mojang.datafixers.types.Func; import com.mojang.datafixers.types.Type; @@ -33,10 +32,9 @@ import com.mojang.datafixers.types.templates.Tag; import com.mojang.datafixers.types.templates.TaggedChoice; import com.mojang.datafixers.types.templates.TypeTemplate; -import org.apache.commons.lang3.ArrayUtils; -import org.apache.commons.lang3.tuple.Triple; import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; import java.util.function.Function; import java.util.function.Supplier; import java.util.stream.Collectors; @@ -168,7 +166,10 @@ static TypeTemplate and(final TypeTemplate first, final TypeTemplate... rest) { } static TypeTemplate allWithRemainder(final TypeTemplate first, final TypeTemplate... rest) { - return and(first, ArrayUtils.add(rest, remainder())); + TypeTemplate[] templates = new TypeTemplate[rest.length + 1]; + System.arraycopy(rest, 0, templates, 0, rest.length); + templates[rest.length] = remainder(); + return and(first, templates); } static Type> and(final Type first, final Type second) { @@ -213,7 +214,7 @@ static TaggedChoice taggedChoiceLazy(final String name, final Type key @SuppressWarnings("unchecked") static Type> taggedChoiceType(final String name, final Type keyType, final Map> types) { - return (Type>) Instances.TAGGED_CHOICE_TYPE_CACHE.computeIfAbsent(Triple.of(name, keyType, types), k -> new TaggedChoice.TaggedChoiceType<>(k.getLeft(), (Type) k.getMiddle(), (Map>) k.getRight())); + return (Type>) Instances.TAGGED_CHOICE_TYPE_CACHE.computeIfAbsent(Triple.of(name, keyType, types), k -> new TaggedChoice.TaggedChoiceType<>(k.getFirst(), (Type) k.getSecond(), (Map>) k.getThird())); } static Type> func(final Type input, final Type output) { @@ -461,6 +462,6 @@ final class Instances { private static final OpticFinder> REMAINDER_FINDER = remainderType().finder(); - private static final Map, Map>>, Type>> TAGGED_CHOICE_TYPE_CACHE = Maps.newConcurrentMap(); + private static final Map, Map>>, Type>> TAGGED_CHOICE_TYPE_CACHE = new ConcurrentHashMap<>(); } } diff --git a/src/main/java/com/mojang/datafixers/DataFixerBuilder.java b/src/main/java/com/mojang/datafixers/DataFixerBuilder.java index 57ceddbf..f6616f2d 100644 --- a/src/main/java/com/mojang/datafixers/DataFixerBuilder.java +++ b/src/main/java/com/mojang/datafixers/DataFixerBuilder.java @@ -2,7 +2,6 @@ // Licensed under the MIT license. package com.mojang.datafixers; -import com.google.common.collect.Lists; import it.unimi.dsi.fastutil.ints.Int2ObjectAVLTreeMap; import it.unimi.dsi.fastutil.ints.Int2ObjectSortedMap; import it.unimi.dsi.fastutil.ints.IntAVLTreeSet; @@ -23,7 +22,7 @@ public class DataFixerBuilder { private final int dataVersion; private final Int2ObjectSortedMap schemas = new Int2ObjectAVLTreeMap<>(); - private final List globalList = Lists.newArrayList(); + private final List globalList = new ArrayList<>(); private final IntSortedSet fixerVersions = new IntAVLTreeSet(); public DataFixerBuilder(final int dataVersion) { diff --git a/src/main/java/com/mojang/datafixers/DataFixerUpper.java b/src/main/java/com/mojang/datafixers/DataFixerUpper.java index 8ce8cb92..c0f04457 100644 --- a/src/main/java/com/mojang/datafixers/DataFixerUpper.java +++ b/src/main/java/com/mojang/datafixers/DataFixerUpper.java @@ -3,7 +3,6 @@ package com.mojang.datafixers; import com.google.common.collect.ImmutableList; -import com.google.common.collect.Lists; import it.unimi.dsi.fastutil.ints.Int2ObjectSortedMap; import it.unimi.dsi.fastutil.ints.IntSortedSet; import it.unimi.dsi.fastutil.longs.Long2ObjectMap; @@ -14,6 +13,7 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; +import java.util.ArrayList; import java.util.List; import java.util.Optional; @@ -128,7 +128,7 @@ protected TypeRewriteRule getRule(final int version, final int dataVersion) { final long key = (long) expandedVersion << 32 | expandedDataVersion; if (!rules.containsKey(key)) { - final List rules = Lists.newArrayList(); + final List rules = new ArrayList<>(); for (final DataFix fix : globalList) { final int fixVersion = fix.getVersionKey(); if (fixVersion > expandedVersion && fixVersion <= expandedDataVersion) { diff --git a/src/main/java/com/mojang/datafixers/FunctionType.java b/src/main/java/com/mojang/datafixers/FunctionType.java index ec1572db..7bb526e8 100644 --- a/src/main/java/com/mojang/datafixers/FunctionType.java +++ b/src/main/java/com/mojang/datafixers/FunctionType.java @@ -10,7 +10,6 @@ import com.mojang.datafixers.kinds.K1; import com.mojang.datafixers.kinds.K2; import com.mojang.datafixers.kinds.Representable; -import com.mojang.datafixers.optics.Optic; import com.mojang.datafixers.optics.Optics; import com.mojang.datafixers.optics.Procompose; import com.mojang.datafixers.optics.Wander; diff --git a/src/main/java/com/mojang/datafixers/RewriteResult.java b/src/main/java/com/mojang/datafixers/RewriteResult.java index e85c71f8..48044876 100644 --- a/src/main/java/com/mojang/datafixers/RewriteResult.java +++ b/src/main/java/com/mojang/datafixers/RewriteResult.java @@ -4,7 +4,6 @@ import com.mojang.datafixers.types.Type; import com.mojang.datafixers.types.templates.RecursivePoint; -import org.apache.commons.lang3.ObjectUtils; import java.util.BitSet; import java.util.Objects; @@ -30,7 +29,7 @@ public RewriteResult compose(final RewriteResult that) { final BitSet newData; if (view.type() instanceof RecursivePoint.RecursivePointType && that.view.type() instanceof RecursivePoint.RecursivePointType) { // same family, merge results - not exactly accurate, but should be good enough - newData = ObjectUtils.clone(recData); + newData = (BitSet) recData.clone(); newData.or(that.recData); } else { newData = recData; diff --git a/src/main/java/com/mojang/datafixers/Typed.java b/src/main/java/com/mojang/datafixers/Typed.java index a6195abd..a3d58b8e 100644 --- a/src/main/java/com/mojang/datafixers/Typed.java +++ b/src/main/java/com/mojang/datafixers/Typed.java @@ -165,7 +165,7 @@ private Typed updateCap(final TypedOptic field, fin public List> getAllTyped(final OpticFinder optic) { final TypedOptic field = optic.findType(type, optic.type(), false).orThrow(); - return getAll(field).stream().map(ft -> new Typed(optic.type(), ops, ft)).collect(Collectors.toList()); + return getAll(field).stream().map(ft -> new Typed<>(optic.type(), ops, ft)).collect(Collectors.toList()); } public List getAll(final TypedOptic field) { diff --git a/src/main/java/com/mojang/datafixers/TypedOptic.java b/src/main/java/com/mojang/datafixers/TypedOptic.java index 375a4137..ae73e917 100644 --- a/src/main/java/com/mojang/datafixers/TypedOptic.java +++ b/src/main/java/com/mojang/datafixers/TypedOptic.java @@ -3,7 +3,6 @@ package com.mojang.datafixers; import com.google.common.collect.ImmutableSet; -import com.google.common.collect.Maps; import com.google.common.reflect.TypeToken; import com.mojang.datafixers.util.Either; import com.mojang.datafixers.util.Pair; @@ -27,6 +26,7 @@ import com.mojang.datafixers.types.templates.TaggedChoice; import java.util.Collection; +import java.util.HashMap; import java.util.Map; import java.util.Objects; import java.util.Optional; @@ -204,7 +204,7 @@ public static TypedOptic, java.util.List, A, B> list if (!Objects.equals(sType.types().get(key), aType)) { throw new IllegalArgumentException("Focused type doesn't match."); } - final Map> newTypes = Maps.newHashMap(sType.types()); + final Map> newTypes = new HashMap<>(sType.types()); newTypes.put(key, bType); final Type> pairType = DSL.taggedChoiceType(sType.getName(), sType.getKeyType(), newTypes); return new TypedOptic<>( diff --git a/src/main/java/com/mojang/datafixers/functions/Fold.java b/src/main/java/com/mojang/datafixers/functions/Fold.java index c6cd021f..b7cab6b8 100644 --- a/src/main/java/com/mojang/datafixers/functions/Fold.java +++ b/src/main/java/com/mojang/datafixers/functions/Fold.java @@ -2,7 +2,6 @@ // Licensed under the MIT license. package com.mojang.datafixers.functions; -import com.google.common.collect.Maps; import com.mojang.datafixers.RewriteResult; import com.mojang.datafixers.View; import com.mojang.datafixers.types.DynamicOps; @@ -11,14 +10,15 @@ import com.mojang.datafixers.types.templates.RecursivePoint; import com.mojang.datafixers.util.Pair; +import java.util.HashMap; import java.util.Map; import java.util.Objects; import java.util.function.Function; import java.util.function.IntFunction; final class Fold extends PointFree> { - private static final Map, IntFunction>> HMAP_CACHE = Maps.newConcurrentMap(); - private static final Map>, Integer>, RewriteResult> HMAP_APPLY_CACHE = Maps.newConcurrentMap(); + private static final Map, IntFunction>> HMAP_CACHE = new HashMap<>(); + private static final Map>, Integer>, RewriteResult> HMAP_APPLY_CACHE = new HashMap<>(); protected final RecursivePoint.RecursivePointType aType; protected final RewriteResult function; diff --git a/src/main/java/com/mojang/datafixers/functions/PointFree.java b/src/main/java/com/mojang/datafixers/functions/PointFree.java index 4bc53fdc..00decb7e 100644 --- a/src/main/java/com/mojang/datafixers/functions/PointFree.java +++ b/src/main/java/com/mojang/datafixers/functions/PointFree.java @@ -4,9 +4,9 @@ import com.mojang.datafixers.types.DynamicOps; import com.mojang.datafixers.types.Type; -import org.apache.commons.lang3.StringUtils; import javax.annotation.Nullable; +import java.util.Arrays; import java.util.Optional; import java.util.function.Function; @@ -40,7 +40,12 @@ public final String toString() { } public static String indent(final int level) { - return StringUtils.repeat(" ", level); + if (level > 0) { + char[] spaces = new char[level * 2]; + Arrays.fill(spaces, ' '); + return new String(spaces); + } + return ""; } public abstract String toString(int level); diff --git a/src/main/java/com/mojang/datafixers/functions/PointFreeRule.java b/src/main/java/com/mojang/datafixers/functions/PointFreeRule.java index 68747734..31a74fc6 100644 --- a/src/main/java/com/mojang/datafixers/functions/PointFreeRule.java +++ b/src/main/java/com/mojang/datafixers/functions/PointFreeRule.java @@ -3,15 +3,12 @@ package com.mojang.datafixers.functions; import com.google.common.collect.ImmutableList; -import com.google.common.collect.Lists; import com.mojang.datafixers.util.Either; import com.mojang.datafixers.util.Pair; import com.mojang.datafixers.DSL; import com.mojang.datafixers.DataFixUtils; -import com.mojang.datafixers.FunctionType; import com.mojang.datafixers.RewriteResult; import com.mojang.datafixers.View; -import com.mojang.datafixers.kinds.App2; import com.mojang.datafixers.kinds.K1; import com.mojang.datafixers.kinds.K2; import com.mojang.datafixers.optics.Optic; @@ -22,8 +19,8 @@ import com.mojang.datafixers.types.families.Algebra; import com.mojang.datafixers.types.families.ListAlgebra; import com.mojang.datafixers.types.families.RecursiveTypeFamily; -import org.apache.commons.lang3.ObjectUtils; +import java.util.ArrayList; import java.util.BitSet; import java.util.List; import java.util.Objects; @@ -394,7 +391,7 @@ public Optional> doRewrite(final Type type, final final RecursiveTypeFamily family = firstFold.aType.family(); if (Objects.equals(family, secondFold.aType.family()) && firstFold.index == secondFold.index) { // same fold - final List> newAlgebra = Lists.newArrayList(); + final List> newAlgebra = new ArrayList<>(); // merge where both are touching, id where neither is @@ -441,7 +438,7 @@ public Optional> doRewrite(final Type type, final final RecursiveTypeFamily family = firstFold.aType.family(); if (Objects.equals(family, secondFold.aType.family()) && firstFold.index == secondFold.index) { // same fold - final List> newAlgebra = Lists.newArrayList(); + final List> newAlgebra = new ArrayList<>(); final BitSet firstModifies = new BitSet(family.size()); final BitSet secondModifies = new BitSet(family.size()); @@ -455,7 +452,7 @@ public Optional> doRewrite(final Type type, final secondModifies.set(i, !secondId); } - final BitSet newSet = ObjectUtils.clone(firstModifies); + final BitSet newSet = (BitSet) firstModifies.clone(); newSet.or(secondModifies); // if the left function doesn't care about the right modifications, and converse is correct, the merge is valid diff --git a/src/main/java/com/mojang/datafixers/optics/Optic.java b/src/main/java/com/mojang/datafixers/optics/Optic.java index e2574f91..077fb157 100644 --- a/src/main/java/com/mojang/datafixers/optics/Optic.java +++ b/src/main/java/com/mojang/datafixers/optics/Optic.java @@ -3,7 +3,6 @@ package com.mojang.datafixers.optics; import com.google.common.reflect.TypeToken; -import com.mojang.datafixers.FunctionType; import com.mojang.datafixers.kinds.App; import com.mojang.datafixers.kinds.App2; import com.mojang.datafixers.kinds.K1; diff --git a/src/main/java/com/mojang/datafixers/optics/Optics.java b/src/main/java/com/mojang/datafixers/optics/Optics.java index 76553b43..0711adce 100644 --- a/src/main/java/com/mojang/datafixers/optics/Optics.java +++ b/src/main/java/com/mojang/datafixers/optics/Optics.java @@ -23,32 +23,32 @@ public abstract class Optics { public static Adapter toAdapter(final Optic optic) { - final Function, A, B>, App2, S, T>> eval = optic.eval(new Adapter.Instance()); + final Function, A, B>, App2, S, T>> eval = optic.eval(new Adapter.Instance<>()); return Adapter.unbox(eval.apply(adapter(Function.identity(), Function.identity()))); } public static Lens toLens(final Optic optic) { - final Function, A, B>, App2, S, T>> eval = optic.eval(new Lens.Instance()); + final Function, A, B>, App2, S, T>> eval = optic.eval(new Lens.Instance<>()); return Lens.unbox(eval.apply(lens(Function.identity(), (b, a) -> b))); } public static Prism toPrism(final Optic optic) { - final Function, A, B>, App2, S, T>> eval = optic.eval(new Prism.Instance()); + final Function, A, B>, App2, S, T>> eval = optic.eval(new Prism.Instance<>()); return Prism.unbox(eval.apply(prism(Either::right, Function.identity()))); } public static Affine toAffine(final Optic optic) { - final Function, A, B>, App2, S, T>> eval = optic.eval(new Affine.Instance()); + final Function, A, B>, App2, S, T>> eval = optic.eval(new Affine.Instance<>()); return Affine.unbox(eval.apply(affine(Either::right, (b, a) -> b))); } public static Getter toGetter(final Optic optic) { - final Function, A, B>, App2, S, T>> eval = optic.eval(new Getter.Instance()); + final Function, A, B>, App2, S, T>> eval = optic.eval(new Getter.Instance<>()); return Getter.unbox(eval.apply(getter(Function.identity()))); } public static Traversal toTraversal(final Optic optic) { - final Function, A, B>, App2, S, T>> eval = optic.eval(new Traversal.Instance()); + final Function, A, B>, App2, S, T>> eval = optic.eval(new Traversal.Instance<>()); return Traversal.unbox(eval.apply(new Traversal() { @Override public FunctionType> wander(final Applicative applicative, final FunctionType> input) { diff --git a/src/main/java/com/mojang/datafixers/optics/profunctors/TraversalP.java b/src/main/java/com/mojang/datafixers/optics/profunctors/TraversalP.java index 3f3daee9..7bd3efcc 100644 --- a/src/main/java/com/mojang/datafixers/optics/profunctors/TraversalP.java +++ b/src/main/java/com/mojang/datafixers/optics/profunctors/TraversalP.java @@ -54,12 +54,12 @@ public FunctionType, App>> wander(final Ap @Override default App2, Pair> first(final App2 input) { - return dimap(traverse(new Pair.Instance(), input), box -> box, Pair::unbox); + return dimap(traverse(new Pair.Instance<>(), input), box -> box, Pair::unbox); } @Override default App2, Either> left(final App2 input) { - return dimap(traverse(new Either.Instance(), input), box -> box, Either::unbox); + return dimap(traverse(new Either.Instance<>(), input), box -> box, Either::unbox); } default FunctorProfunctor> toFP3() { diff --git a/src/main/java/com/mojang/datafixers/schemas/Schema.java b/src/main/java/com/mojang/datafixers/schemas/Schema.java index 5d0dd222..205e7511 100644 --- a/src/main/java/com/mojang/datafixers/schemas/Schema.java +++ b/src/main/java/com/mojang/datafixers/schemas/Schema.java @@ -2,8 +2,6 @@ // Licensed under the MIT license. package com.mojang.datafixers.schemas; -import com.google.common.collect.Lists; -import com.google.common.collect.Maps; import it.unimi.dsi.fastutil.objects.Object2IntMap; import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap; import com.mojang.datafixers.DSL; @@ -15,6 +13,8 @@ import com.mojang.datafixers.types.templates.TaggedChoice; import com.mojang.datafixers.types.templates.TypeTemplate; +import java.util.ArrayList; +import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Set; @@ -23,7 +23,7 @@ public class Schema { protected final Object2IntMap RECURSIVE_TYPES = new Object2IntOpenHashMap<>(); - private final Map> TYPE_TEMPLATES = Maps.newHashMap(); + private final Map> TYPE_TEMPLATES = new HashMap<>(); private final Map> TYPES; private final int versionKey; private final String name; @@ -39,9 +39,9 @@ public Schema(final int versionKey, final Schema parent) { } protected Map> buildTypes() { - final Map> types = Maps.newHashMap(); + final Map> types = new HashMap<>(); - final List templates = Lists.newArrayList(); + final List templates = new ArrayList<>(); for (final Object2IntMap.Entry entry : RECURSIVE_TYPES.object2IntEntrySet()) { templates.add(DSL.check(entry.getKey(), entry.getIntValue(), getTemplate(entry.getKey()))); diff --git a/src/main/java/com/mojang/datafixers/types/Type.java b/src/main/java/com/mojang/datafixers/types/Type.java index 152f3ff0..287fe2e6 100644 --- a/src/main/java/com/mojang/datafixers/types/Type.java +++ b/src/main/java/com/mojang/datafixers/types/Type.java @@ -2,7 +2,6 @@ // Licensed under the MIT license. package com.mojang.datafixers.types; -import com.google.common.collect.Maps; import com.mojang.datafixers.util.Either; import com.mojang.datafixers.util.Pair; import com.mojang.datafixers.DSL; @@ -23,15 +22,16 @@ import com.mojang.datafixers.types.families.RecursiveTypeFamily; import com.mojang.datafixers.types.templates.TaggedChoice; import com.mojang.datafixers.types.templates.TypeTemplate; -import org.apache.commons.lang3.tuple.Triple; +import com.mojang.datafixers.util.Triple; import javax.annotation.Nullable; import java.util.Map; import java.util.Objects; import java.util.Optional; +import java.util.concurrent.ConcurrentHashMap; public abstract class Type implements App { - private static final Map, TypeRewriteRule, PointFreeRule>, Optional>> REWRITE_CACHE = Maps.newConcurrentMap(); + private static final Map, TypeRewriteRule, PointFreeRule>, Optional>> REWRITE_CACHE = new ConcurrentHashMap<>(); public static class Mu implements K1 {} diff --git a/src/main/java/com/mojang/datafixers/types/families/RecursiveTypeFamily.java b/src/main/java/com/mojang/datafixers/types/families/RecursiveTypeFamily.java index 234bb4fb..71807aab 100644 --- a/src/main/java/com/mojang/datafixers/types/families/RecursiveTypeFamily.java +++ b/src/main/java/com/mojang/datafixers/types/families/RecursiveTypeFamily.java @@ -2,7 +2,6 @@ // Licensed under the MIT license. package com.mojang.datafixers.types.families; -import com.google.common.collect.Lists; import com.mojang.datafixers.DataFixUtils; import com.mojang.datafixers.FamilyOptic; import com.mojang.datafixers.OpticParts; @@ -22,6 +21,7 @@ import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; import javax.annotation.Nullable; +import java.util.ArrayList; import java.util.BitSet; import java.util.List; import java.util.Objects; @@ -111,7 +111,7 @@ public RecursivePoint.RecursivePointType apply(final int index) { public Either, Type.FieldNotFoundException> findType(final int index, final Type aType, final Type bType, final Type.TypeMatcher matcher, final boolean recurse) { return apply(index).unfold().findType(aType, bType, matcher, false).flatMap(optic -> { final TypeTemplate nc = optic.tType().template(); - final List> fo = Lists.newArrayList(); + final List> fo = new ArrayList<>(); final RecursiveTypeFamily newFamily = new RecursiveTypeFamily(name, nc); final RecursivePoint.RecursivePointType sType = apply(index); @@ -151,7 +151,7 @@ private TypedOptic mkOptic(final Type sType, final T final RecursivePoint.RecursivePointType newType = buildMuType(sourceView.view().newType(), null); final RecursiveTypeFamily newFamily = newType.family(); - final List> views = Lists.newArrayList(); + final List> views = new ArrayList<>(); boolean foundAny = false; // FB -> B for (int i = 0; i < size; i++) { diff --git a/src/main/java/com/mojang/datafixers/types/templates/CompoundList.java b/src/main/java/com/mojang/datafixers/types/templates/CompoundList.java index 33bda0e0..cadfdbfe 100644 --- a/src/main/java/com/mojang/datafixers/types/templates/CompoundList.java +++ b/src/main/java/com/mojang/datafixers/types/templates/CompoundList.java @@ -4,7 +4,6 @@ import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; -import com.google.common.collect.Sets; import com.google.common.reflect.TypeToken; import com.mojang.datafixers.util.Either; import com.mojang.datafixers.util.Pair; @@ -26,6 +25,7 @@ import com.mojang.datafixers.types.families.TypeFamily; import javax.annotation.Nullable; +import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Objects; @@ -57,7 +57,7 @@ public FamilyOptic applyO(final FamilyOptic input, final Type return TypeFamily.familyOptic( i -> { final OpticParts optic = element.applyO(input, aType, bType).apply(i); - final Set> bounds = Sets.newHashSet(optic.bounds()); + final Set> bounds = new HashSet<>(optic.bounds()); bounds.add(TraversalP.Mu.TYPE_TOKEN); return new OpticParts<>(bounds, cap(optic.optic())); } diff --git a/src/main/java/com/mojang/datafixers/types/templates/List.java b/src/main/java/com/mojang/datafixers/types/templates/List.java index 956bea11..738d95b4 100644 --- a/src/main/java/com/mojang/datafixers/types/templates/List.java +++ b/src/main/java/com/mojang/datafixers/types/templates/List.java @@ -3,7 +3,6 @@ package com.mojang.datafixers.types.templates; import com.google.common.collect.ImmutableList; -import com.google.common.collect.Sets; import com.google.common.reflect.TypeToken; import com.mojang.datafixers.util.Either; import com.mojang.datafixers.util.Pair; @@ -23,6 +22,7 @@ import com.mojang.datafixers.types.families.TypeFamily; import javax.annotation.Nullable; +import java.util.HashSet; import java.util.Objects; import java.util.Optional; import java.util.Set; @@ -66,7 +66,7 @@ public FamilyOptic applyO(final FamilyOptic input, final Type return TypeFamily.familyOptic( i -> { final OpticParts pair = element.applyO(input, aType, bType).apply(i); - final Set> bounds = Sets.newHashSet(pair.bounds()); + final Set> bounds = new HashSet<>(pair.bounds()); bounds.add(TraversalP.Mu.TYPE_TOKEN); return new OpticParts<>(bounds, cap(pair.optic())); } diff --git a/src/main/java/com/mojang/datafixers/types/templates/RecursivePoint.java b/src/main/java/com/mojang/datafixers/types/templates/RecursivePoint.java index 2ffadfb9..65cf4a07 100644 --- a/src/main/java/com/mojang/datafixers/types/templates/RecursivePoint.java +++ b/src/main/java/com/mojang/datafixers/types/templates/RecursivePoint.java @@ -16,7 +16,6 @@ import com.mojang.datafixers.types.Type; import com.mojang.datafixers.types.families.RecursiveTypeFamily; import com.mojang.datafixers.types.families.TypeFamily; -import org.apache.commons.lang3.ObjectUtils; import javax.annotation.Nullable; import java.util.BitSet; @@ -83,7 +82,7 @@ public RewriteResult cap(final TypeFamily family, final RewriteResu } final RecursivePointType sType = (RecursivePointType) sourceType; final RecursivePointType tType = sType.family().buildMuType(result.view().newType(), null); - final BitSet bitSet = ObjectUtils.clone(result.recData()); + final BitSet bitSet = (BitSet) result.recData().clone(); bitSet.set(index); return RewriteResult.create(View.create(sType, tType, result.view().function()), bitSet); } diff --git a/src/main/java/com/mojang/datafixers/types/templates/TaggedChoice.java b/src/main/java/com/mojang/datafixers/types/templates/TaggedChoice.java index 03bad608..d6254f2f 100644 --- a/src/main/java/com/mojang/datafixers/types/templates/TaggedChoice.java +++ b/src/main/java/com/mojang/datafixers/types/templates/TaggedChoice.java @@ -3,8 +3,6 @@ package com.mojang.datafixers.types.templates; import com.google.common.base.Joiner; -import com.google.common.collect.Maps; -import com.google.common.collect.Sets; import com.google.common.reflect.TypeToken; import com.mojang.datafixers.util.Either; import com.mojang.datafixers.util.Pair; @@ -39,10 +37,13 @@ import javax.annotation.Nullable; import java.util.Arrays; import java.util.BitSet; +import java.util.HashMap; +import java.util.HashSet; import java.util.Map; import java.util.Objects; import java.util.Optional; import java.util.Set; +import java.util.concurrent.ConcurrentHashMap; import java.util.function.Function; import java.util.function.IntFunction; import java.util.stream.Collectors; @@ -53,7 +54,7 @@ public final class TaggedChoice implements TypeTemplate { private final String name; private final Type keyType; private final Map templates; - private final Map, Type> types = Maps.newConcurrentMap(); + private final Map, Type> types = new ConcurrentHashMap<>(); private final int size; public TaggedChoice(final String name, final Type keyType, final Map templates) { @@ -149,7 +150,7 @@ public TaggedChoiceType(final String name, final Type keyType, final Map> entry = results.entrySet().iterator().next(); return elementResult(entry.getKey(), this, entry.getValue()); } - final Map> newTypes = Maps.newHashMap(types); + final Map> newTypes = new HashMap<>(types); final BitSet recData = new BitSet(); for (final Map.Entry> entry : results.entrySet()) { newTypes.put(entry.getKey(), entry.getValue().view().newType()); @@ -254,7 +255,7 @@ public Optional> findFieldTypeOpt(final String name) { final Map.Entry> entry = optics.entrySet().iterator().next(); return Either.left(cap(this, entry.getKey(), entry.getValue())); } else { - final Set> bounds = Sets.newHashSet(); + final Set> bounds = new HashSet<>(); optics.values().forEach(o -> bounds.addAll(o.bounds())); final Optic, Pair, FT, FR> optic; diff --git a/src/main/java/com/mojang/datafixers/util/Triple.java b/src/main/java/com/mojang/datafixers/util/Triple.java new file mode 100644 index 00000000..48af2abb --- /dev/null +++ b/src/main/java/com/mojang/datafixers/util/Triple.java @@ -0,0 +1,54 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT license. +package com.mojang.datafixers.util; + +import java.util.Objects; + +public class Triple { + + private final F first; + private final S second; + private final T third; + + public Triple(F first, S second, T third) { + this.first = first; + this.second = second; + this.third = third; + } + + public F getFirst() { + return first; + } + + public S getSecond() { + return second; + } + + public T getThird() { + return third; + } + + @Override + public String toString() { + return "(" + first + ", " + second + ", " + third + ")"; + } + + @Override + public boolean equals(final Object obj) { + if (!(obj instanceof Triple)) { + return false; + } + + final Triple other = (Triple) obj; + return Objects.equals(first, other.first) && Objects.equals(second, other.second) && Objects.equals(third, other.third); + } + + @Override + public int hashCode() { + return com.google.common.base.Objects.hashCode(first, second, third); + } + + public static Triple of(final F first, final S second, T third) { + return new Triple<>(first, second, third); + } +}