Skip to content
1 change: 0 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ dependencies {

compileOnlyApi 'com.google.code.findbugs:jsr305:3.0.2'
implementation 'org.slf4j:slf4j-api:1.8.0-beta4'
implementation 'org.apache.commons:commons-lang3:3.12.0'

testImplementation 'junit:junit-dep:4.10'
testImplementation "org.slf4j:slf4j-simple:1.8.0-beta4"
Expand Down
12 changes: 6 additions & 6 deletions src/main/java/com/mojang/datafixers/DSL.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// 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.schemas.Schema;
import com.mojang.datafixers.types.Func;
import com.mojang.datafixers.types.Type;
Expand All @@ -22,13 +22,13 @@
import com.mojang.datafixers.types.templates.TypeTemplate;
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.serialization.Codec;
import com.mojang.serialization.Dynamic;
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;

Expand Down Expand Up @@ -155,7 +155,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 @@ -200,7 +200,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, ? extends 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 @@ -447,6 +447,6 @@ final class Instances {

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

private static final Map<Triple<String, Type<?>, Map<?, ? extends Type<?>>>, Type<? extends Pair<?, ?>>> TAGGED_CHOICE_TYPE_CACHE = Maps.newConcurrentMap();
private static final Map<Triple<String, Type<?>, Map<?, ? extends Type<?>>>, Type<? extends Pair<?, ?>>> TAGGED_CHOICE_TYPE_CACHE = new ConcurrentHashMap<>();
}
}
5 changes: 2 additions & 3 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 @@ -26,7 +25,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 Expand Up @@ -69,7 +68,7 @@ public DataFixer buildOptimized(final Executor executor) {
final DataFixerUpper fixerUpper = build();

final Instant started = Instant.now();
final List<CompletableFuture<Void>> futures = Lists.newArrayList();
final List<CompletableFuture<Void>> futures = new ArrayList<>();

final IntBidirectionalIterator iterator = fixerUpper.fixerVersions().iterator();
while (iterator.hasNext()) {
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 com.mojang.datafixers.functions.PointFreeRule;
import com.mojang.datafixers.schemas.Schema;
import com.mojang.datafixers.types.Type;
Expand All @@ -17,6 +16,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.ArrayList;
import java.util.List;

/*
Expand Down Expand Up @@ -123,7 +123,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
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
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.kinds.App;
import com.mojang.datafixers.kinds.App2;
Expand All @@ -27,6 +26,7 @@
import com.mojang.datafixers.util.Pair;

import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
Expand Down Expand Up @@ -205,7 +205,7 @@ public static <A, B> TypedOptic<List<A>, List<B>, A, B> list(final Type<A> aType
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.families.Algebra;
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.Type;
import com.mojang.serialization.DynamicOps;
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
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
package com.mojang.datafixers.functions;

import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;
import com.mojang.datafixers.DSL;
import com.mojang.datafixers.DataFixUtils;
import com.mojang.datafixers.RewriteResult;
Expand All @@ -20,8 +19,8 @@
import com.mojang.datafixers.types.families.RecursiveTypeFamily;
import com.mojang.datafixers.util.Either;
import com.mojang.datafixers.util.Pair;
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 @@ -392,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 @@ -439,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 @@ -453,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
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
12 changes: 6 additions & 6 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.FieldFinder;
Expand All @@ -22,22 +21,23 @@
import com.mojang.datafixers.types.templates.TypeTemplate;
import com.mojang.datafixers.util.Either;
import com.mojang.datafixers.util.Pair;
import com.mojang.datafixers.util.Triple;
import com.mojang.datafixers.util.ValueHolder;
import com.mojang.serialization.Codec;
import com.mojang.serialization.DataResult;
import com.mojang.serialization.Dynamic;
import com.mojang.serialization.DynamicOps;
import org.apache.commons.lang3.mutable.MutableObject;
import org.apache.commons.lang3.tuple.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;

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 Expand Up @@ -178,7 +178,7 @@ private <T, B> DataResult<T> capWrite(final DynamicOps<T> ops, final Type<?> exp
return (Optional<RewriteResult<A, ?>>) rewrite;
}
// TODO: AtomicReference.getPlain/setPlain in java9+
final MutableObject<CompletableFuture<Optional<? extends RewriteResult<?, ?>>>> ref = new MutableObject<>();
final ValueHolder<CompletableFuture<Optional<? extends RewriteResult<?, ?>>>> ref = new ValueHolder<>(null);

final CompletableFuture<Optional<? extends RewriteResult<?, ?>>> pending = PENDING_REWRITE_CACHE.computeIfAbsent(key, k -> {
final CompletableFuture<Optional<? extends RewriteResult<?, ?>>> value = new CompletableFuture<>();
Expand Down
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.families;

import com.google.common.collect.Lists;
import com.mojang.datafixers.DataFixUtils;
import com.mojang.datafixers.FamilyOptic;
import com.mojang.datafixers.OpticParts;
Expand All @@ -23,6 +22,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;
Expand Down Expand Up @@ -112,7 +112,7 @@ public RecursivePoint.RecursivePointType<?> apply(final int index) {
public <A, B> Either<TypedOptic<?, ?, A, B>, Type.FieldNotFoundException> findType(final int index, final Type<A> aType, final Type<B> bType, final Type.TypeMatcher<A, B> matcher, final boolean recurse) {
return apply(index).unfold().findType(aType, bType, matcher, false).flatMap(optic -> {
final TypeTemplate nc = optic.tType().template();
final List<FamilyOptic<A, B>> fo = Lists.newArrayList();
final List<FamilyOptic<A, B>> fo = new ArrayList<>();
final RecursiveTypeFamily newFamily = new RecursiveTypeFamily(name, nc);

final RecursivePoint.RecursivePointType<?> sType = apply(index);
Expand Down Expand Up @@ -152,7 +152,7 @@ private <S, T, A, B> TypedOptic<S, T, A, B> mkOptic(final Type<S> sType, final T
final RecursivePoint.RecursivePointType<?> newType = buildMuType(sourceView.view().newType(), null);
final RecursiveTypeFamily newFamily = newType.family();

final List<RewriteResult<?, ?>> views = Lists.newArrayList();
final List<RewriteResult<?, ?>> views = new ArrayList<>();
boolean foundAny = false;
// FB -> B
for (int i = 0; i < size; i++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.DSL;
import com.mojang.datafixers.DataFixUtils;
Expand All @@ -26,6 +25,7 @@
import com.mojang.serialization.DynamicOps;

import javax.annotation.Nullable;
import java.util.HashSet;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
Expand Down Expand Up @@ -56,7 +56,7 @@ public <A, B> FamilyOptic<A, B> applyO(final FamilyOptic<A, B> input, final Type
return TypeFamily.familyOptic(
i -> {
final OpticParts<A, B> optic = element.applyO(input, aType, bType).apply(i);
final Set<TypeToken<? extends K1>> bounds = Sets.newHashSet(optic.bounds());
final Set<TypeToken<? extends K1>> bounds = new HashSet<>(optic.bounds());
bounds.add(TraversalP.Mu.TYPE_TOKEN);
return new OpticParts<>(bounds, cap(optic.optic()));
}
Expand Down
Loading