Commit f52df776 authored by Lubomir Bulej's avatar Lubomir Bulej

Remove legacy utility classes that did not carry their weight anymore.

The utility classes made life simpler prior to Java 8, but their usage
was reduced to in-place initialization of collections, for which the
pattern of new CollectionType <> (Arrays.asList (...)) can be endured.

The users of the utility classes were updated to cope without them.
parent 918d9701
package ch.usi.dag.disl.processor.generator;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import ch.usi.dag.disl.snippet.Shadow;
import ch.usi.dag.util.Maps;
public class PIResolver {
private final Map <ResolverKey, ProcInstance> piStore = Maps.newHashMap ();
private final Map <ResolverKey, ProcInstance> piStore = new HashMap <> ();
//
......
......@@ -2,7 +2,10 @@ package ch.usi.dag.disl.tools;
import java.io.FileNotFoundException;
import java.io.PrintStream;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.Set;
import javax.annotation.processing.Completion;
......@@ -26,7 +29,6 @@ import ch.usi.dag.disl.annotation.Before;
import ch.usi.dag.disl.annotation.Guarded;
import ch.usi.dag.disl.annotation.ProcessAlso;
import ch.usi.dag.disl.annotation.SyntheticLocal;
import ch.usi.dag.util.Sets;
/**
......@@ -53,7 +55,7 @@ public final class DislClassFinder implements Processor {
//
private String __effectiveSeparator;
private final Set <String> __dislClasses = Sets.newHashSet ();
private final Set <String> __dislClasses = new HashSet <> ();
//
......@@ -62,7 +64,7 @@ public final class DislClassFinder implements Processor {
private static final String __OPTION_FORCE_EOL__ = "disl.classfinder.force-eol";
private static final Set <String> __options__ = Collections.unmodifiableSet (
Sets.newHashSet (__OPTION_OUTPUT__, __OPTION_SEPARATOR__)
new HashSet <> (Arrays.asList (__OPTION_OUTPUT__, __OPTION_SEPARATOR__))
);
@Override
......@@ -80,7 +82,7 @@ public final class DislClassFinder implements Processor {
@Override
public Set <String> getSupportedAnnotationTypes () {
final Set <String> result = Sets.newLinkedHashSet ();
final Set <String> result = new LinkedHashSet <> ();
for (final Class <?> annotationClass : __annotations__) {
result.add (annotationClass.getName ());
}
......@@ -153,7 +155,7 @@ public final class DislClassFinder implements Processor {
// The annotations may be processed in multiple rounds. Collect
// DiSL classes in each round and only report those not seen before.
//
final Set <String> newClasses = Sets.newHashSet ();
final Set <String> newClasses = new HashSet <> ();
for (final TypeElement te : annotations) {
for (final Element e : env.getElementsAnnotatedWith (te)) {
......
......@@ -6,10 +6,10 @@ import static org.junit.Assert.assertTrue;
import java.io.File;
import java.io.IOException;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
import ch.usi.dag.util.Duration;
import ch.usi.dag.util.Lists;
public class ClientEvaluationRunner extends Runner {
......@@ -61,10 +61,10 @@ public class ClientEvaluationRunner extends Runner {
private Job __startShadow (
final File instJar, final File statusFile
) throws IOException {
final List <String> command = Lists.newLinkedList (
final List <String> command = new LinkedList <> (Arrays.asList (
__SHADOW_JAVA_COMMAND__, "-Xms1G", "-Xmx2G",
"-classpath", Runner.classPath (_SHVM_SERVER_JAR_, instJar)
);
));
if (statusFile != null) {
command.add (String.format (
......@@ -82,13 +82,13 @@ public class ClientEvaluationRunner extends Runner {
private Job __startClient (
final File instJar, final File appJar
) throws IOException {
final List <String> command = Lists.newLinkedList (
final List <String> command = new LinkedList <> (Arrays.asList (
__CLIENT_JAVA_COMMAND__,
String.format ("-agentpath:%s", _SHVM_AGENT_LIB_),
String.format ("-Xbootclasspath/a:%s", Runner.classPath (
_SHVM_DISPATCH_JAR_, instJar
))
);
));
command.addAll (propertiesStartingWith ("disl."));
command.addAll (Arrays.asList (
......
......@@ -6,10 +6,10 @@ import static org.junit.Assert.assertTrue;
import java.io.File;
import java.io.IOException;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
import ch.usi.dag.util.Duration;
import ch.usi.dag.util.Lists;
public class ClientServerEvaluationRunner extends Runner {
......@@ -76,10 +76,10 @@ public class ClientServerEvaluationRunner extends Runner {
private Job __startServer (
final File instJar, final File statusFile
) throws IOException {
final List <String> command = Lists.newLinkedList (
final List <String> command = new LinkedList <> (Arrays.asList (
__SERVER_JAVA_COMMAND__,
"-classpath", Runner.classPath (_DISL_SERVER_JAR_, instJar)
);
));
if (statusFile != null) {
command.add (String.format (
......@@ -98,10 +98,10 @@ public class ClientServerEvaluationRunner extends Runner {
private Job __startShadow (
final File instJar, final File statusFile
) throws IOException {
final List <String> command = Lists.newLinkedList (
final List <String> command = new LinkedList <> (Arrays.asList (
__SHADOW_JAVA_COMMAND__, "-Xms1G", "-Xmx2G",
"-classpath", Runner.classPath (_SHVM_SERVER_JAR_, instJar)
);
));
if (statusFile != null) {
command.add (String.format (
......@@ -119,14 +119,14 @@ public class ClientServerEvaluationRunner extends Runner {
private Job __startClient (
final File instJar, final File appJar
) throws IOException {
final List <String> command = Lists.newLinkedList (
final List <String> command = new LinkedList <> (Arrays.asList (
__CLIENT_JAVA_COMMAND__,
String.format ("-agentpath:%s", _DISL_AGENT_LIB_),
String.format ("-agentpath:%s", _SHVM_AGENT_LIB_),
String.format ("-Xbootclasspath/a:%s", Runner.classPath (
_DISL_BYPASS_JAR_, _SHVM_DISPATCH_JAR_, instJar
))
);
));
command.addAll (propertiesStartingWith ("disl."));
command.addAll (Arrays.asList (
......
......@@ -6,10 +6,10 @@ import static org.junit.Assert.assertTrue;
import java.io.File;
import java.io.IOException;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
import ch.usi.dag.util.Duration;
import ch.usi.dag.util.Lists;
public class ClientServerRunner extends Runner {
......@@ -60,10 +60,10 @@ public class ClientServerRunner extends Runner {
private Job __startServer (
final File testInstJar, final File statusFile
) throws IOException {
final List <String> command = Lists.newLinkedList (
final List <String> command = new LinkedList <> (Arrays.asList (
__SERVER_JAVA_COMMAND__,
"-classpath", Runner.classPath (_DISL_SERVER_JAR_, testInstJar)
);
));
if (statusFile != null) {
command.add (String.format (
......@@ -84,13 +84,13 @@ public class ClientServerRunner extends Runner {
private Job __startClient (
final File testInstJar, final File testAppJar
) throws IOException {
final List <String> command = Lists.newLinkedList (
final List <String> command = new LinkedList <> (Arrays.asList (
__CLIENT_JAVA_COMMAND__,
String.format ("-agentpath:%s", _DISL_AGENT_LIB_),
String.format ("-Xbootclasspath/a:%s", Runner.classPath (
_DISL_BYPASS_JAR_, testInstJar
))
);
));
command.addAll (propertiesStartingWith ("disl."));
command.addAll (Arrays.asList (
......
package ch.usi.dag.util;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
/**
* Utility class providing generic static factory methods for creating instances
* of {@link List} collection types. The factory methods rely on type inference
* to determine the type parameters needed for constructing a specific instance.
*
* @author Lubomir Bulej
*/
public final class Lists {
private Lists () {
// pure static class - not to be instantiated
}
/* ***********************************************************************
* ArrayList
* ***********************************************************************/
/**
* Creates a new instance of a generic {@link ArrayList}.
*
* @param <E>
* element type, inferred from the result type
* @return
* new {@link ArrayList} instance
*/
public static <E> ArrayList <E> newArrayList () {
return new ArrayList <E> ();
}
/**
* Creates a new instance of a generic {@link ArrayList} with a given
* initial capacity.
*
* @param <E>
* element type, inferred from the result type
* @param initialCapacity
* the initial capacity of the list
* @return
* new {@link ArrayList} instance
* @throws IllegalArgumentException
* if the specified initial capacity is negative
*/
public static <E> ArrayList <E> newArrayList (final int initialCapacity) {
return new ArrayList <E> (initialCapacity);
}
/**
* Creates a new instance of a generic {@link ArrayList} and fills it
* {@code elements} from the given array.
*
* @param <E>
* element type, inferred from the result type
* @param elements
* the elements to put into the list
* @return
* new {@link ArrayList} instance
*/
public static <E> ArrayList <E> newArrayList (final E ... elements) {
Assert.objectNotNull (elements, "elements");
//
return __addAllToList (elements, new ArrayList <E> (elements.length));
}
/**
* Creates a new instance of a generic {@link ArrayList} and fills it with
* {@code elements} from the given {@link Collection}.
*
* @param <E>
* element type, inferred from the result type
* @param elements
* the elements to put into the list
* @return
* new {@link ArrayList} instance of appropriate type
*/
public static <E> ArrayList <E> newArrayList (
final Collection <? extends E> elements
) {
Assert.objectNotNull (elements, "elements");
//
return new ArrayList <E> (elements);
}
/**
* Creates a new instance of a generic {@link ArrayList} and fills it with
* {@code elements} from the given {@link Iterable}.
*
* @param <E>
* element type, inferred from the result type
* @param elements
* the elements to put into the list
* @return
* new {@link ArrayList} instance
*/
public static <E> ArrayList <E> newArrayList (
final Iterable <? extends E> elements
) {
Assert.objectNotNull (elements, "elements");
//
final ArrayList <E> result = new ArrayList <E> ();
for (final E item : elements) {
result.add (item);
}
return result;
}
/**
* Creates a new instance of a generic {@link ArrayList} and fills it with
* elements from the given collections.
*
* @param <E>
* element type, inferred from the result type
* @param collections
* the collections of elements to put into the list
* @return
* new {@link ArrayList} instance
*/
public static <E> List <E> newArrayList (
final Collection <? extends E> ... collections
) {
Assert.objectNotNull (collections, "collections");
//
final int collectionCount = collections.length;
if (collectionCount > 0) {
//
// Aggregate collection sizes to determine the size of the
// resulting ArrayList to avoid reallocations, then gather
// all elements from the collections.
//
int elementCount = 0;
for (final Collection <? extends E> collection : collections) {
elementCount += collection.size ();
}
final ArrayList <E> result = new ArrayList <E> (elementCount);
for (final Collection <? extends E> collection : collections) {
result.addAll (collection);
}
return result;
} else {
return Collections.emptyList ();
}
}
/* ***********************************************************************
* LinkedList
* ***********************************************************************/
/**
* Creates a new instance of a generic {@link LinkedList}.
*
* @param <E>
* element type, inferred from the result type
* @return
* new {@link LinkedList} instance
*/
public static <E> LinkedList <E> newLinkedList () {
return new LinkedList <E> ();
}
/**
* Creates a new instance of a generic {@link LinkedList} and fills it with
* elements from the given array.
*
* @param <E>
* element type, inferred from the result type
* @param elements
* the array of elements to put into the list, may not be {@code null}
* @return
* new {@link LinkedList} instance
* @throws NullPointerException
* if the specified array is {@code null}
*/
public static <E> LinkedList <E> newLinkedList (final E ... elements) {
Assert.objectNotNull (elements, "elements");
//
return __addAllToList (elements, new LinkedList <E> ());
}
/**
* Creates a new instance of a generic {@link LinkedList} and fills it with
* elements from the given collection.
*
* @param <E>
* element type, inferred from the result type
* @param elements
* the collection of elements to put into the list, may not be
* {@code null}
* @return
* new {@link LinkedList} instance of appropriate type
* @throws NullPointerException
* if the specified collection is {@code null}
*/
public static <E> LinkedList <E> newLinkedList (
final Collection <? extends E> elements
) {
Assert.objectNotNull (elements, "elements");
//
return new LinkedList <E> (elements);
}
//
private static <E, L extends List <E>> L __addAllToList (
final E [] elements, final L result
) {
for (final E element : elements) {
result.add (element);
}
return result;
}
}
package ch.usi.dag.util;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
/**
* Utility class providing generic static factory methods for creating instances
* of {@link Map} collection types. The factory methods rely on type inference
* to determine the type parameters needed for constructing a specific instance.
*
* @author Lubomir Bulej
*/
public class Maps {
private Maps () {
// pure static class - not to be instantiated
}
/* ***********************************************************************
* HashMap
* ***********************************************************************/
/**
* Creates a new instance of a generic {@link HashMap}.
*
* @see HashMap#HashMap()
*
* @param <K>
* the type of the key
* @param <V>
* the type of the value
* @return
* new instance of HashMap <K, V>
*/
public static <K, V> HashMap <K, V> newHashMap () {
return new HashMap <K, V> ();
}
/**
* Creates a new instance of a generic {@link HashMap} using
* mappings provided by source {@link Map}.
*
* @see HashMap#HashMap(Map)
*
* @param <K>
* the type of the key
* @param <V>
* the type of the value
* @return
* new instance of HashMap <K, V>
*/
public static <K, V> HashMap <K, V> newHashMap (final Map <K, V> source) {
return new HashMap <K, V> (source);
}
/* ***********************************************************************
* LinkedHashMap
* ***********************************************************************/
/**
* Creates a new instance of a generic {@link LinkedHashMap}.
*
* @see LinkedHashMap#LinkedHashMap()
*
* @param <K>
* the type of the key
* @param <V>
* the type of the value
* @return
* new instance of LinkedHashMap <K, V>
*/
public static <K, V> LinkedHashMap <K, V> newLinkedHashMap () {
return new LinkedHashMap <K, V> ();
}
/* ***********************************************************************
* ConcurrentHashMap
* ***********************************************************************/
/**
* Creates a new instance of a generic {@link ConcurrentHashMap}.
*
* @see ConcurrentHashMap#ConcurrentHashMap()
*
* @param <K>
* the type of the key
* @param <V>
* the type of the value
* @return
* new instance of ConcurrentHashMap <K, V>
*/
public static <K, V> ConcurrentHashMap <K, V> newConcurrentHashMap () {
return new ConcurrentHashMap <K, V> ();
}
}
package ch.usi.dag.util;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.Set;
import java.util.TreeSet;
/**
* Utility class providing generic static factory methods for creating instances
* of {@link Set} collection types. The factory methods rely on type inference
* to determine the type parameters needed for constructing a specific instance.
*
* @author Lubomir Bulej
*/
public final class Sets {
private Sets () {
// pure static class - not to be instantiated
}
/* ***********************************************************************
* HashSet
* ***********************************************************************/
/**
* Creates a new instance of a generic {@link HashSet}.
*
* @param <E>
* the type of the set element
* @return
* new {@link HashSet} instance of appropriate type
*/
public static <E> HashSet <E> newHashSet () {
return new HashSet <E> ();
}
/**
* Creates a new instance of a generic {@link HashSet} and fills it
* {@code elements} from the given array.
*
* @param <E>
* element type, inferred from the result type
* @param elements
* the elements to put into the set
* @return
* new {@link HashSet} instance containing the given elements
*/
public static <E> HashSet <E> newHashSet (final E ... elements) {
Assert.objectNotNull (elements, "elements");
//
return __addAllToSet (elements, new HashSet <E> (elements.length));
}
/* ***********************************************************************
* LinkedHashSet
* ***********************************************************************/
/**
* Creates a new instance of a generic {@link LinkedHashSet}.
*
* @param <E>
* the type of the set element
* @return
* new {@link LinkedHashSet} instance of appropriate type
*/
public static <E> LinkedHashSet <E> newLinkedHashSet () {
return new LinkedHashSet <E> ();
}
/* ***********************************************************************
* TreeSet
* ***********************************************************************/
/**
* Creates a new instance of a generic {@link TreeSet}.
*
* @param <E>
* the type of the set element
* @return
* new {@link TreeSet} instance of appropriate type
*/
public static <E> TreeSet <E> newTreeSet () {
return new TreeSet <E> ();
}
//
private static <E, L extends Set <E>> L __addAllToSet (
final E [] elements, final L result
) {
for (final E element : elements) {
result.add (element);
}
return result;
}
}
package ch.usi.dag.util.logging;
import java.io.PrintStream;
import java.util.Arrays;
import java.util.EnumMap;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.ServiceLoader;
......@@ -10,8 +12,6 @@ import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicReference;
import ch.usi.dag.util.Assert;
import ch.usi.dag.util.Lists;
import ch.usi.dag.util.Maps;
/**
......@@ -380,7 +380,7 @@ public final class Logger {
* ***********************************************************************/
private static final List <String>
__providerAliases__ = Lists.newLinkedList (__PROVIDER_PROPERTY__);
__providerAliases__ = new LinkedList <> (Arrays.asList (__PROVIDER_PROPERTY__));
/**
......@@ -405,7 +405,7 @@ public final class Logger {
private static final List <String>
__levelAliases__ = Lists.newLinkedList (__LEVEL_PROPERTY__);
__levelAliases__ = new LinkedList <> (Arrays.asList (__LEVEL_PROPERTY__));
/**
......@@ -442,7 +442,7 @@ public final class Logger {
* ***********************************************************************/
private static final ConcurrentHashMap <String, Logger>
__loggers__ = Maps.newConcurrentHashMap ();
__loggers__ = new ConcurrentHashMap <> ();
public static Logger getInstance (final String name) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment