Skip to content

Commit

Permalink
Use interfaces instead of implementations where possible for local va…
Browse files Browse the repository at this point in the history
…riables.

Signed-off-by: Craig P. Motlin <cmotlin@gmail.com>
  • Loading branch information
motlin committed May 11, 2022
1 parent e8f86ea commit 71aa9f9
Show file tree
Hide file tree
Showing 78 changed files with 298 additions and 262 deletions.
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021 Goldman Sachs.
* Copyright (c) 2022 Goldman Sachs and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* and Eclipse Distribution License v. 1.0 which accompany this distribution.
Expand Down Expand Up @@ -291,7 +291,7 @@ public void testForEachWithException()
public void testForEachWithIndexToArrayUsingFastListSerialPath()
{
Integer[] array = new Integer[200];
FastList<Integer> list = (FastList<Integer>) Interval.oneTo(200).toList();
MutableList<Integer> list = new FastList<>(Interval.oneTo(200));
Assert.assertTrue(ArrayIterate.allSatisfy(array, Predicates.isNull()));
FJIterate.forEachWithIndex(list, (each, index) -> array[index] = each);
Assert.assertArrayEquals(array, list.toArray(new Integer[]{}));
Expand All @@ -301,7 +301,7 @@ public void testForEachWithIndexToArrayUsingFastListSerialPath()
public void testForEachWithIndexToArrayUsingFastList()
{
Integer[] array = new Integer[200];
FastList<Integer> list = (FastList<Integer>) Interval.oneTo(200).toList();
MutableList<Integer> list = new FastList<>(Interval.oneTo(200));
Assert.assertTrue(ArrayIterate.allSatisfy(array, Predicates.isNull()));
FJIterate.forEachWithIndex(list, (each, index) -> array[index] = each, 10, 10);
Assert.assertArrayEquals(array, list.toArray(new Integer[]{}));
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021 Goldman Sachs.
* Copyright (c) 2022 Goldman Sachs and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* and Eclipse Distribution License v. 1.0 which accompany this distribution.
Expand Down Expand Up @@ -297,7 +297,7 @@ public void testForEachWithException()
public void testForEachWithIndexToArrayUsingFastListSerialPath()
{
Integer[] array = new Integer[200];
FastList<Integer> list = (FastList<Integer>) Interval.oneTo(200).toList();
MutableList<Integer> list = new FastList<>(Interval.oneTo(200));
Assert.assertTrue(ArrayIterate.allSatisfy(array, Predicates.isNull()));
ParallelIterate.forEachWithIndex(list, (each, index) -> array[index] = each);
Assert.assertArrayEquals(array, list.toArray(new Integer[]{}));
Expand All @@ -307,7 +307,7 @@ public void testForEachWithIndexToArrayUsingFastListSerialPath()
public void testForEachWithIndexToArrayUsingFastList()
{
Integer[] array = new Integer[200];
FastList<Integer> list = (FastList<Integer>) Interval.oneTo(200).toList();
MutableList<Integer> list = new FastList<>(Interval.oneTo(200));
Assert.assertTrue(ArrayIterate.allSatisfy(array, Predicates.isNull()));
ParallelIterate.forEachWithIndex(list, (each, index) -> array[index] = each, 10, 10);
Assert.assertArrayEquals(array, list.toArray(new Integer[]{}));
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021 Goldman Sachs.
* Copyright (c) 2022 Goldman Sachs and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* and Eclipse Distribution License v. 1.0 which accompany this distribution.
Expand All @@ -21,6 +21,7 @@

import org.eclipse.collections.api.list.MutableList;
import org.eclipse.collections.api.set.MutableSet;
import org.eclipse.collections.api.set.Pool;
import org.eclipse.collections.impl.CollidingInt;
import org.eclipse.collections.impl.block.factory.Procedures;
import org.eclipse.collections.impl.factory.Lists;
Expand Down Expand Up @@ -789,7 +790,7 @@ private void runUnifiedSetAsPool(int shift)
{
CollidingInt[] toPool = new CollidingInt[5000];

UnifiedSet<CollidingInt> set = new UnifiedSet<>();
Pool<CollidingInt> set = new UnifiedSet<>();

for (int i = 0; i < toPool.length; i++)
{
Expand Down Expand Up @@ -842,7 +843,7 @@ private void runUnifiedSetAsPoolRandomInput(int shift)

toPool = shuffle(toPool);

UnifiedSet<CollidingInt> set = new UnifiedSet<>();
Pool<CollidingInt> set = new UnifiedSet<>();
for (int i = 0; i < toPool.length; i++)
{
Assert.assertSame(toPool[i], set.put(toPool[i]));
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021 Goldman Sachs and others.
* Copyright (c) 2022 Goldman Sachs and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* and Eclipse Distribution License v. 1.0 which accompany this distribution.
Expand All @@ -23,6 +23,7 @@
import org.eclipse.collections.codegenerator.tools.FileUtils;
import org.eclipse.collections.codegenerator.tools.IntegerOrStringRenderer;
import org.stringtemplate.v4.ST;
import org.stringtemplate.v4.STErrorListener;
import org.stringtemplate.v4.STGroupFile;

public class EclipseCollectionsCodeGenerator
Expand Down Expand Up @@ -67,7 +68,7 @@ public int generateFiles()
continue;
}

LoggingErrorListener stErrorListener = new LoggingErrorListener(this.errorListener, url);
STErrorListener stErrorListener = new LoggingErrorListener(this.errorListener, url);

templateFile.setListener(stErrorListener);
templateFile.registerRenderer(String.class, new IntegerOrStringRenderer());
Expand Down
Expand Up @@ -111,8 +111,8 @@ public static <T, PT extends ObjectIntProcedure<? super T>> void forEachWithInde
PT procedure,
ForkJoinPool executor)
{
PassThruObjectIntProcedureFactory<PT> procedureFactory = new PassThruObjectIntProcedureFactory<>(procedure);
PassThruCombiner<PT> combiner = new PassThruCombiner<>();
ObjectIntProcedureFactory<PT> procedureFactory = new PassThruObjectIntProcedureFactory<>(procedure);
Combiner<PT> combiner = new PassThruCombiner<>();
FJIterate.forEachWithIndex(iterable, procedureFactory, combiner, executor);
}

Expand All @@ -131,8 +131,8 @@ public static <T, PT extends ObjectIntProcedure<? super T>> void forEachWithInde
int minForkSize,
int taskCount)
{
PassThruObjectIntProcedureFactory<PT> procedureFactory = new PassThruObjectIntProcedureFactory<>(procedure);
PassThruCombiner<PT> combiner = new PassThruCombiner<>();
ObjectIntProcedureFactory<PT> procedureFactory = new PassThruObjectIntProcedureFactory<>(procedure);
Combiner<PT> combiner = new PassThruCombiner<>();
FJIterate.forEachWithIndex(iterable, procedureFactory, combiner, minForkSize, taskCount);
}

Expand Down Expand Up @@ -269,8 +269,8 @@ public static <T, PT extends Procedure<? super T>> void forEach(
PT procedure,
ForkJoinPool executor)
{
PassThruProcedureFactory<PT> procedureFactory = new PassThruProcedureFactory<>(procedure);
PassThruCombiner<PT> combiner = new PassThruCombiner<>();
ProcedureFactory<PT> procedureFactory = new PassThruProcedureFactory<>(procedure);
Combiner<PT> combiner = new PassThruCombiner<>();
FJIterate.forEach(iterable, procedureFactory, combiner, executor);
}

Expand Down Expand Up @@ -298,8 +298,8 @@ public static <T, PT extends Procedure<? super T>> void forEach(
int taskCount,
ForkJoinPool executor)
{
PassThruProcedureFactory<PT> procedureFactory = new PassThruProcedureFactory<>(procedure);
PassThruCombiner<PT> combiner = new PassThruCombiner<>();
ProcedureFactory<PT> procedureFactory = new PassThruProcedureFactory<>(procedure);
Combiner<PT> combiner = new PassThruCombiner<>();
FJIterate.forEach(iterable, procedureFactory, combiner, minForkSize, taskCount, executor);
}

Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021 Goldman Sachs.
* Copyright (c) 2022 Goldman Sachs and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* and Eclipse Distribution License v. 1.0 which accompany this distribution.
Expand Down Expand Up @@ -277,7 +277,7 @@ public void testForEachWithException()
public void testForEachWithIndexToArrayUsingFastListSerialPath()
{
Integer[] array = new Integer[200];
FastList<Integer> list = (FastList<Integer>) Interval.oneTo(200).toList();
MutableList<Integer> list = new FastList<>(Interval.oneTo(200));
Assert.assertTrue(ArrayIterate.allSatisfy(array, Predicates.isNull()));
FJIterate.forEachWithIndex(list, (each, index) -> array[index] = each);
Assert.assertArrayEquals(array, list.toArray(new Integer[]{}));
Expand All @@ -287,7 +287,7 @@ public void testForEachWithIndexToArrayUsingFastListSerialPath()
public void testForEachWithIndexToArrayUsingFastList()
{
Integer[] array = new Integer[200];
FastList<Integer> list = (FastList<Integer>) Interval.oneTo(200).toList();
MutableList<Integer> list = new FastList<>(Interval.oneTo(200));
Assert.assertTrue(ArrayIterate.allSatisfy(array, Predicates.isNull()));
FJIterate.forEachWithIndex(list, (each, index) -> array[index] = each, 10, 10);
Assert.assertArrayEquals(array, list.toArray(new Integer[]{}));
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021 Goldman Sachs.
* Copyright (c) 2022 Goldman Sachs and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* and Eclipse Distribution License v. 1.0 which accompany this distribution.
Expand All @@ -13,7 +13,9 @@
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectInputStream;
import java.io.ObjectOutput;
import java.io.ObjectOutputStream;

public final class SerializeTestHelper
Expand Down Expand Up @@ -51,7 +53,7 @@ public static <T> ByteArrayOutputStream getByteArrayOutputStream(T sourceObject)

private static <T> void writeObjectToStream(Object sourceObject, ByteArrayOutputStream baos) throws IOException
{
try (ObjectOutputStream objectOutputStream = new ObjectOutputStream(baos))
try (ObjectOutput objectOutputStream = new ObjectOutputStream(baos))
{
objectOutputStream.writeObject(sourceObject);
objectOutputStream.flush();
Expand All @@ -62,7 +64,7 @@ private static <T> void writeObjectToStream(Object sourceObject, ByteArrayOutput
private static Object readOneObject(ByteArrayInputStream bais)
throws IOException, ClassNotFoundException
{
try (ObjectInputStream objectStream = new ObjectInputStream(bais))
try (ObjectInput objectStream = new ObjectInputStream(bais))
{
return objectStream.readObject();
}
Expand Down
Expand Up @@ -15,6 +15,7 @@
import java.io.IOException;
import java.io.NotSerializableException;
import java.io.ObjectInputStream;
import java.io.ObjectOutput;
import java.io.ObjectOutputStream;
import java.io.ObjectStreamClass;
import java.io.Serializable;
Expand Down Expand Up @@ -3356,7 +3357,7 @@ private static String encodeObject(Object actualObject)
try
{
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
ObjectOutputStream objectOutputStream = new ObjectOutputStream(byteArrayOutputStream);
ObjectOutput objectOutputStream = new ObjectOutputStream(byteArrayOutputStream);
objectOutputStream.writeObject(actualObject);
objectOutputStream.flush();
objectOutputStream.close();
Expand Down
Expand Up @@ -602,14 +602,14 @@ public String toString()
@Override
public void appendString(Appendable appendable, String separator)
{
AppendStringProcedure<T> appendStringProcedure = new AppendStringProcedure<>(appendable, separator);
Procedure<T> appendStringProcedure = new AppendStringProcedure<>(appendable, separator);
this.forEach(appendStringProcedure);
}

@Override
public void appendString(Appendable appendable, String start, String separator, String end)
{
AppendStringProcedure<T> appendStringProcedure = new AppendStringProcedure<>(appendable, separator);
Procedure<T> appendStringProcedure = new AppendStringProcedure<>(appendable, separator);
try
{
appendable.append(start);
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021 Goldman Sachs.
* Copyright (c) 2022 Goldman Sachs and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* and Eclipse Distribution License v. 1.0 which accompany this distribution.
Expand All @@ -17,6 +17,7 @@
import org.eclipse.collections.api.block.function.Function;
import org.eclipse.collections.api.block.predicate.Predicate;
import org.eclipse.collections.api.block.procedure.Procedure;
import org.eclipse.collections.api.map.ConcurrentMutableMap;
import org.eclipse.collections.api.map.MapIterable;
import org.eclipse.collections.api.multimap.set.UnsortedSetMultimap;
import org.eclipse.collections.api.set.ParallelUnsortedSetIterable;
Expand Down Expand Up @@ -66,7 +67,7 @@ public ParallelUnsortedSetIterable<T> asUnique()
public void forEach(Procedure<? super T> procedure)
{
// TODO: Replace the map with a concurrent set once it's implemented
ConcurrentHashMap<T, Boolean> distinct = new ConcurrentHashMap<>();
ConcurrentMutableMap<T, Boolean> distinct = new ConcurrentHashMap<>();
this.delegate.forEach(each -> {
if (distinct.put(each, true) == null)
{
Expand Down Expand Up @@ -131,7 +132,7 @@ public <V> MapIterable<V, T> groupByUniqueKey(Function<? super T, ? extends V> f
private static final class DistinctAndPredicate<T> implements Predicate<T>
{
// TODO: Replace the map with a concurrent set once it's implemented
private final ConcurrentHashMap<T, Boolean> distinct = new ConcurrentHashMap<>();
private final ConcurrentMutableMap<T, Boolean> distinct = new ConcurrentHashMap<>();
private final Predicate<? super T> predicate;

private DistinctAndPredicate(Predicate<? super T> predicate)
Expand All @@ -149,7 +150,7 @@ public boolean accept(T each)
private static final class DistinctOrPredicate<T> implements Predicate<T>
{
// TODO: Replace the map with a concurrent set once it's implemented
private final ConcurrentHashMap<T, Boolean> distinct = new ConcurrentHashMap<>();
private final ConcurrentMutableMap<T, Boolean> distinct = new ConcurrentHashMap<>();
private final Predicate<? super T> predicate;

private DistinctOrPredicate(Predicate<? super T> predicate)
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021 Goldman Sachs.
* Copyright (c) 2022 Goldman Sachs and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* and Eclipse Distribution License v. 1.0 which accompany this distribution.
Expand All @@ -17,6 +17,7 @@
import org.eclipse.collections.api.block.function.Function;
import org.eclipse.collections.api.block.predicate.Predicate;
import org.eclipse.collections.api.block.procedure.Procedure;
import org.eclipse.collections.api.map.ConcurrentMutableMap;
import org.eclipse.collections.api.map.MapIterable;
import org.eclipse.collections.api.multimap.set.UnsortedSetMultimap;
import org.eclipse.collections.api.set.ParallelUnsortedSetIterable;
Expand Down Expand Up @@ -65,7 +66,7 @@ public ParallelUnsortedSetIterable<T> asUnique()
public void forEach(Procedure<? super T> procedure)
{
// TODO: Replace the map with a concurrent set once it's implemented
ConcurrentHashMap<T, Boolean> distinct = new ConcurrentHashMap<>();
ConcurrentMutableMap<T, Boolean> distinct = new ConcurrentHashMap<>();
this.delegate.forEach(each -> {
if (distinct.put(each, true) == null)
{
Expand Down Expand Up @@ -130,7 +131,7 @@ public <V> MapIterable<V, T> groupByUniqueKey(Function<? super T, ? extends V> f
private static final class DistinctAndPredicate<T> implements Predicate<T>
{
// TODO: Replace the map with a concurrent set once it's implemented
private final ConcurrentHashMap<T, Boolean> distinct = new ConcurrentHashMap<>();
private final ConcurrentMutableMap<T, Boolean> distinct = new ConcurrentHashMap<>();
private final Predicate<? super T> predicate;

private DistinctAndPredicate(Predicate<? super T> predicate)
Expand All @@ -148,7 +149,7 @@ public boolean accept(T each)
private static final class DistinctOrPredicate<T> implements Predicate<T>
{
// TODO: Replace the map with a concurrent set once it's implemented
private final ConcurrentHashMap<T, Boolean> distinct = new ConcurrentHashMap<>();
private final ConcurrentMutableMap<T, Boolean> distinct = new ConcurrentHashMap<>();
private final Predicate<? super T> predicate;

private DistinctOrPredicate(Predicate<? super T> predicate)
Expand Down
Expand Up @@ -658,23 +658,23 @@ public <T, R extends Collection<T>> R collect(
Function<? super Integer, ? extends T> function,
R target)
{
CollectProcedure<Integer, T> procedure = new CollectProcedure<>(function, target);
Procedure<Integer> procedure = new CollectProcedure<>(function, target);
this.forEach(procedure);
return target;
}

@Override
public <R extends Collection<Integer>> R select(Predicate<? super Integer> predicate, R target)
{
SelectProcedure<Integer> procedure = new SelectProcedure<>(predicate, target);
Procedure<Integer> procedure = new SelectProcedure<>(predicate, target);
this.forEach(procedure);
return target;
}

@Override
public <R extends Collection<Integer>> R reject(Predicate<? super Integer> predicate, R target)
{
RejectProcedure<Integer> procedure = new RejectProcedure<>(predicate, target);
Procedure<Integer> procedure = new RejectProcedure<>(predicate, target);
this.forEach(procedure);
return target;
}
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021 Goldman Sachs.
* Copyright (c) 2022 Goldman Sachs and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* and Eclipse Distribution License v. 1.0 which accompany this distribution.
Expand Down Expand Up @@ -396,7 +396,7 @@ public ImmutableBooleanArrayList toReversed()
@Override
public ImmutableBooleanList distinct()
{
BooleanArrayList target = new BooleanArrayList();
MutableBooleanList target = new BooleanArrayList();
MutableBooleanSet seenSoFar = new BooleanHashSet();
for (int i = 0; i < this.size; i++)
{
Expand Down
Expand Up @@ -754,7 +754,7 @@ public BooleanArrayList toReversed()
@Override
public MutableBooleanList distinct()
{
BooleanArrayList target = new BooleanArrayList();
MutableBooleanList target = new BooleanArrayList();
MutableBooleanSet seenSoFar = new BooleanHashSet();
for (int i = 0; i < this.size; i++)
{
Expand Down
Expand Up @@ -1214,7 +1214,7 @@ public void safeValue(T object) throws IOException
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
{
int size = in.readInt();
FastList<T> deserializedDelegate = new FastList<>(size);
MutableList<T> deserializedDelegate = new FastList<>(size);

for (int i = 0; i < size; i++)
{
Expand All @@ -1230,4 +1230,3 @@ protected Object readResolve()
}
}
}

0 comments on commit 71aa9f9

Please sign in to comment.