diff --git a/microsphere-java-core/src/main/java/io/microsphere/classloading/ArtifactDetector.java b/microsphere-java-core/src/main/java/io/microsphere/classloading/ArtifactDetector.java index a964ad919..189477ba9 100644 --- a/microsphere-java-core/src/main/java/io/microsphere/classloading/ArtifactDetector.java +++ b/microsphere-java-core/src/main/java/io/microsphere/classloading/ArtifactDetector.java @@ -25,6 +25,7 @@ import static io.microsphere.util.SystemUtils.JAVA_HOME; import static java.util.Collections.emptyList; import static java.util.Collections.unmodifiableList; +import static io.microsphere.collection.SetUtils.newLinkedHashSet; /** * The {@code ArtifactDetector} class is responsible for detecting and resolving artifacts from the classpath. @@ -149,7 +150,7 @@ public Artifact detect(@Nonnull URL classPathURL) { protected Set getClassPathURLs(boolean includedJdkLibraries) { Set urls = findAllClassPathURLs(classLoader); - LinkedHashSet classPathURLs = new LinkedHashSet<>(urls); + LinkedHashSet classPathURLs = newLinkedHashSet(urls); if (!includedJdkLibraries) { removeJdkClassPathURLs(classPathURLs); } diff --git a/microsphere-java-core/src/main/java/io/microsphere/classloading/BannedArtifactClassLoadingExecutor.java b/microsphere-java-core/src/main/java/io/microsphere/classloading/BannedArtifactClassLoadingExecutor.java index c571a8ee8..7048afe74 100644 --- a/microsphere-java-core/src/main/java/io/microsphere/classloading/BannedArtifactClassLoadingExecutor.java +++ b/microsphere-java-core/src/main/java/io/microsphere/classloading/BannedArtifactClassLoadingExecutor.java @@ -18,6 +18,7 @@ import static io.microsphere.util.StringUtils.isBlank; import static io.microsphere.util.StringUtils.split; import static io.microsphere.util.SystemUtils.FILE_ENCODING; +import static io.microsphere.collection.ListUtils.newLinkedList; /** * The executor for the banned artifacts that are loading by {@link ClassLoader}. @@ -94,7 +95,7 @@ public void execute() { } static List loadBannedArtifactConfigs(ClassLoader classLoader) { - LinkedList bannedArtifactConfigs = new LinkedList<>(); + LinkedList bannedArtifactConfigs = newLinkedList(); try { Enumeration configResources = classLoader.getResources(CONFIG_LOCATION); while (configResources.hasMoreElements()) { @@ -109,7 +110,7 @@ static List loadBannedArtifactConfigs(ClassLoader classLoader) { } static List loadBannedArtifactConfigs(URL configResource) throws IOException { - LinkedList bannedArtifactConfigs = new LinkedList<>(); + LinkedList bannedArtifactConfigs = newLinkedList(); try (InputStream inputStream = configResource.openStream(); BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream, ENCODING)) ) { diff --git a/microsphere-java-core/src/main/java/io/microsphere/event/AbstractEventDispatcher.java b/microsphere-java-core/src/main/java/io/microsphere/event/AbstractEventDispatcher.java index bea8ef142..7f4e865e7 100644 --- a/microsphere-java-core/src/main/java/io/microsphere/event/AbstractEventDispatcher.java +++ b/microsphere-java-core/src/main/java/io/microsphere/event/AbstractEventDispatcher.java @@ -40,6 +40,7 @@ import static io.microsphere.util.ServiceLoaderUtils.loadServicesList; import static java.util.Collections.sort; import static java.util.Collections.unmodifiableList; +import static io.microsphere.collection.ListUtils.newLinkedList; /** * Abstract implementation of {@link EventDispatcher} that provides common functionality for dispatching events to @@ -127,7 +128,7 @@ public void removeEventListener(EventListener listener) throws NullPointerExc @Override @Immutable public List> getAllEventListeners() { - LinkedList> listeners = new LinkedList<>(); + LinkedList> listeners = newLinkedList(); sortedListeners().forEach(listener -> { addIfAbsent(listeners, listener); @@ -192,7 +193,7 @@ protected void doInListener(EventListener listener, Consumer eventType, Consumer> consumer) { if (eventType != null) { synchronized (mutex) { - List listeners = listenersCache.computeIfAbsent(eventType, e -> new LinkedList<>()); + List listeners = listenersCache.computeIfAbsent(eventType, e -> newLinkedList()); // consume consumer.accept(listeners); // sort diff --git a/microsphere-java-core/src/main/java/io/microsphere/event/GenericEventListener.java b/microsphere-java-core/src/main/java/io/microsphere/event/GenericEventListener.java index 8e2d040e4..55cdff04a 100644 --- a/microsphere-java-core/src/main/java/io/microsphere/event/GenericEventListener.java +++ b/microsphere-java-core/src/main/java/io/microsphere/event/GenericEventListener.java @@ -29,6 +29,7 @@ import static io.microsphere.lang.function.ThrowableConsumer.execute; import static java.util.Collections.emptySet; import static java.util.stream.Stream.of; +import static io.microsphere.collection.SetUtils.newLinkedHashSet; /** * A generic implementation of the {@link EventListener} interface that supports multiple event handling methods. @@ -97,7 +98,7 @@ private Map, Set> findHandleEventMethods() { HashMap, Set> eventMethods = newHashMap(); of(getClass().getMethods()).filter(this::isHandleEventMethod).forEach(method -> { Class paramType = method.getParameterTypes()[0]; - Set methods = eventMethods.computeIfAbsent(paramType, key -> new LinkedHashSet<>()); + Set methods = eventMethods.computeIfAbsent(paramType, key -> newLinkedHashSet()); methods.add(method); }); return eventMethods; diff --git a/microsphere-java-core/src/main/java/io/microsphere/event/Listenable.java b/microsphere-java-core/src/main/java/io/microsphere/event/Listenable.java index 81bcb169a..fe037b5f0 100644 --- a/microsphere-java-core/src/main/java/io/microsphere/event/Listenable.java +++ b/microsphere-java-core/src/main/java/io/microsphere/event/Listenable.java @@ -27,6 +27,7 @@ import static io.microsphere.util.ClassUtils.getTypeName; import static java.lang.reflect.Modifier.isFinal; import static java.util.stream.StreamSupport.stream; +import static io.microsphere.collection.ListUtils.newArrayList; /** * A component that allows registration and management of {@link EventListener} instances. @@ -111,7 +112,7 @@ static void assertListener(EventListener listener) throws IllegalArgumentExce */ default void addEventListeners(E listener, E... others) throws NullPointerException, IllegalArgumentException { - ArrayList listeners = new ArrayList<>(1 + others.length); + ArrayList listeners = newArrayList(1 + others.length); listeners.add(listener); addAll(listeners, others); addEventListeners(listeners); diff --git a/microsphere-java-core/src/main/java/io/microsphere/filter/FilterUtils.java b/microsphere-java-core/src/main/java/io/microsphere/filter/FilterUtils.java index 8725c3b6c..d13724127 100644 --- a/microsphere-java-core/src/main/java/io/microsphere/filter/FilterUtils.java +++ b/microsphere-java-core/src/main/java/io/microsphere/filter/FilterUtils.java @@ -12,6 +12,7 @@ import java.util.List; import static java.util.Collections.unmodifiableList; +import static io.microsphere.collection.ListUtils.newArrayList; /** * Utility class for working with {@link Filter} instances. @@ -74,7 +75,7 @@ public static List filter(Iterable iterable, Filter filter) { @Nonnull @Immutable public static List filter(Iterable iterable, FilterOperator filterOperator, Filter... filters) { - ArrayList list = new ArrayList(); + ArrayList list = newArrayList(); Iterator iterator = iterable.iterator(); while (iterator.hasNext()) { E element = iterator.next(); diff --git a/microsphere-java-core/src/main/java/io/microsphere/io/StandardFileWatchService.java b/microsphere-java-core/src/main/java/io/microsphere/io/StandardFileWatchService.java index 94576736b..23c1579e0 100644 --- a/microsphere-java-core/src/main/java/io/microsphere/io/StandardFileWatchService.java +++ b/microsphere-java-core/src/main/java/io/microsphere/io/StandardFileWatchService.java @@ -63,6 +63,7 @@ import static java.nio.file.StandardWatchEventKinds.ENTRY_MODIFY; import static java.util.concurrent.Executors.newSingleThreadExecutor; import static java.util.concurrent.TimeUnit.MILLISECONDS; +import static io.microsphere.collection.SetUtils.newTreeSet; /** * /** @@ -330,7 +331,7 @@ static Kind toKind(WatchEvent.Kind watchEventKind) { private static class FileChangedMetadata { - private final Set filePaths = new TreeSet<>(); + private final Set filePaths = newTreeSet(); private EventDispatcher eventDispatcher; diff --git a/microsphere-java-core/src/main/java/io/microsphere/json/JSONArray.java b/microsphere-java-core/src/main/java/io/microsphere/json/JSONArray.java index b5fe96af6..7257fa2f9 100644 --- a/microsphere-java-core/src/main/java/io/microsphere/json/JSONArray.java +++ b/microsphere-java-core/src/main/java/io/microsphere/json/JSONArray.java @@ -82,7 +82,7 @@ public class JSONArray { * Creates a {@code JSONArray} with no values. */ public JSONArray() { - this.values = new ArrayList<>(); + this.values = newArrayList(); } @SuppressWarnings("rawtypes") diff --git a/microsphere-java-core/src/main/java/io/microsphere/json/JSONObject.java b/microsphere-java-core/src/main/java/io/microsphere/json/JSONObject.java index d07a16292..3aed8813e 100644 --- a/microsphere-java-core/src/main/java/io/microsphere/json/JSONObject.java +++ b/microsphere-java-core/src/main/java/io/microsphere/json/JSONObject.java @@ -43,6 +43,7 @@ import static io.microsphere.util.ClassUtils.isEnum; import static io.microsphere.util.ClassUtils.isNumber; import static io.microsphere.util.ClassUtils.isWrapperType; +import static io.microsphere.collection.ListUtils.newArrayList; /** * A modifiable set of name/value mappings. Names are unique, non-null strings. Values may @@ -730,7 +731,7 @@ public Iterator keys() { * @return the array */ public JSONArray names() { - return this.nameValuePairs.isEmpty() ? null : new JSONArray(new ArrayList<>(this.nameValuePairs.keySet())); + return this.nameValuePairs.isEmpty() ? null : new JSONArray(newArrayList(this.nameValuePairs.keySet())); } /** diff --git a/microsphere-java-core/src/main/java/io/microsphere/json/JSONStringer.java b/microsphere-java-core/src/main/java/io/microsphere/json/JSONStringer.java index ffb062aec..98711c612 100644 --- a/microsphere-java-core/src/main/java/io/microsphere/json/JSONStringer.java +++ b/microsphere-java-core/src/main/java/io/microsphere/json/JSONStringer.java @@ -29,6 +29,7 @@ import static io.microsphere.util.ClassUtils.getTypeName; import static java.lang.String.format; import static java.util.Arrays.fill; +import static io.microsphere.collection.ListUtils.newArrayList; /** * Implements {@link JSONObject#toString} and {@link JSONArray#toString}. Most application @@ -121,7 +122,7 @@ enum Scope { * Unlike the original implementation, this stack isn't limited to 20 levels of * nesting. */ - private final List stack = new ArrayList<>(); + private final List stack = newArrayList(); /** * A string containing a full set of spaces for a single level of indentation, or null diff --git a/microsphere-java-core/src/main/java/io/microsphere/management/builder/MBeanInfoBuilder.java b/microsphere-java-core/src/main/java/io/microsphere/management/builder/MBeanInfoBuilder.java index 25d0b747c..b0538c6fa 100644 --- a/microsphere-java-core/src/main/java/io/microsphere/management/builder/MBeanInfoBuilder.java +++ b/microsphere-java-core/src/main/java/io/microsphere/management/builder/MBeanInfoBuilder.java @@ -37,6 +37,7 @@ import static io.microsphere.reflect.MethodUtils.isIsMethod; import static io.microsphere.util.ClassUtils.getTypeName; import static java.util.Objects.nonNull; +import static io.microsphere.collection.ListUtils.newLinkedList; /** * The {@link MBeanInfo} Builder @@ -54,16 +55,16 @@ public class MBeanInfoBuilder extends MBeanDescribableBuilder String className; @Nullable - List attributeBuilders = new LinkedList<>(); + List attributeBuilders = newLinkedList(); @Nullable - List operationBuilders = new LinkedList<>(); + List operationBuilders = newLinkedList(); @Nullable - List constructorBuilders = new LinkedList<>(); + List constructorBuilders = newLinkedList(); @Nullable - List notificationBuilders = new LinkedList<>(); + List notificationBuilders = newLinkedList(); public MBeanInfoBuilder attribute(String attributeName, Class attributeType, Consumer builderConsumer) { MBeanAttributeInfoBuilder builder = MBeanAttributeInfoBuilder.attribute(attributeType).name(attributeName); diff --git a/microsphere-java-core/src/main/java/io/microsphere/net/ExtendableProtocolURLStreamHandler.java b/microsphere-java-core/src/main/java/io/microsphere/net/ExtendableProtocolURLStreamHandler.java index 6a6d8c6be..c9eed2744 100644 --- a/microsphere-java-core/src/main/java/io/microsphere/net/ExtendableProtocolURLStreamHandler.java +++ b/microsphere-java-core/src/main/java/io/microsphere/net/ExtendableProtocolURLStreamHandler.java @@ -50,6 +50,7 @@ import static java.lang.System.setProperty; import static java.net.Proxy.NO_PROXY; import static java.util.Collections.sort; +import static io.microsphere.collection.ListUtils.newArrayList; /** * Extendable Protocol {@link URLStreamHandler} class supports the sub-protocols, @@ -133,7 +134,7 @@ public abstract class ExtendableProtocolURLStreamHandler extends URLStreamHandle private final String protocol; - private final List factories = new ArrayList<>(); + private final List factories = newArrayList(); /** * The default constructor must obey the following conventions: diff --git a/microsphere-java-core/src/main/java/io/microsphere/reflect/MethodUtils.java b/microsphere-java-core/src/main/java/io/microsphere/reflect/MethodUtils.java index cb5d7cef7..f9b90f060 100644 --- a/microsphere-java-core/src/main/java/io/microsphere/reflect/MethodUtils.java +++ b/microsphere-java-core/src/main/java/io/microsphere/reflect/MethodUtils.java @@ -34,6 +34,7 @@ import java.util.function.Predicate; import static io.microsphere.annotation.ConfigurationProperty.SYSTEM_PROPERTIES_SOURCE; +import static io.microsphere.collection.ListUtils.newLinkedList; import static io.microsphere.collection.ListUtils.of; import static io.microsphere.constants.PropertyConstants.MICROSPHERE_PROPERTY_NAME_PREFIX; import static io.microsphere.constants.SymbolConstants.COMMA_CHAR; @@ -567,7 +568,7 @@ public static List findMethods(Class targetClass, boolean includeInhe } // All methods - LinkedList allMethods = new LinkedList<>(); + LinkedList allMethods = newLinkedList(); if (includeInheritedTypes) { while (targetClass != null) { diff --git a/microsphere-java-core/src/main/java/io/microsphere/reflect/ReflectionUtils.java b/microsphere-java-core/src/main/java/io/microsphere/reflect/ReflectionUtils.java index c38289668..277daf929 100644 --- a/microsphere-java-core/src/main/java/io/microsphere/reflect/ReflectionUtils.java +++ b/microsphere-java-core/src/main/java/io/microsphere/reflect/ReflectionUtils.java @@ -37,6 +37,7 @@ import static java.lang.reflect.Array.getLength; import static java.util.Collections.emptyMap; import static java.util.Collections.unmodifiableMap; +import static io.microsphere.collection.ListUtils.newArrayList; /** * Reflection Utility class , generic methods are defined from {@link FieldUtils} , {@link MethodUtils} , {@link @@ -375,7 +376,7 @@ static String getCallerClassNameInSunReflectReflection() { @Nonnull public static List toList(Object array) throws IllegalArgumentException { int length = getLength(array); - ArrayList list = new ArrayList<>(length); + ArrayList list = newArrayList(length); for (int i = 0; i < length; i++) { Object element = get(array, i); list.add((T) toObject(element)); diff --git a/microsphere-java-core/src/main/java/io/microsphere/util/AnnotationUtils.java b/microsphere-java-core/src/main/java/io/microsphere/util/AnnotationUtils.java index aabde9319..c90768627 100644 --- a/microsphere-java-core/src/main/java/io/microsphere/util/AnnotationUtils.java +++ b/microsphere-java-core/src/main/java/io/microsphere/util/AnnotationUtils.java @@ -853,7 +853,7 @@ public static List findAllDeclaredAnnotations(Class type, Predica return emptyList(); } - LinkedList allAnnotations = new LinkedList<>(); + LinkedList allAnnotations = newLinkedList(); List> allInheritedClasses = findAllInheritedClasses(type, NON_OBJECT_CLASS_FILTER); // Add the declared annotations diff --git a/microsphere-java-core/src/main/java/io/microsphere/util/StopWatch.java b/microsphere-java-core/src/main/java/io/microsphere/util/StopWatch.java index 9efdfb896..2307e4e28 100644 --- a/microsphere-java-core/src/main/java/io/microsphere/util/StopWatch.java +++ b/microsphere-java-core/src/main/java/io/microsphere/util/StopWatch.java @@ -28,6 +28,7 @@ import static java.util.Collections.unmodifiableList; import static java.util.Objects.hash; import static java.util.concurrent.TimeUnit.NANOSECONDS; +import static io.microsphere.collection.ListUtils.newLinkedList; /** *

{@code StopWatch} provides a simple way to measure execution time for tasks, supporting nested task tracking. @@ -80,12 +81,12 @@ public class StopWatch { /** * Running tasks(FIFO) */ - private final List runningTasks = new LinkedList<>(); + private final List runningTasks = newLinkedList(); /** * Completed tasks(FILO) */ - private final List completedTasks = new LinkedList<>(); + private final List completedTasks = newLinkedList(); /** * Total running time. diff --git a/microsphere-java-core/src/main/java/io/microsphere/util/StringUtils.java b/microsphere-java-core/src/main/java/io/microsphere/util/StringUtils.java index b4db24362..b623cd1a1 100644 --- a/microsphere-java-core/src/main/java/io/microsphere/util/StringUtils.java +++ b/microsphere-java-core/src/main/java/io/microsphere/util/StringUtils.java @@ -32,6 +32,7 @@ import static java.lang.Character.toLowerCase; import static java.lang.Character.toUpperCase; import static java.lang.String.valueOf; +import static io.microsphere.collection.ListUtils.newArrayList; /** * The utilities class for {@link String} @@ -169,7 +170,7 @@ public static String[] split(@Nullable String value, @Nullable String delimiter) int delimiterLength = delimiter.length(); - ArrayList result = new ArrayList<>(); + ArrayList result = newArrayList(); if (delimiterLength == 0) { for (int i = 0; i < length; i++) { diff --git a/microsphere-java-core/src/main/java/io/microsphere/util/jar/JarUtils.java b/microsphere-java-core/src/main/java/io/microsphere/util/jar/JarUtils.java index cec66d059..ef275ac15 100644 --- a/microsphere-java-core/src/main/java/io/microsphere/util/jar/JarUtils.java +++ b/microsphere-java-core/src/main/java/io/microsphere/util/jar/JarUtils.java @@ -25,6 +25,7 @@ import java.util.jar.JarFile; import static io.microsphere.collection.CollectionUtils.isEmpty; +import static io.microsphere.collection.ListUtils.newLinkedList; import static io.microsphere.collection.ListUtils.ofList; import static io.microsphere.constants.ProtocolConstants.FILE_PROTOCOL; import static io.microsphere.constants.ProtocolConstants.JAR_PROTOCOL; @@ -215,7 +216,7 @@ public static List filter(JarFile jarFile, JarEntryFilter jarEntryFilt @Nonnull @Immutable protected static List doFilter(Iterable jarEntries, JarEntryFilter jarEntryFilter) { - LinkedList jarEntriesList = new LinkedList<>(); + LinkedList jarEntriesList = newLinkedList(); for (JarEntry jarEntry : jarEntries) { if (jarEntryFilter == null || jarEntryFilter.accept(jarEntry)) { jarEntriesList.add(jarEntry);