diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2024-04-11 15:09:55 +0200 |
---|---|---|
committer | Henning Baldersheim <balder@yahoo-inc.com> | 2024-04-11 21:04:22 +0200 |
commit | 2d6bbe0b8bff09d105b77161c1d26a00ce43bf0c (patch) | |
tree | f9948a9904d837960887e81a956b29f92d918002 /jdisc_core | |
parent | 6923743ed320ce339727ad57f6fc2da5f82f5e3f (diff) |
Unify on List.of
Diffstat (limited to 'jdisc_core')
8 files changed, 20 insertions, 28 deletions
diff --git a/jdisc_core/src/main/java/com/yahoo/jdisc/application/BundleInstaller.java b/jdisc_core/src/main/java/com/yahoo/jdisc/application/BundleInstaller.java index 60ca0851fd4..1e0050335dc 100644 --- a/jdisc_core/src/main/java/com/yahoo/jdisc/application/BundleInstaller.java +++ b/jdisc_core/src/main/java/com/yahoo/jdisc/application/BundleInstaller.java @@ -5,11 +5,9 @@ import com.google.inject.Inject; import org.osgi.framework.Bundle; import org.osgi.framework.BundleException; -import java.util.Arrays; import java.util.LinkedList; import java.util.List; -import static java.util.Collections.singletonList; /** * <p>This is a utility class to help with installing, starting, stopping and uninstalling OSGi Bundles. You can choose @@ -30,7 +28,7 @@ public final class BundleInstaller { } public List<Bundle> installAndStart(String... locations) throws BundleException { - return installAndStart(Arrays.asList(locations)); + return installAndStart(List.of(locations)); } public List<Bundle> installAndStart(Iterable<String> locations) throws BundleException { @@ -56,7 +54,7 @@ public final class BundleInstaller { } public void stopAndUninstall(Bundle... bundles) throws BundleException { - stopAndUninstall(Arrays.asList(bundles)); + stopAndUninstall(List.of(bundles)); } public void stopAndUninstall(Iterable<Bundle> bundles) throws BundleException { @@ -76,7 +74,7 @@ public final class BundleInstaller { throw new BundleException("OSGi header '" + OsgiHeader.APPLICATION + "' not allowed for " + "non-application bundle " + bundle.getSymbolicName() + "."); } - osgiFramework.startBundles(singletonList(bundle), false); + osgiFramework.startBundles(List.of(bundle), false); } private void stop(Bundle bundle) throws BundleException { diff --git a/jdisc_core/src/main/java/com/yahoo/jdisc/application/ContainerBuilder.java b/jdisc_core/src/main/java/com/yahoo/jdisc/application/ContainerBuilder.java index 6550d9b5386..8b3fe4c13aa 100644 --- a/jdisc_core/src/main/java/com/yahoo/jdisc/application/ContainerBuilder.java +++ b/jdisc_core/src/main/java/com/yahoo/jdisc/application/ContainerBuilder.java @@ -8,7 +8,6 @@ import com.google.inject.Module; import com.yahoo.jdisc.Container; import com.yahoo.jdisc.handler.RequestHandler; -import java.util.Collections; import java.util.HashMap; import java.util.LinkedList; import java.util.List; @@ -107,7 +106,7 @@ public class ContainerBuilder { public static List<String> safeStringSplit(Object obj, String delim) { if (!(obj instanceof String)) { - return Collections.emptyList(); + return List.of(); } List<String> lst = new LinkedList<>(); for (String str : ((String)obj).split(delim)) { diff --git a/jdisc_core/src/main/java/com/yahoo/jdisc/core/Main.java b/jdisc_core/src/main/java/com/yahoo/jdisc/core/Main.java index edd4dd40496..b2a8660e2a8 100644 --- a/jdisc_core/src/main/java/com/yahoo/jdisc/core/Main.java +++ b/jdisc_core/src/main/java/com/yahoo/jdisc/core/Main.java @@ -6,8 +6,7 @@ import com.yahoo.jdisc.application.ContainerBuilder; import com.yahoo.jdisc.application.OsgiFramework; import java.io.IOException; -import java.util.Arrays; -import java.util.Collections; +import java.util.List; /** * @author Simon Thoresen Hult @@ -31,7 +30,7 @@ public class Main { static Iterable<Module> newConfigModule() { String configFile = System.getProperty("jdisc.config.file"); if (configFile == null) { - return Collections.emptyList(); + return List.of(); } Module configModule; try { @@ -39,7 +38,7 @@ public class Main { } catch (IOException e) { throw new IllegalStateException("Exception thrown while reading config file '" + configFile + "'.", e); } - return Arrays.asList(configModule); + return List.of(configModule); } } diff --git a/jdisc_core/src/main/java/com/yahoo/jdisc/handler/RequestDispatch.java b/jdisc_core/src/main/java/com/yahoo/jdisc/handler/RequestDispatch.java index ef420d69f16..c39a70c7093 100644 --- a/jdisc_core/src/main/java/com/yahoo/jdisc/handler/RequestDispatch.java +++ b/jdisc_core/src/main/java/com/yahoo/jdisc/handler/RequestDispatch.java @@ -8,7 +8,7 @@ import com.yahoo.jdisc.Response; import com.yahoo.jdisc.SharedResource; import java.nio.ByteBuffer; -import java.util.Collections; +import java.util.List; import java.util.concurrent.CompletableFuture; import java.util.concurrent.ExecutionException; import java.util.concurrent.Executor; @@ -35,7 +35,7 @@ import java.util.concurrent.TimeoutException; * } * @Override * protected Iterable<ByteBuffer> requestContent() { - * return Collections.singleton(ByteBuffer.wrap(new byte[] { 6, 9 })); + * return Set.of(ByteBuffer.wrap(new byte[] { 6, 9 })); * } * @Override * public ContentChannel handleResponse(Response response) { @@ -69,7 +69,7 @@ public abstract class RequestDispatch implements Future<Response>, ResponseHandl * @return The ByteBuffers to write to the Request's ContentChannel. */ protected Iterable<ByteBuffer> requestContent() { - return Collections.emptyList(); + return List.of(); } /** diff --git a/jdisc_core/src/main/java/com/yahoo/jdisc/handler/ResponseDispatch.java b/jdisc_core/src/main/java/com/yahoo/jdisc/handler/ResponseDispatch.java index ff1f23917d7..0670aa5ea67 100644 --- a/jdisc_core/src/main/java/com/yahoo/jdisc/handler/ResponseDispatch.java +++ b/jdisc_core/src/main/java/com/yahoo/jdisc/handler/ResponseDispatch.java @@ -5,8 +5,7 @@ import com.yahoo.jdisc.Response; import com.yahoo.jdisc.SharedResource; import java.nio.ByteBuffer; -import java.util.Arrays; -import java.util.Collections; +import java.util.List; import java.util.concurrent.CompletableFuture; import java.util.concurrent.ExecutionException; import java.util.concurrent.Future; @@ -28,7 +27,7 @@ import java.util.concurrent.TimeoutException; * } * @Override * protected Iterable<ByteBuffer> responseContent() { - * return Collections.singleton(ByteBuffer.wrap(new byte[] { 6, 9 })); + * return Set.of(ByteBuffer.wrap(new byte[] { 6, 9 })); * } * }.dispatch(handler); * } @@ -56,7 +55,7 @@ public abstract class ResponseDispatch implements Future<Boolean> { * @return The ByteBuffers to write to the Response's ContentChannel. */ protected Iterable<ByteBuffer> responseContent() { - return Collections.emptyList(); + return List.of(); } /** @@ -130,7 +129,7 @@ public abstract class ResponseDispatch implements Future<Boolean> { * @return The created ResponseDispatch. */ public static ResponseDispatch newInstance(int responseStatus, ByteBuffer... content) { - return newInstance(new Response(responseStatus), Arrays.asList(content)); + return newInstance(new Response(responseStatus), List.of(content)); } /** @@ -155,7 +154,7 @@ public abstract class ResponseDispatch implements Future<Boolean> { * @return The created ResponseDispatch. */ public static ResponseDispatch newInstance(Response response, ByteBuffer... content) { - return newInstance(response, Arrays.asList(content)); + return newInstance(response, List.of(content)); } /** diff --git a/jdisc_core/src/main/java/com/yahoo/jdisc/test/NonWorkingOsgiFramework.java b/jdisc_core/src/main/java/com/yahoo/jdisc/test/NonWorkingOsgiFramework.java index 1b90e8adcfe..3565a1ec4c5 100644 --- a/jdisc_core/src/main/java/com/yahoo/jdisc/test/NonWorkingOsgiFramework.java +++ b/jdisc_core/src/main/java/com/yahoo/jdisc/test/NonWorkingOsgiFramework.java @@ -6,7 +6,6 @@ import org.osgi.framework.Bundle; import org.osgi.framework.BundleContext; import java.util.Collection; -import java.util.Collections; import java.util.List; /** @@ -36,12 +35,12 @@ public class NonWorkingOsgiFramework implements OsgiFramework { @Override public List<Bundle> bundles() { - return Collections.emptyList(); + return List.of(); } @Override public List<Bundle> getBundles(Bundle requestingBundle) { - return Collections.emptyList(); + return List.of(); } @Override diff --git a/jdisc_core/src/test/java/com/yahoo/jdisc/application/UriPatternTestCase.java b/jdisc_core/src/test/java/com/yahoo/jdisc/application/UriPatternTestCase.java index fa949ccaabd..063ddc81f45 100644 --- a/jdisc_core/src/test/java/com/yahoo/jdisc/application/UriPatternTestCase.java +++ b/jdisc_core/src/test/java/com/yahoo/jdisc/application/UriPatternTestCase.java @@ -6,7 +6,6 @@ import org.junit.jupiter.api.Test; import java.net.URI; import java.util.ArrayList; import java.util.Arrays; -import java.util.Collections; import java.util.List; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -20,7 +19,7 @@ import static org.junit.jupiter.api.Assertions.fail; */ public class UriPatternTestCase { - private static final List<String> NO_GROUPS = Collections.emptyList(); + private static final List<String> NO_GROUPS = List.of(); @Test void requireThatIllegalPatternsAreDetected() { diff --git a/jdisc_core/src/test/java/com/yahoo/jdisc/core/ApplicationEnvironmentModuleTestCase.java b/jdisc_core/src/test/java/com/yahoo/jdisc/core/ApplicationEnvironmentModuleTestCase.java index dfc52b92583..af3fa418556 100644 --- a/jdisc_core/src/test/java/com/yahoo/jdisc/core/ApplicationEnvironmentModuleTestCase.java +++ b/jdisc_core/src/test/java/com/yahoo/jdisc/core/ApplicationEnvironmentModuleTestCase.java @@ -17,7 +17,6 @@ import java.util.List; import java.util.Map; import java.util.concurrent.ThreadFactory; -import static java.util.Collections.emptyList; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -40,7 +39,7 @@ public class ApplicationEnvironmentModuleTestCase { expected.add(entry.getKey().getTypeLiteral().getRawType()); } - ApplicationLoader loader = new ApplicationLoader(new NonWorkingOsgiFramework(), emptyList()); + ApplicationLoader loader = new ApplicationLoader(new NonWorkingOsgiFramework(), List.of()); injector = Guice.createInjector(new ApplicationEnvironmentModule(loader)); for (Map.Entry<Key<?>, Binding<?>> entry : injector.getBindings().entrySet()) { assertNotNull(expected.remove(entry.getKey().getTypeLiteral().getRawType())); @@ -50,7 +49,7 @@ public class ApplicationEnvironmentModuleTestCase { @Test void requireThatContainerBuilderCanBeInjected() { - ApplicationLoader loader = new ApplicationLoader(new NonWorkingOsgiFramework(), emptyList()); + ApplicationLoader loader = new ApplicationLoader(new NonWorkingOsgiFramework(), List.of()); assertNotNull(new ApplicationEnvironmentModule(loader).containerBuilder()); assertNotNull(Guice.createInjector(new ApplicationEnvironmentModule(loader)) .getInstance(ContainerBuilder.class)); |