BUG-509: explain the use of SuppressWarnings 93/5993/2
authorRobert Varga <rovarga@cisco.com>
Wed, 9 Apr 2014 04:02:11 +0000 (06:02 +0200)
committerTony Tkacik <ttkacik@cisco.com>
Wed, 9 Apr 2014 11:02:14 +0000 (11:02 +0000)
This adds an explanation why we opted to suppress warnings instead of
doing the type-safe thing.

Also speeds up string building very slightly by compacting two append()
calls and using append(char) instead append(String).

Change-Id: Ifed1005bb118de101476063790b5c8aee73888bb
Signed-off-by: Robert Varga <rovarga@cisco.com>
opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/md/sal/dom/store/impl/StoreUtils.java

index 02c2a4fa06042e2984745183262a7d053411157a..830d7e3dc40303859748e5d1977eeaa3f7018c3b 100644 (file)
@@ -24,7 +24,6 @@ import com.google.common.primitives.UnsignedLong;
 public final class StoreUtils {
 
     private final static Function<Identifiable<Object>, Object> EXTRACT_IDENTIFIER = new Function<Identifiable<Object>, Object>() {
-
         @Override
         public Object apply(final Identifiable<Object> input) {
             return input.getIdentifier();
@@ -45,6 +44,11 @@ public final class StoreUtils {
         return new InitialDataChangeEvent(path, data.getData());
     }
 
+    /*
+     * Suppressing warnings here allows us to fool the compiler enough
+     * such that we can reuse a single function for all applicable types
+     * and present it in a type-safe manner to our users.
+     */
     @SuppressWarnings({ "unchecked", "rawtypes" })
     public static <V> Function<Identifiable<V>, V> identifierExtractor() {
         return (Function) EXTRACT_IDENTIFIER;
@@ -90,7 +94,6 @@ public final class StoreUtils {
         public NormalizedNode<?, ?> getUpdatedSubtree() {
             return data;
         }
-
     }
 
     public static <V> Set<V> toIdentifierSet(final Iterable<? extends Identifiable<V>> children) {
@@ -101,7 +104,6 @@ public final class StoreUtils {
         StringBuilder builder = new StringBuilder();
         toStringTree(builder, metaNode, 0);
         return builder.toString();
-
     }
 
     private static void toStringTree(final StringBuilder builder, final StoreMetadataNode metaNode, final int offset) {
@@ -109,15 +111,15 @@ public final class StoreUtils {
         builder.append(prefix).append(toStringTree(metaNode.getIdentifier()));
         NormalizedNode<?, ?> dataNode = metaNode.getData();
         if (dataNode instanceof NormalizedNodeContainer<?, ?, ?>) {
-            builder.append(" {").append("\n");
+            builder.append(" {\n");
             for (StoreMetadataNode child : metaNode.getChildren()) {
                 toStringTree(builder, child, offset + 4);
             }
-            builder.append(prefix).append("}");
+            builder.append(prefix).append('}');
         } else {
-            builder.append(" ").append(dataNode.getValue());
+            builder.append(' ').append(dataNode.getValue());
         }
-        builder.append("\n");
+        builder.append('\n');
     }
 
     private static String toStringTree(final PathArgument identifier) {