Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove Apache Commons Lang and unnecessary Guava usages #25

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
1 change: 0 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}

Expand Down
13 changes: 6 additions & 7 deletions src/main/java/com/mojang/datafixers/DSL.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
// Licensed under the MIT license.
package com.mojang.datafixers;

import com.google.common.collect.Maps;
import com.google.common.collect.ObjectArrays;
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;
Expand All @@ -33,10 +33,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;
Expand Down Expand Up @@ -168,7 +167,7 @@ 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()));
return and(first, ObjectArrays.concat(rest, remainder()));
}

static <F, G> Type<Pair<F, G>> and(final Type<F> first, final Type<G> second) {
Expand Down Expand Up @@ -213,7 +212,7 @@ static <K> TaggedChoice<K> taggedChoiceLazy(final String name, final Type<K> key

@SuppressWarnings("unchecked")
static <K> Type<Pair<K, ?>> taggedChoiceType(final String name, final Type<K> keyType, final Map<K, Type<?>> types) {
return (Type<Pair<K, ?>>) Instances.TAGGED_CHOICE_TYPE_CACHE.computeIfAbsent(Triple.of(name, keyType, types), k -> new TaggedChoice.TaggedChoiceType<>(k.getLeft(), (Type<K>) k.getMiddle(), (Map<K, Type<?>>) k.getRight()));
return (Type<Pair<K, ?>>) Instances.TAGGED_CHOICE_TYPE_CACHE.computeIfAbsent(Triple.of(name, keyType, types), k -> new TaggedChoice.TaggedChoiceType<>(k.getFirst(), (Type<K>) k.getSecond(), (Map<K, Type<?>>) k.getThird()));
}

static <A, B> Type<Function<A, B>> func(final Type<A> input, final Type<B> output) {
Expand Down Expand Up @@ -461,6 +460,6 @@ final class Instances {

private static final OpticFinder<Dynamic<?>> REMAINDER_FINDER = remainderType().finder();

private static final Map<Triple<String, Type<?>, Map<?, Type<?>>>, Type<? extends Pair<?, ?>>> TAGGED_CHOICE_TYPE_CACHE = Maps.newConcurrentMap();
private static final Map<Triple<String, Type<?>, Map<?, Type<?>>>, Type<? extends Pair<?, ?>>> TAGGED_CHOICE_TYPE_CACHE = new ConcurrentHashMap<>();
}
}
3 changes: 1 addition & 2 deletions src/main/java/com/mojang/datafixers/DataFixerBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// Licensed under the MIT license.
package com.mojang.datafixers;

import com.google.common.collect.Lists;
import com.mojang.datafixers.schemas.Schema;
import com.mojang.datafixers.types.Type;
import it.unimi.dsi.fastutil.ints.Int2ObjectAVLTreeMap;
Expand All @@ -24,7 +23,7 @@ public class DataFixerBuilder {

private final int dataVersion;
private final Int2ObjectSortedMap<Schema> schemas = new Int2ObjectAVLTreeMap<>();
private final List<DataFix> globalList = Lists.newArrayList();
private final List<DataFix> globalList = new ArrayList<>();
private final IntSortedSet fixerVersions = new IntAVLTreeSet();

public DataFixerBuilder(final int dataVersion) {
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/mojang/datafixers/DataFixerUpper.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -15,6 +14,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;

Expand Down Expand Up @@ -129,7 +129,7 @@ protected TypeRewriteRule getRule(final int version, final int dataVersion) {

final long key = (long) expandedVersion << 32 | expandedDataVersion;
return rules.computeIfAbsent(key, k -> {
final List<TypeRewriteRule> rules = Lists.newArrayList();
final List<TypeRewriteRule> rules = new ArrayList<>();
for (final DataFix fix : globalList) {
final int fixVersion = fix.getVersionKey();
if (fixVersion > expandedVersion && fixVersion <= expandedDataVersion) {
Expand Down
1 change: 0 additions & 1 deletion src/main/java/com/mojang/datafixers/FunctionType.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/com/mojang/datafixers/RewriteResult.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -30,7 +29,7 @@ public <C> RewriteResult<C, B> compose(final RewriteResult<C, A> 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;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/mojang/datafixers/Typed.java
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ private <B, FT, FR> Typed<B> updateCap(final TypedOptic<A, B, FT, FR> field, fin

public <FT> List<Typed<FT>> getAllTyped(final OpticFinder<FT> optic) {
final TypedOptic<A, ?, FT, ?> field = optic.findType(type, optic.type(), false).orThrow();
return getAll(field).stream().map(ft -> new Typed<FT>(optic.type(), ops, ft)).collect(Collectors.toList());
return getAll(field).stream().map(ft -> new Typed<>(optic.type(), ops, ft)).collect(Collectors.toList());
}

public <FT> List<FT> getAll(final TypedOptic<A, ?, FT, ?> field) {
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/mojang/datafixers/TypedOptic.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -204,7 +204,7 @@ public static <A, B> TypedOptic<java.util.List<A>, java.util.List<B>, A, B> list
if (!Objects.equals(sType.types().get(key), aType)) {
throw new IllegalArgumentException("Focused type doesn't match.");
}
final Map<K, Type<?>> newTypes = Maps.newHashMap(sType.types());
final Map<K, Type<?>> newTypes = new HashMap<>(sType.types());
newTypes.put(key, bType);
final Type<Pair<K, ?>> pairType = DSL.taggedChoiceType(sType.getName(), sType.getKeyType(), newTypes);
return new TypedOptic<>(
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/com/mojang/datafixers/functions/Fold.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -13,12 +12,13 @@

import java.util.Map;
import java.util.Objects;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Function;
import java.util.function.IntFunction;

final class Fold<A, B> extends PointFree<Function<A, B>> {
private static final Map<Pair<RecursiveTypeFamily, Algebra>, IntFunction<RewriteResult<?, ?>>> HMAP_CACHE = Maps.newConcurrentMap();
private static final Map<Pair<IntFunction<RewriteResult<?, ?>>, Integer>, RewriteResult<?, ?>> HMAP_APPLY_CACHE = Maps.newConcurrentMap();
private static final Map<Pair<RecursiveTypeFamily, Algebra>, IntFunction<RewriteResult<?, ?>>> HMAP_CACHE = new ConcurrentHashMap<>();
private static final Map<Pair<IntFunction<RewriteResult<?, ?>>, Integer>, RewriteResult<?, ?>> HMAP_APPLY_CACHE = new ConcurrentHashMap<>();

protected final RecursivePoint.RecursivePointType<A> aType;
protected final RewriteResult<?, B> function;
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/mojang/datafixers/functions/PointFree.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
// Licensed under the MIT license.
package com.mojang.datafixers.functions;

import com.google.common.base.Strings;
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.Optional;
Expand Down Expand Up @@ -44,7 +44,7 @@ public final String toString() {
}

public static String indent(final int level) {
return StringUtils.repeat(" ", level);
return Strings.repeat(" ", level);
}

public abstract String toString(int level);
Expand Down
11 changes: 4 additions & 7 deletions src/main/java/com/mojang/datafixers/functions/PointFreeRule.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -394,7 +391,7 @@ public <A> Optional<? extends PointFree<?>> doRewrite(final Type<A> type, final
final RecursiveTypeFamily family = firstFold.aType.family();
if (Objects.equals(family, secondFold.aType.family()) && firstFold.index == secondFold.index) {
// same fold
final List<RewriteResult<?, ?>> newAlgebra = Lists.newArrayList();
final List<RewriteResult<?, ?>> newAlgebra = new ArrayList<>();

// merge where both are touching, id where neither is

Expand Down Expand Up @@ -441,7 +438,7 @@ public <A> Optional<? extends PointFree<?>> doRewrite(final Type<A> type, final
final RecursiveTypeFamily family = firstFold.aType.family();
if (Objects.equals(family, secondFold.aType.family()) && firstFold.index == secondFold.index) {
// same fold
final List<RewriteResult<?, ?>> newAlgebra = Lists.newArrayList();
final List<RewriteResult<?, ?>> newAlgebra = new ArrayList<>();

final BitSet firstModifies = new BitSet(family.size());
final BitSet secondModifies = new BitSet(family.size());
Expand All @@ -455,7 +452,7 @@ public <A> Optional<? extends PointFree<?>> doRewrite(final Type<A> 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
Expand Down
1 change: 0 additions & 1 deletion src/main/java/com/mojang/datafixers/optics/Optic.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
12 changes: 6 additions & 6 deletions src/main/java/com/mojang/datafixers/optics/Optics.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,32 +23,32 @@

public abstract class Optics {
public static <S, T, A, B> Adapter<S, T, A, B> toAdapter(final Optic<? super Profunctor.Mu, S, T, A, B> optic) {
final Function<App2<Adapter.Mu<A, B>, A, B>, App2<Adapter.Mu<A, B>, S, T>> eval = optic.eval(new Adapter.Instance<A, B>());
final Function<App2<Adapter.Mu<A, B>, A, B>, App2<Adapter.Mu<A, B>, S, T>> eval = optic.eval(new Adapter.Instance<>());
return Adapter.unbox(eval.apply(adapter(Function.identity(), Function.identity())));
}

public static <S, T, A, B> Lens<S, T, A, B> toLens(final Optic<? super Cartesian.Mu, S, T, A, B> optic) {
final Function<App2<Lens.Mu<A, B>, A, B>, App2<Lens.Mu<A, B>, S, T>> eval = optic.eval(new Lens.Instance<A, B>());
final Function<App2<Lens.Mu<A, B>, A, B>, App2<Lens.Mu<A, B>, S, T>> eval = optic.eval(new Lens.Instance<>());
return Lens.unbox(eval.apply(lens(Function.identity(), (b, a) -> b)));
}

public static <S, T, A, B> Prism<S, T, A, B> toPrism(final Optic<? super Cocartesian.Mu, S, T, A, B> optic) {
final Function<App2<Prism.Mu<A, B>, A, B>, App2<Prism.Mu<A, B>, S, T>> eval = optic.eval(new Prism.Instance<A, B>());
final Function<App2<Prism.Mu<A, B>, A, B>, App2<Prism.Mu<A, B>, S, T>> eval = optic.eval(new Prism.Instance<>());
return Prism.unbox(eval.apply(prism(Either::right, Function.identity())));
}

public static <S, T, A, B> Affine<S, T, A, B> toAffine(final Optic<? super AffineP.Mu, S, T, A, B> optic) {
final Function<App2<Affine.Mu<A, B>, A, B>, App2<Affine.Mu<A, B>, S, T>> eval = optic.eval(new Affine.Instance<A, B>());
final Function<App2<Affine.Mu<A, B>, A, B>, App2<Affine.Mu<A, B>, S, T>> eval = optic.eval(new Affine.Instance<>());
return Affine.unbox(eval.apply(affine(Either::right, (b, a) -> b)));
}

public static <S, T, A, B> Getter<S, T, A, B> toGetter(final Optic<? super GetterP.Mu, S, T, A, B> optic) {
final Function<App2<Getter.Mu<A, B>, A, B>, App2<Getter.Mu<A, B>, S, T>> eval = optic.eval(new Getter.Instance<A, B>());
final Function<App2<Getter.Mu<A, B>, A, B>, App2<Getter.Mu<A, B>, S, T>> eval = optic.eval(new Getter.Instance<>());
return Getter.unbox(eval.apply(getter(Function.identity())));
}

public static <S, T, A, B> Traversal<S, T, A, B> toTraversal(final Optic<? super TraversalP.Mu, S, T, A, B> optic) {
final Function<App2<Traversal.Mu<A, B>, A, B>, App2<Traversal.Mu<A, B>, S, T>> eval = optic.eval(new Traversal.Instance<A, B>());
final Function<App2<Traversal.Mu<A, B>, A, B>, App2<Traversal.Mu<A, B>, S, T>> eval = optic.eval(new Traversal.Instance<>());
return Traversal.unbox(eval.apply(new Traversal<A, B, A, B>() {
@Override
public <F extends K1> FunctionType<A, App<F, B>> wander(final Applicative<F, ?> applicative, final FunctionType<A, App<F, B>> input) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,12 @@ public <F extends K1> FunctionType<App<T, A>, App<F, App<T, B>>> wander(final Ap

@Override
default <A, B, C> App2<P, Pair<A, C>, Pair<B, C>> first(final App2<P, A, B> input) {
return dimap(traverse(new Pair.Instance<C>(), input), box -> box, Pair::unbox);
return dimap(traverse(new Pair.Instance<>(), input), box -> box, Pair::unbox);
}

@Override
default <A, B, C> App2<P, Either<A, C>, Either<B, C>> left(final App2<P, A, B> input) {
return dimap(traverse(new Either.Instance<C>(), input), box -> box, Either::unbox);
return dimap(traverse(new Either.Instance<>(), input), box -> box, Either::unbox);
}

default FunctorProfunctor<Traversable.Mu, P, FunctorProfunctor.Mu<Traversable.Mu>> toFP3() {
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/com/mojang/datafixers/schemas/Schema.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 com.mojang.datafixers.DSL;
import com.mojang.datafixers.DataFixUtils;
import com.mojang.datafixers.types.Type;
Expand All @@ -15,6 +13,8 @@
import it.unimi.dsi.fastutil.objects.Object2IntMap;
import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
Expand All @@ -23,7 +23,7 @@

public class Schema {
protected final Object2IntMap<String> RECURSIVE_TYPES = new Object2IntOpenHashMap<>();
private final Map<String, Supplier<TypeTemplate>> TYPE_TEMPLATES = Maps.newHashMap();
private final Map<String, Supplier<TypeTemplate>> TYPE_TEMPLATES = new HashMap<>();
private final Map<String, Type<?>> TYPES;
private final int versionKey;
private final String name;
Expand All @@ -39,9 +39,9 @@ public Schema(final int versionKey, final Schema parent) {
}

protected Map<String, Type<?>> buildTypes() {
final Map<String, Type<?>> types = Maps.newHashMap();
final Map<String, Type<?>> types = new HashMap<>();

final List<TypeTemplate> templates = Lists.newArrayList();
final List<TypeTemplate> templates = new ArrayList<>();

for (final Object2IntMap.Entry<String> entry : RECURSIVE_TYPES.object2IntEntrySet()) {
templates.add(DSL.check(entry.getKey(), entry.getIntValue(), getTemplate(entry.getKey())));
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/com/mojang/datafixers/types/Type.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// Licensed under the MIT license.
package com.mojang.datafixers.types;

import com.google.common.collect.Maps;
import com.mojang.datafixers.DSL;
import com.mojang.datafixers.DataFixUtils;
import com.mojang.datafixers.Dynamic;
Expand All @@ -23,18 +22,19 @@
import com.mojang.datafixers.types.templates.TypeTemplate;
import com.mojang.datafixers.util.Either;
import com.mojang.datafixers.util.Pair;
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;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.atomic.AtomicReference;

public abstract class Type<A> implements App<Type.Mu, A> {
private static final Map<Triple<Type<?>, TypeRewriteRule, PointFreeRule>, CompletableFuture<Optional<? extends RewriteResult<?, ?>>>> PENDING_REWRITE_CACHE = Maps.newConcurrentMap();
private static final Map<Triple<Type<?>, TypeRewriteRule, PointFreeRule>, Optional<? extends RewriteResult<?, ?>>> REWRITE_CACHE = Maps.newConcurrentMap();
private static final Map<Triple<Type<?>, TypeRewriteRule, PointFreeRule>, CompletableFuture<Optional<? extends RewriteResult<?, ?>>>> PENDING_REWRITE_CACHE = new ConcurrentHashMap<>();
private static final Map<Triple<Type<?>, TypeRewriteRule, PointFreeRule>, Optional<? extends RewriteResult<?, ?>>> REWRITE_CACHE = new ConcurrentHashMap<>();

public static class Mu implements K1 {}

Expand Down
Loading