Fix some sonar/checkstyle issues 76/64276/2
authorDavid Suarez <david.suarez.fuentes@gmail.com>
Sat, 14 Oct 2017 13:49:21 +0000 (15:49 +0200)
committerTom Pantelis <tompantelis@gmail.com>
Sat, 14 Oct 2017 16:29:15 +0000 (16:29 +0000)
- Remove unnecessary boxing
- Utility classes should be final and implement a private constructor
- Remove unnecessary types
- Remove two duplicated entries in pom.xml

Change-Id: I2f4539babf7d4ea6d4550d81b71deb4399dc1dc3
Signed-off-by: David Suarez <david.suarez.fuentes@gmail.com>
opendaylight/md-sal/sal-clustering-commons/pom.xml
opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/datastore/node/utils/QNameFactory.java
opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/datastore/node/utils/stream/NormalizedNodeInputStreamReader.java
opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/datastore/node/utils/stream/SerializationUtils.java
opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/datastore/node/utils/stream/ValueTypes.java
opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/messaging/MessageSlicer.java
opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/persistence/LocalSnapshotStore.java
opendaylight/md-sal/sal-clustering-commons/src/test/java/org/opendaylight/controller/cluster/schema/provider/impl/RemoteSchemaProviderTest.java
opendaylight/md-sal/sal-clustering-commons/src/test/java/org/opendaylight/controller/cluster/schema/provider/impl/RemoteYangTextSourceProviderImplTest.java

index 8e70b44..7a904b3 100644 (file)
       <groupId>org.opendaylight.yangtools</groupId>
       <artifactId>util</artifactId>
     </dependency>
-    <dependency>
-      <groupId>org.opendaylight.yangtools</groupId>
-      <artifactId>yang-common</artifactId>
-    </dependency>
     <dependency>
       <groupId>org.opendaylight.yangtools</groupId>
       <artifactId>yang-data-api</artifactId>
       <groupId>org.opendaylight.yangtools</groupId>
       <artifactId>yang-model-util</artifactId>
     </dependency>
-    <dependency>
-      <groupId>org.opendaylight.controller</groupId>
-      <artifactId>config-api</artifactId>
-    </dependency>
   </dependencies>
 
   <build>
index 7d5379d..5c7f6d1 100644 (file)
@@ -13,22 +13,20 @@ import com.google.common.cache.CacheLoader;
 import com.google.common.cache.LoadingCache;
 import org.opendaylight.yangtools.yang.common.QName;
 
-public class QNameFactory {
+public final class QNameFactory {
 
     private static final int MAX_QNAME_CACHE_SIZE = 10000;
 
-    private static final LoadingCache<String, QName> CACHE = CacheBuilder.newBuilder()
-        .maximumSize(MAX_QNAME_CACHE_SIZE)
-        .softValues()
-        .build(
-            new CacheLoader<String, QName>() {
+    private QNameFactory() {
+    }
+
+    private static final LoadingCache<String, QName> CACHE = CacheBuilder.newBuilder().maximumSize(MAX_QNAME_CACHE_SIZE)
+            .softValues().build(new CacheLoader<String, QName>() {
                 @Override
                 public QName load(String key) {
                     return QName.create(key);
                 }
-            }
-        );
-
+            });
 
     public static QName create(String name) {
         return CACHE.getUnchecked(name);
index 6316bf3..3b912e6 100755 (executable)
@@ -261,7 +261,7 @@ public class NormalizedNodeInputStreamReader implements NormalizedNodeDataInput
             return codedStringMap.get(input.readInt());
         } else if (valueType == TokenTypes.IS_STRING_VALUE) {
             String value = input.readUTF().intern();
-            codedStringMap.put(Integer.valueOf(codedStringMap.size()), value);
+            codedStringMap.put(codedStringMap.size(), value);
             return value;
         }
 
@@ -296,22 +296,22 @@ public class NormalizedNodeInputStreamReader implements NormalizedNodeDataInput
                 return readObjSet();
 
             case ValueTypes.BOOL_TYPE :
-                return Boolean.valueOf(input.readBoolean());
+                return input.readBoolean();
 
             case ValueTypes.BYTE_TYPE :
-                return Byte.valueOf(input.readByte());
+                return input.readByte();
 
             case ValueTypes.INT_TYPE :
-                return Integer.valueOf(input.readInt());
+                return input.readInt();
 
             case ValueTypes.LONG_TYPE :
-                return Long.valueOf(input.readLong());
+                return input.readLong();
 
             case ValueTypes.QNAME_TYPE :
                 return readQName();
 
             case ValueTypes.SHORT_TYPE :
-                return Short.valueOf(input.readShort());
+                return input.readShort();
 
             case ValueTypes.STRING_TYPE :
                 return input.readUTF();
index e4fd936..3a04347 100644 (file)
@@ -27,6 +27,9 @@ public final class SerializationUtils {
     public static final ThreadLocal<NormalizedNodeDataOutput> REUSABLE_WRITER_TL = new ThreadLocal<>();
     public static final ThreadLocal<NormalizedNodeDataInput> REUSABLE_READER_TL = new ThreadLocal<>();
 
+    private SerializationUtils() {
+    }
+
     public interface Applier<T> {
         void apply(T instance, YangInstanceIdentifier path, NormalizedNode<?, ?> node);
     }
index dd9e102..190f596 100644 (file)
@@ -41,16 +41,16 @@ final class ValueTypes {
     static {
         final Builder<Class<?>, Byte> b = ImmutableMap.builder();
 
-        b.put(String.class, Byte.valueOf(STRING_TYPE));
-        b.put(Byte.class, Byte.valueOf(BYTE_TYPE));
-        b.put(Integer.class, Byte.valueOf(INT_TYPE));
-        b.put(Long.class, Byte.valueOf(LONG_TYPE));
-        b.put(Boolean.class, Byte.valueOf(BOOL_TYPE));
-        b.put(QName.class, Byte.valueOf(QNAME_TYPE));
-        b.put(Short.class, Byte.valueOf(SHORT_TYPE));
-        b.put(BigInteger.class, Byte.valueOf(BIG_INTEGER_TYPE));
-        b.put(BigDecimal.class, Byte.valueOf(BIG_DECIMAL_TYPE));
-        b.put(byte[].class, Byte.valueOf(BINARY_TYPE));
+        b.put(String.class, STRING_TYPE);
+        b.put(Byte.class, BYTE_TYPE);
+        b.put(Integer.class, INT_TYPE);
+        b.put(Long.class, LONG_TYPE);
+        b.put(Boolean.class, BOOL_TYPE);
+        b.put(QName.class, QNAME_TYPE);
+        b.put(Short.class, SHORT_TYPE);
+        b.put(BigInteger.class, BIG_INTEGER_TYPE);
+        b.put(BigDecimal.class, BIG_DECIMAL_TYPE);
+        b.put(byte[].class, BINARY_TYPE);
 
         TYPES = b.build();
     }
index 4c3d67b..fd08a95 100644 (file)
@@ -12,7 +12,6 @@ import com.google.common.annotations.VisibleForTesting;
 import com.google.common.base.Preconditions;
 import com.google.common.cache.Cache;
 import com.google.common.cache.CacheBuilder;
-import com.google.common.cache.RemovalListener;
 import com.google.common.cache.RemovalNotification;
 import java.io.IOException;
 import java.io.ObjectOutputStream;
@@ -55,13 +54,12 @@ public class MessageSlicer implements AutoCloseable {
         id = SLICER_ID_COUNTER.getAndIncrement();
         this.logContext = builder.logContext + "_slicer-id-" + id;
 
-        CacheBuilder<Identifier, SlicedMessageState<ActorRef>> cacheBuilder = CacheBuilder.newBuilder().removalListener(
-                (RemovalListener<Identifier, SlicedMessageState<ActorRef>>) notification -> stateRemoved(notification));
+        CacheBuilder<Identifier, SlicedMessageState<ActorRef>> cacheBuilder =
+                CacheBuilder.newBuilder().removalListener(notification -> stateRemoved(notification));
         if (builder.expireStateAfterInactivityDuration > 0) {
             cacheBuilder = cacheBuilder.expireAfterAccess(builder.expireStateAfterInactivityDuration,
                     builder.expireStateAfterInactivityUnit);
         }
-
         stateCache = cacheBuilder.build();
     }
 
index c89d7ff..e1589ff 100644 (file)
@@ -22,7 +22,6 @@ import java.io.BufferedInputStream;
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.FileOutputStream;
-import java.io.FilenameFilter;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.ObjectInputStream;
@@ -236,7 +235,7 @@ public class LocalSnapshotStore extends SnapshotStore {
     private Collection<File> getSnapshotFiles(final String persistenceId) {
         String encodedPersistenceId = encode(persistenceId);
 
-        File[] files = snapshotDir.listFiles((FilenameFilter) (dir, name) -> {
+        File[] files = snapshotDir.listFiles((dir, name) -> {
             int persistenceIdEndIndex = name.lastIndexOf('-', name.lastIndexOf('-') - 1);
             return PERSISTENCE_ID_START_INDEX + encodedPersistenceId.length() == persistenceIdEndIndex
                     && name.startsWith(encodedPersistenceId, PERSISTENCE_ID_START_INDEX) && !name.endsWith(".tmp");
index 9b20328..5ce2d9b 100644 (file)
@@ -62,7 +62,7 @@ public class RemoteSchemaProviderTest {
         Futures.failed(new Exception("halo"));
 
         Mockito.when(mockedRemoteSchemaRepository.getYangTextSchemaSource(ID)).thenReturn(
-                Futures.<YangTextSchemaSourceSerializationProxy>failed(
+                Futures.failed(
                         new SchemaSourceException("Source not provided")));
 
         CheckedFuture<?, ?> sourceFuture = remoteSchemaProvider.getSource(ID);
index 72170ca..678bad7 100644 (file)
@@ -50,7 +50,7 @@ public class RemoteYangTextSourceProviderImplTest {
         YangTextSchemaSource schemaSource = YangTextSchemaSource.delegateForByteSource(
                 ID, ByteSource.wrap(source.getBytes()));
         Mockito.when(mockedLocalRepository.getSchemaSource(ID, YangTextSchemaSource.class)).thenReturn(
-                Futures.<YangTextSchemaSource, SchemaSourceException>immediateCheckedFuture(schemaSource));
+                Futures.immediateCheckedFuture(schemaSource));
 
         Future<YangTextSchemaSourceSerializationProxy> retrievedSourceFuture =
                 remoteRepository.getYangTextSchemaSource(ID);
@@ -64,7 +64,7 @@ public class RemoteYangTextSourceProviderImplTest {
     @Test(expected = SchemaSourceException.class)
     public void testGetNonExistentYangTextSchemaSource() throws Exception {
         Mockito.when(mockedLocalRepository.getSchemaSource(ID, YangTextSchemaSource.class)).thenReturn(
-                Futures.<YangTextSchemaSource, SchemaSourceException>immediateFailedCheckedFuture(
+                Futures.immediateFailedCheckedFuture(
                         new SchemaSourceException("Source is not provided")));
 
         Future<YangTextSchemaSourceSerializationProxy> retrievedSourceFuture =

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.