Reduce use of Lists.new*List() 61/84461/3
authorRobert Varga <robert.varga@pantheon.tech>
Sat, 14 Sep 2019 20:22:55 +0000 (22:22 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Sat, 14 Sep 2019 23:22:53 +0000 (01:22 +0200)
Pure-java 'new ArrayList<>()' is just as efficient, use that
instead.

Change-Id: Ibfe198885df96b5eba55a861d9a7824dd63f8fd0
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
bgp/parser-impl/src/test/java/org/opendaylight/protocol/bgp/parser/impl/BGPParserTest.java
bgp/parser-impl/src/test/java/org/opendaylight/protocol/bgp/parser/impl/message/update/ClusterIdAttributeParserTest.java
bgp/parser-impl/src/test/java/org/opendaylight/protocol/bgp/parser/impl/message/update/CommunitiesAttributeParserTest.java
bgp/util/src/main/java/org/opendaylight/protocol/bgp/util/BinaryBGPDumpFileParser.java
bgp/util/src/main/java/org/opendaylight/protocol/bgp/util/HexDumpBGPFileParser.java

index b68665e29c687081512533029caf41843730fe73..e6169a1229c65c3aceeb72b8e86bea4ef40c4073 100644 (file)
@@ -189,13 +189,13 @@ public class BGPParserTest {
         // attributes
         final List<AsNumber> asNumbers = new ArrayList<>();
         asNumbers.add(new AsNumber(65002L));
-        final List<Segments> asPath = Lists.newArrayList();
+        final List<Segments> asPath = new ArrayList<>();
         asPath.add(new SegmentsBuilder().setAsSequence(asNumbers).build());
 
         final Ipv4NextHopCase nextHop = new Ipv4NextHopCaseBuilder().setIpv4NextHop(
                 new Ipv4NextHopBuilder().setGlobal(new Ipv4Address("10.0.0.2")).build()).build();
 
-        final List<Communities> comms = Lists.newArrayList();
+        final List<Communities> comms = new ArrayList<>();
         comms.add((Communities) CommunityUtil.NO_EXPORT);
         comms.add((Communities) CommunityUtil.NO_ADVERTISE);
         comms.add((Communities) CommunityUtil.NO_EXPORT_SUBCONFED);
@@ -310,7 +310,7 @@ public class BGPParserTest {
         // attributes
         final List<AsNumber> asNumbers = new ArrayList<>();
         asNumbers.add(new AsNumber(30L));
-        final List<Segments> asPath = Lists.newArrayList();
+        final List<Segments> asPath = new ArrayList<>();
         asPath.add(new SegmentsBuilder().setAsSequence(asNumbers).build());
         final List<AsNumber> asSet = Lists.newArrayList(new AsNumber(10L), new AsNumber(20L));
         asPath.add(new SegmentsBuilder().setAsSet(asSet).build());
@@ -402,7 +402,7 @@ public class BGPParserTest {
         assertNull(message.getWithdrawnRoutes());
 
         // check nlri
-        final List<Nlri> nlris = Lists.newArrayList();
+        final List<Nlri> nlris = new ArrayList<>();
         nlris.add(new NlriBuilder().setPrefix(new Ipv4Prefix("10.30.3.0/24")).build());
         nlris.add(new NlriBuilder().setPrefix(new Ipv4Prefix("10.30.2.0/24")).build());
         nlris.add(new NlriBuilder().setPrefix(new Ipv4Prefix("10.30.1.0/24")).build());
@@ -641,13 +641,13 @@ public class BGPParserTest {
         // attributes
         final List<AsNumber> asNumbers = new ArrayList<>();
         asNumbers.add(new AsNumber(65002L));
-        final List<Segments> asPath = Lists.newArrayList();
+        final List<Segments> asPath = new ArrayList<>();
         asPath.add(new SegmentsBuilder().setAsSequence(asNumbers).build());
 
         final Ipv4NextHopCase nextHop = new Ipv4NextHopCaseBuilder().setIpv4NextHop(
                 new Ipv4NextHopBuilder().setGlobal(new Ipv4Address("10.0.0.2")).build()).build();
 
-        final List<Communities> comms = Lists.newArrayList();
+        final List<Communities> comms = new ArrayList<>();
         comms.add((Communities) CommunityUtil.NO_EXPORT);
         comms.add((Communities) CommunityUtil.NO_ADVERTISE);
         comms.add((Communities) CommunityUtil.NO_EXPORT_SUBCONFED);
@@ -657,7 +657,7 @@ public class BGPParserTest {
 
         // check nlri
 
-        final List<Nlri> nlris = Lists.newArrayList();
+        final List<Nlri> nlris = new ArrayList<>();
         nlris.add(new NlriBuilder().setPrefix(new Ipv4Prefix("172.17.1.0/24")).setPathId(new PathId(1L)).build());
         nlris.add(new NlriBuilder().setPrefix(new Ipv4Prefix("172.17.1.0/24")).setPathId(new PathId(2L)).build());
         nlris.add(new NlriBuilder().setPrefix(new Ipv4Prefix("172.17.0.0/24")).setPathId(new PathId(1L)).build());
@@ -724,7 +724,7 @@ public class BGPParserTest {
             mpConstraint);
 
         // attributes
-        final List<WithdrawnRoutes> withdrawnRoutes = Lists.newArrayList();
+        final List<WithdrawnRoutes> withdrawnRoutes = new ArrayList<>();
         withdrawnRoutes.add(new WithdrawnRoutesBuilder().setPrefix(new Ipv4Prefix("172.16.0.4/30"))
             .setPathId(new PathId(1L)).build());
         withdrawnRoutes.add(new WithdrawnRoutesBuilder().setPrefix(new Ipv4Prefix("172.16.0.4/30"))
index 35f0349208634b5332a0d6cfce9333c95a3b81a8..ea1266b4cc99971e44ff03ec8403023254ee7bf6 100644 (file)
@@ -10,9 +10,9 @@ package org.opendaylight.protocol.bgp.parser.impl.message.update;
 import static org.junit.Assert.assertArrayEquals;
 import static org.junit.Assert.assertEquals;
 
-import com.google.common.collect.Lists;
 import io.netty.buffer.ByteBuf;
 import io.netty.buffer.Unpooled;
+import java.util.ArrayList;
 import java.util.List;
 import org.junit.Before;
 import org.junit.Test;
@@ -37,7 +37,7 @@ public class ClusterIdAttributeParserTest {
 
     @Test
     public void testParserAttribute() throws Exception {
-        final List<ClusterIdentifier> list = Lists.newArrayList();
+        final List<ClusterIdentifier> list = new ArrayList<>();
         final Ipv4Address ip1 = new Ipv4Address("192.168.1.1");
         final Ipv4Address ip2 = new Ipv4Address("192.168.1.2");
         list.add(new ClusterIdentifier(ip1));
@@ -59,7 +59,7 @@ public class ClusterIdAttributeParserTest {
 
     @Test
     public void testParseEmptyListAttribute() {
-        final List<ClusterIdentifier> list = Lists.newArrayList();
+        final List<ClusterIdentifier> list = new ArrayList<>();
         final Attributes clusterId = new AttributesBuilder().setClusterId(new ClusterIdBuilder().setCluster(list)
             .build()).build();
         final ByteBuf output = Unpooled.buffer();
index 6f07fd4f088e147386141a06e319d0287b4a1d8d..28584a94abf327c5152e59e1262e166fb84f7b39 100644 (file)
@@ -5,15 +5,14 @@
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
  * and is available at http://www.eclipse.org/legal/epl-v10.html
  */
-
 package org.opendaylight.protocol.bgp.parser.impl.message.update;
 
 import static org.junit.Assert.assertArrayEquals;
 import static org.junit.Assert.assertEquals;
 
-import com.google.common.collect.Lists;
 import io.netty.buffer.ByteBuf;
 import io.netty.buffer.Unpooled;
+import java.util.ArrayList;
 import java.util.List;
 import org.junit.Test;
 import org.opendaylight.protocol.bgp.parser.spi.pojo.ServiceLoaderBGPExtensionProviderContext;
@@ -36,7 +35,7 @@ public class CommunitiesAttributeParserTest {
 
     @Test
     public void testCommunitiesAttributeParser() throws Exception {
-        final List<Communities> comms = Lists.newArrayList();
+        final List<Communities> comms = new ArrayList<>();
         comms.add((Communities) CommunityUtil.NO_EXPORT);
         comms.add((Communities) CommunityUtil.NO_ADVERTISE);
         comms.add((Communities) CommunityUtil.NO_EXPORT_SUBCONFED);
@@ -58,7 +57,7 @@ public class CommunitiesAttributeParserTest {
 
     @Test
     public void testParseEmptyListAttribute() {
-        final List<Communities> comms = Lists.newArrayList();
+        final List<Communities> comms = new ArrayList<>();
         final ByteBuf actual = Unpooled.buffer();
         ServiceLoaderBGPExtensionProviderContext.getSingletonInstance().getAttributeRegistry()
             .serializeAttribute(new AttributesBuilder().setCommunities(comms).build(), actual);
index f1007296bcc04869478d53e30280ecce90edd639..d54c141d2ed4136df41939672b47d6ebf870c08d 100644 (file)
@@ -8,9 +8,9 @@
 package org.opendaylight.protocol.bgp.util;
 
 import com.google.common.base.Preconditions;
-import com.google.common.collect.Lists;
 import com.google.common.primitives.UnsignedBytes;
 import java.util.Arrays;
+import java.util.LinkedList;
 import java.util.List;
 import org.opendaylight.protocol.util.ByteArray;
 import org.slf4j.Logger;
@@ -38,7 +38,7 @@ public final class BinaryBGPDumpFileParser {
      */
     public static List<byte[]> parseMessages(final byte[] byteArray) {
 
-        final List<byte[]> messages = Lists.newLinkedList();
+        final List<byte[]> messages = new LinkedList();
         // search for 16 FFs
         for (int i = 0; i < byteArray.length; i++) {
             final byte b = byteArray[i];
@@ -52,7 +52,7 @@ public final class BinaryBGPDumpFileParser {
                     if (byteArray[j] == UnsignedBytes.MAX_VALUE) {
                         ffCount++;
                     } else if (ffCount == MARKER_LENGTH) {
-                        if (j == (i + MARKER_LENGTH)) {
+                        if (j == i + MARKER_LENGTH) {
                             // Parse length
                             final int length = ByteArray.bytesToInt(new byte[]{ byteArray[j], byteArray[j + 1] });
 
index 0a9f363132d057799ac4a4f83e41626ee2261f1d..065e6f93146d0edd12430294faf13d6855e1b99b 100644 (file)
@@ -12,7 +12,6 @@ import static java.util.Objects.requireNonNull;
 import com.google.common.annotations.VisibleForTesting;
 import com.google.common.base.Preconditions;
 import com.google.common.base.Strings;
-import com.google.common.collect.Lists;
 import com.google.common.io.BaseEncoding;
 import com.google.common.io.CharStreams;
 import java.io.File;
@@ -20,6 +19,8 @@ import java.io.FileInputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.InputStreamReader;
+import java.nio.charset.StandardCharsets;
+import java.util.LinkedList;
 import java.util.List;
 import java.util.Locale;
 import org.opendaylight.protocol.util.ByteArray;
@@ -46,7 +47,7 @@ public final class HexDumpBGPFileParser {
 
     public static List<byte[]> parseMessages(final InputStream is) throws IOException {
         requireNonNull(is);
-        try (InputStreamReader isr = new InputStreamReader(is, "UTF-8")) {
+        try (InputStreamReader isr = new InputStreamReader(is, StandardCharsets.UTF_8)) {
             return parseMessages(CharStreams.toString(isr));
         } finally {
             is.close();
@@ -59,7 +60,7 @@ public final class HexDumpBGPFileParser {
         final int four = 4;
         // search for 16 FFs
 
-        final List<byte[]> messages = Lists.newLinkedList();
+        final List<byte[]> messages = new LinkedList<>();
         int idx = content.indexOf(FF_16, 0);
         while (idx > -1) {
             // next 2 bytes are length