From 77f332b908f558ff75255fc4f179e66a9ea8900b Mon Sep 17 00:00:00 2001 From: Tony Tkacik Date: Tue, 28 Apr 2015 17:46:29 +0200 Subject: [PATCH] Fixed some major sonar warnings in yang-data-api Change-Id: I53006edaa2963e50ff8366c76d2e67778499b345 Signed-off-by: Tony Tkacik Signed-off-by: Robert Varga --- .../yangtools/yang/common/QName.java | 7 +++-- .../NormalizedNodeStreamAttributeWriter.java | 10 +++---- .../stream/NormalizedNodeStreamWriter.java | 27 +++++++++---------- .../schema/stream/NormalizedNodeWriter.java | 12 ++++----- 4 files changed, 27 insertions(+), 29 deletions(-) diff --git a/yang/yang-common/src/main/java/org/opendaylight/yangtools/yang/common/QName.java b/yang/yang-common/src/main/java/org/opendaylight/yangtools/yang/common/QName.java index 4bb9aede0f..588579fdb9 100644 --- a/yang/yang-common/src/main/java/org/opendaylight/yangtools/yang/common/QName.java +++ b/yang/yang-common/src/main/java/org/opendaylight/yangtools/yang/common/QName.java @@ -8,6 +8,8 @@ package org.opendaylight.yangtools.yang.common; import static org.opendaylight.yangtools.yang.common.SimpleDateFormatUtil.getRevisionFormat; + +import com.google.common.base.Preconditions; import java.io.Serializable; import java.net.URI; import java.net.URISyntaxException; @@ -233,10 +235,7 @@ public final class QName implements Immutable, Serializable, Comparable { * @return Instance of QName */ public static QName create(final QNameModule qnameModule, final String localName) { - if (qnameModule == null) { - throw new NullPointerException("module may not be null"); - } - return new QName(qnameModule, localName); + return new QName(Preconditions.checkNotNull(qnameModule,"module may not be null"), localName); } /** diff --git a/yang/yang-data-api/src/main/java/org/opendaylight/yangtools/yang/data/api/schema/stream/NormalizedNodeStreamAttributeWriter.java b/yang/yang-data-api/src/main/java/org/opendaylight/yangtools/yang/data/api/schema/stream/NormalizedNodeStreamAttributeWriter.java index ca0e3428bb..ae4f37d51e 100644 --- a/yang/yang-data-api/src/main/java/org/opendaylight/yangtools/yang/data/api/schema/stream/NormalizedNodeStreamAttributeWriter.java +++ b/yang/yang-data-api/src/main/java/org/opendaylight/yangtools/yang/data/api/schema/stream/NormalizedNodeStreamAttributeWriter.java @@ -17,13 +17,13 @@ import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; */ public interface NormalizedNodeStreamAttributeWriter extends NormalizedNodeStreamWriter { - void leafNode(YangInstanceIdentifier.NodeIdentifier name, Object value, Map attributes) throws IOException, IllegalArgumentException; + void leafNode(YangInstanceIdentifier.NodeIdentifier name, Object value, Map attributes) throws IOException; - void leafSetEntryNode(Object value, Map attributes) throws IOException, IllegalArgumentException; + void leafSetEntryNode(Object value, Map attributes) throws IOException; - void startContainerNode(YangInstanceIdentifier.NodeIdentifier name, int childSizeHint, Map attributes) throws IOException, IllegalArgumentException; + void startContainerNode(YangInstanceIdentifier.NodeIdentifier name, int childSizeHint, Map attributes) throws IOException; - void startUnkeyedListItem(YangInstanceIdentifier.NodeIdentifier name, int childSizeHint, Map attributes) throws IOException, IllegalStateException; + void startUnkeyedListItem(YangInstanceIdentifier.NodeIdentifier name, int childSizeHint, Map attributes) throws IOException; - void startMapEntryNode(YangInstanceIdentifier.NodeIdentifierWithPredicates identifier, int childSizeHint, Map attributes) throws IOException, IllegalArgumentException; + void startMapEntryNode(YangInstanceIdentifier.NodeIdentifierWithPredicates identifier, int childSizeHint, Map attributes) throws IOException; } diff --git a/yang/yang-data-api/src/main/java/org/opendaylight/yangtools/yang/data/api/schema/stream/NormalizedNodeStreamWriter.java b/yang/yang-data-api/src/main/java/org/opendaylight/yangtools/yang/data/api/schema/stream/NormalizedNodeStreamWriter.java index 1165612038..5f4e66c5c6 100644 --- a/yang/yang-data-api/src/main/java/org/opendaylight/yangtools/yang/data/api/schema/stream/NormalizedNodeStreamWriter.java +++ b/yang/yang-data-api/src/main/java/org/opendaylight/yangtools/yang/data/api/schema/stream/NormalizedNodeStreamWriter.java @@ -10,7 +10,6 @@ package org.opendaylight.yangtools.yang.data.api.schema.stream; import java.io.Closeable; import java.io.Flushable; import java.io.IOException; - import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.AugmentationIdentifier; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates; @@ -111,7 +110,7 @@ public interface NormalizedNodeStreamWriter extends Closeable, Flushable { * choice unkeyed list node. * @throws IOException if an underlying IO error occurs */ - void leafNode(NodeIdentifier name, Object value) throws IOException, IllegalArgumentException; + void leafNode(NodeIdentifier name, Object value) throws IOException; /** * @@ -137,7 +136,7 @@ public interface NormalizedNodeStreamWriter extends Closeable, Flushable { * choice unkeyed list node. * @throws IOException if an underlying IO error occurs */ - void startLeafSet(NodeIdentifier name, int childSizeHint) throws IOException, IllegalArgumentException; + void startLeafSet(NodeIdentifier name, int childSizeHint) throws IOException; /** * Emits a leaf set entry node @@ -150,7 +149,7 @@ public interface NormalizedNodeStreamWriter extends Closeable, Flushable { * If node was emitted outside leaf set node. * @throws IOException if an underlying IO error occurs */ - void leafSetEntryNode(Object value) throws IOException, IllegalArgumentException; + void leafSetEntryNode(Object value) throws IOException; /** * @@ -187,7 +186,7 @@ public interface NormalizedNodeStreamWriter extends Closeable, Flushable { * choice unkeyed list node. * @throws IOException if an underlying IO error occurs */ - void startContainerNode(NodeIdentifier name, int childSizeHint) throws IOException, IllegalArgumentException; + void startContainerNode(NodeIdentifier name, int childSizeHint) throws IOException; /** * @@ -214,7 +213,7 @@ public interface NormalizedNodeStreamWriter extends Closeable, Flushable { * choice unkeyed list node. * @throws IOException if an underlying IO error occurs */ - void startUnkeyedList(NodeIdentifier name, int childSizeHint) throws IOException, IllegalArgumentException; + void startUnkeyedList(NodeIdentifier name, int childSizeHint) throws IOException; /** * Emits start of new unkeyed list item. @@ -242,7 +241,7 @@ public interface NormalizedNodeStreamWriter extends Closeable, Flushable { * If node was emitted outside unkeyed list node. * @throws IOException if an underlying IO error occurs */ - void startUnkeyedListItem(NodeIdentifier name, int childSizeHint) throws IOException, IllegalStateException; + void startUnkeyedListItem(NodeIdentifier name, int childSizeHint) throws IOException; /** * @@ -264,7 +263,7 @@ public interface NormalizedNodeStreamWriter extends Closeable, Flushable { * choice unkeyed list node. * @throws IOException if an underlying IO error occurs */ - void startMapNode(NodeIdentifier name, int childSizeHint) throws IOException, IllegalArgumentException; + void startMapNode(NodeIdentifier name, int childSizeHint) throws IOException; /** * @@ -294,7 +293,7 @@ public interface NormalizedNodeStreamWriter extends Closeable, Flushable { * If node was emitted outside map entry node. * @throws IOException if an underlying IO error occurs */ - void startMapEntryNode(NodeIdentifierWithPredicates identifier, int childSizeHint) throws IOException, IllegalArgumentException; + void startMapEntryNode(NodeIdentifierWithPredicates identifier, int childSizeHint) throws IOException; /** * @@ -315,7 +314,7 @@ public interface NormalizedNodeStreamWriter extends Closeable, Flushable { * choice unkeyed list node. * @throws IOException if an underlying IO error occurs */ - void startOrderedMapNode(NodeIdentifier name, int childSizeHint) throws IOException, IllegalArgumentException; + void startOrderedMapNode(NodeIdentifier name, int childSizeHint) throws IOException; /** * @@ -331,7 +330,7 @@ public interface NormalizedNodeStreamWriter extends Closeable, Flushable { * choice unkeyed list node. * @throws IOException if an underlying IO error occurs */ - void startChoiceNode(NodeIdentifier name, int childSizeHint) throws IOException, IllegalArgumentException; + void startChoiceNode(NodeIdentifier name, int childSizeHint) throws IOException; /** * Emits start of augmentation node. @@ -357,7 +356,7 @@ public interface NormalizedNodeStreamWriter extends Closeable, Flushable { * If augmentation is invalid in current context. * @throws IOException if an underlying IO error occurs */ - void startAugmentationNode(AugmentationIdentifier identifier) throws IOException, IllegalArgumentException; + void startAugmentationNode(AugmentationIdentifier identifier) throws IOException; /** * Emits anyxml node event. @@ -370,7 +369,7 @@ public interface NormalizedNodeStreamWriter extends Closeable, Flushable { * choice unkeyed list node. * @throws IOException if an underlying IO error occurs */ - void anyxmlNode(NodeIdentifier name, Object value) throws IOException, IllegalArgumentException; + void anyxmlNode(NodeIdentifier name, Object value) throws IOException; /** * Emits end event for node. @@ -378,7 +377,7 @@ public interface NormalizedNodeStreamWriter extends Closeable, Flushable { * @throws IllegalStateException If there is no start* event to be closed. * @throws IOException if an underlying IO error occurs */ - void endNode() throws IOException, IllegalStateException; + void endNode() throws IOException; @Override void close() throws IOException; diff --git a/yang/yang-data-api/src/main/java/org/opendaylight/yangtools/yang/data/api/schema/stream/NormalizedNodeWriter.java b/yang/yang-data-api/src/main/java/org/opendaylight/yangtools/yang/data/api/schema/stream/NormalizedNodeWriter.java index 9a0a7bd499..1c7147f3c0 100644 --- a/yang/yang-data-api/src/main/java/org/opendaylight/yangtools/yang/data/api/schema/stream/NormalizedNodeWriter.java +++ b/yang/yang-data-api/src/main/java/org/opendaylight/yangtools/yang/data/api/schema/stream/NormalizedNodeWriter.java @@ -165,7 +165,7 @@ public class NormalizedNodeWriter implements Closeable, Flushable { * @throws IOException when the writer reports it */ protected final boolean writeChildren(final Iterable> children) throws IOException { - for (NormalizedNode child : children) { + for (final NormalizedNode child : children) { write(child); } @@ -245,16 +245,16 @@ public class NormalizedNodeWriter implements Closeable, Flushable { @Override protected boolean writeMapEntryNode(final MapEntryNode node) throws IOException { - final NormalizedNodeStreamWriter writer = getWriter(); - if(writer instanceof NormalizedNodeStreamAttributeWriter) { - ((NormalizedNodeStreamAttributeWriter) writer).startMapEntryNode(node.getIdentifier(), childSizeHint(node.getValue()), node.getAttributes()); + final NormalizedNodeStreamWriter nnWriter = getWriter(); + if(nnWriter instanceof NormalizedNodeStreamAttributeWriter) { + ((NormalizedNodeStreamAttributeWriter) nnWriter).startMapEntryNode(node.getIdentifier(), childSizeHint(node.getValue()), node.getAttributes()); } else { - writer.startMapEntryNode(node.getIdentifier(), childSizeHint(node.getValue())); + nnWriter.startMapEntryNode(node.getIdentifier(), childSizeHint(node.getValue())); } final Set qnames = node.getIdentifier().getKeyValues().keySet(); // Write out all the key children - for (QName qname : qnames) { + for (final QName qname : qnames) { final Optional> child = node.getChild(new NodeIdentifier(qname)); if (child.isPresent()) { write(child.get()); -- 2.36.6