Fix CS warnings in sal-clustering-commons and enable enforcement
authorTom Pantelis <tpanteli@brocade.com>
Wed, 12 Oct 2016 20:28:13 +0000 (16:28 -0400)
committerTom Pantelis <tpanteli@brocade.com>
Fri, 21 Oct 2016 11:36:17 +0000 (11:36 +0000)
Fixed checkstyle warnings and enabled enforcement. Most of the
warnings/changes were for:
 - white space before if/for/while/catch
 - white space before beginning brace
 - line too long
 - illegal catching of Exception (suppressed)
 - variable name too short
 - indentation
 - local vars/params hiding a field
 - putting overloaded methods close to one another
 - remove unused vars
 - convert functional interfaces to lambdas (eclipse save action)
 - empty catch block - added comment or Throwables.propagate as appropriate
 - missing period after first sentence in javadoc
 - missing first sentence in javadoc
 - adding final for locals declared too far from first usage

Change-Id: I0a6690f97820e8fb670f209221d8e4e2f1cf5d8b
Signed-off-by: Tom Pantelis <tpanteli@brocade.com>
56 files changed:
java/org/opendaylight/controller/cluster/ActorSystemProvider.java
java/org/opendaylight/controller/cluster/DataPersistenceProvider.java
java/org/opendaylight/controller/cluster/DelegatingPersistentDataProvider.java
java/org/opendaylight/controller/cluster/NonPersistentDataProvider.java
java/org/opendaylight/controller/cluster/PersistentDataProvider.java
java/org/opendaylight/controller/cluster/common/actor/AbstractConfig.java
java/org/opendaylight/controller/cluster/common/actor/AbstractUntypedActor.java
java/org/opendaylight/controller/cluster/common/actor/AbstractUntypedActorWithMetering.java
java/org/opendaylight/controller/cluster/common/actor/AbstractUntypedPersistentActor.java
java/org/opendaylight/controller/cluster/common/actor/AbstractUntypedPersistentActorWithMetering.java
java/org/opendaylight/controller/cluster/common/actor/CommonConfig.java
java/org/opendaylight/controller/cluster/common/actor/ExplicitAsk.java
java/org/opendaylight/controller/cluster/common/actor/FileAkkaConfigurationReader.java
java/org/opendaylight/controller/cluster/common/actor/MessageTracker.java
java/org/opendaylight/controller/cluster/common/actor/MeteredBoundedMailbox.java
java/org/opendaylight/controller/cluster/common/actor/MeteringBehavior.java
java/org/opendaylight/controller/cluster/common/actor/Monitor.java
java/org/opendaylight/controller/cluster/common/actor/QuarantinedMonitorActor.java
java/org/opendaylight/controller/cluster/common/actor/UnifiedConfig.java
java/org/opendaylight/controller/cluster/datastore/node/NormalizedNodeToNodeCodec.java
java/org/opendaylight/controller/cluster/datastore/node/utils/AugmentationIdentifierGenerator.java
java/org/opendaylight/controller/cluster/datastore/node/utils/NodeIdentifierFactory.java
java/org/opendaylight/controller/cluster/datastore/node/utils/NodeIdentifierGenerator.java
java/org/opendaylight/controller/cluster/datastore/node/utils/NodeIdentifierWithPredicatesGenerator.java
java/org/opendaylight/controller/cluster/datastore/node/utils/NodeIdentifierWithValueGenerator.java
java/org/opendaylight/controller/cluster/datastore/node/utils/NormalizedNodeGetter.java
java/org/opendaylight/controller/cluster/datastore/node/utils/NormalizedNodeNavigator.java
java/org/opendaylight/controller/cluster/datastore/node/utils/NormalizedNodePrinter.java [deleted file]
java/org/opendaylight/controller/cluster/datastore/node/utils/PathUtils.java
java/org/opendaylight/controller/cluster/datastore/node/utils/QNameFactory.java
java/org/opendaylight/controller/cluster/datastore/node/utils/serialization/NormalizedNodeDeSerializationContext.java
java/org/opendaylight/controller/cluster/datastore/node/utils/serialization/NormalizedNodeSerializationContext.java
java/org/opendaylight/controller/cluster/datastore/node/utils/serialization/NormalizedNodeSerializer.java
java/org/opendaylight/controller/cluster/datastore/node/utils/serialization/NormalizedNodeType.java
java/org/opendaylight/controller/cluster/datastore/node/utils/serialization/PathArgumentSerializer.java
java/org/opendaylight/controller/cluster/datastore/node/utils/serialization/PathArgumentType.java
java/org/opendaylight/controller/cluster/datastore/node/utils/serialization/QNameSerializationContextImpl.java
java/org/opendaylight/controller/cluster/datastore/node/utils/serialization/ValueSerializer.java
java/org/opendaylight/controller/cluster/datastore/node/utils/serialization/ValueType.java
java/org/opendaylight/controller/cluster/datastore/node/utils/stream/AbstractNormalizedNodeDataOutput.java
java/org/opendaylight/controller/cluster/datastore/node/utils/stream/NormalizedNodeDataOutput.java
java/org/opendaylight/controller/cluster/datastore/node/utils/stream/NormalizedNodeInputStreamReader.java
java/org/opendaylight/controller/cluster/datastore/node/utils/stream/NormalizedNodeOutputStreamWriter.java
java/org/opendaylight/controller/cluster/datastore/node/utils/stream/PathArgumentTypes.java
java/org/opendaylight/controller/cluster/datastore/node/utils/stream/ValueTypes.java
java/org/opendaylight/controller/cluster/datastore/node/utils/transformer/NormalizedNodeBuilderWrapper.java
java/org/opendaylight/controller/cluster/datastore/node/utils/transformer/NormalizedNodePruner.java
java/org/opendaylight/controller/cluster/datastore/util/InstanceIdentifierUtils.java
java/org/opendaylight/controller/cluster/notifications/RegisterRoleChangeListener.java
java/org/opendaylight/controller/cluster/notifications/RegisterRoleChangeListenerReply.java
java/org/opendaylight/controller/cluster/notifications/RoleChangeNotification.java
java/org/opendaylight/controller/cluster/notifications/RoleChangeNotifier.java
java/org/opendaylight/controller/cluster/notifications/RoleChanged.java
java/org/opendaylight/controller/cluster/raft/protobuff/client/messages/Payload.java
java/org/opendaylight/controller/cluster/schema/provider/impl/RemoteSchemaProvider.java
java/org/opendaylight/controller/cluster/schema/provider/impl/RemoteYangTextSourceProviderImpl.java

index 31ce16a1c01b071de0c4d8783763ea11dc8ca382..dcb3b6b714150202bc4b68840b816a07a853d252 100644 (file)
@@ -17,8 +17,11 @@ import org.opendaylight.yangtools.concepts.ListenerRegistration;
  * @author Thomas Pantelis
  */
 public interface ActorSystemProvider {
+
     /**
-     * @return the current ActorSystem.
+     * Returns the ActorSystem.
+     *
+     * @return the ActorSystem.
      */
     @Nonnull
     ActorSystem getActorSystem();
index 730310e22e2f37d5153c2c918ea5b458b3531fe2..d136d45bc7aa6bbfb4ea9d0092f24a4e849c10fe 100644 (file)
@@ -16,44 +16,49 @@ import akka.persistence.SnapshotSelectionCriteria;
  * API.
  */
 public interface DataPersistenceProvider {
+
     /**
-     * @return false if recovery is not applicable. In that case the provider is not persistent and may not have
-     * anything to be recovered
+     * Returns whether or not persistence recovery is applicable/enabled.
+     *
+     * @return true if recovery is applicable, otherwise false, in which case the provider is not persistent and may
+     *         not have anything to be recovered
      */
     boolean isRecoveryApplicable();
 
     /**
-     * Persist a journal entry.
+     * Persists an entry to he applicable synchronously.
      *
-     * @param o
-     * @param procedure
-     * @param <T>
+     * @param entry the journal entry to persist
+     * @param procedure the callback when persistence is complete
+     * @param <T> the type of the journal entry
      */
-    <T> void persist(T o, Procedure<T> procedure);
+    <T> void persist(T entry, Procedure<T> procedure);
 
     /**
-     * Save a snapshot
+     * Saves a snapshot.
      *
-     * @param o
+     * @param snapshot the snapshot object to save
      */
-    void saveSnapshot(Object o);
+    void saveSnapshot(Object snapshot);
 
     /**
-     * Delete snapshots based on the criteria
+     * Deletes snapshots based on the given criteria.
      *
-     * @param criteria
+     * @param criteria the search criteria
      */
     void deleteSnapshots(SnapshotSelectionCriteria criteria);
 
     /**
-     * Delete journal entries up to the sequence number
+     * Deletes journal entries up to the given sequence number.
      *
-     * @param sequenceNumber
+     * @param sequenceNumber the sequence number
      */
     void deleteMessages(long sequenceNumber);
 
     /**
      * Returns the last sequence number contained in the journal.
+     *
+     * @return the last sequence number
      */
     long getLastSequenceNumber();
 }
index e27fa26aebb3953f6a0ddd35c056a812a00e833c..c513e38fc6d03bcfc19a8d903913996635955e7b 100644 (file)
@@ -36,13 +36,13 @@ public class DelegatingPersistentDataProvider implements DataPersistenceProvider
     }
 
     @Override
-    public <T> void persist(T o, Procedure<T> procedure) {
-        delegate.persist(o, procedure);
+    public <T> void persist(T entry, Procedure<T> procedure) {
+        delegate.persist(entry, procedure);
     }
 
     @Override
-    public void saveSnapshot(Object o) {
-        delegate.saveSnapshot(o);
+    public void saveSnapshot(Object entry) {
+        delegate.saveSnapshot(entry);
     }
 
     @Override
index d1af58f18b426c19d7c70ef0d0a44734948e4b72..91ae8f118ebeaed44154bc1531950eb792bd81e8 100644 (file)
@@ -24,28 +24,32 @@ public class NonPersistentDataProvider implements DataPersistenceProvider {
     }
 
     @Override
-    public <T> void persist(T o, Procedure<T> procedure) {
+    @SuppressWarnings("checkstyle:IllegalCatch")
+    public <T> void persist(T entry, Procedure<T> procedure) {
         try {
-            procedure.apply(o);
+            procedure.apply(entry);
         } catch (Exception e) {
             LOG.error("An unexpected error occurred", e);
         }
     }
 
     @Override
-    public void saveSnapshot(Object o) {
+    public void saveSnapshot(Object snapshot) {
+        // no-op
     }
 
     @Override
     public void deleteSnapshots(SnapshotSelectionCriteria criteria) {
+        // no-op
     }
 
     @Override
     public void deleteMessages(long sequenceNumber) {
+        // no-op
     }
 
     @Override
     public long getLastSequenceNumber() {
         return -1;
     }
-}
\ No newline at end of file
+}
index 4ccd5f4d29cc39a695772f8e36a800d078fcde79..b4f08c0394b38c9ef88772760b084ff5dd7db6df 100644 (file)
@@ -29,13 +29,13 @@ public class PersistentDataProvider implements DataPersistenceProvider {
     }
 
     @Override
-    public <T> void persist(T o, Procedure<T> procedure) {
-        persistentActor.persist(o, procedure);
+    public <T> void persist(T entry, Procedure<T> procedure) {
+        persistentActor.persist(entry, procedure);
     }
 
     @Override
-    public void saveSnapshot(Object o) {
-        persistentActor.saveSnapshot(o);
+    public void saveSnapshot(Object snapshot) {
+        persistentActor.saveSnapshot(snapshot);
     }
 
     @Override
@@ -52,4 +52,4 @@ public class PersistentDataProvider implements DataPersistenceProvider {
     public long getLastSequenceNumber() {
         return persistentActor.lastSequenceNr();
     }
-}
\ No newline at end of file
+}
index 1a331b7e99d28216dbad982d36916d1b5fa3d4d0..976d48d270c8b9fcf14706f3bdfd1cb41a05938d 100644 (file)
@@ -18,7 +18,7 @@ public abstract class AbstractConfig implements UnifiedConfig {
 
     private final Config config;
 
-    public AbstractConfig(Config config){
+    public AbstractConfig(Config config) {
         this.config = config;
     }
 
@@ -27,19 +27,20 @@ public abstract class AbstractConfig implements UnifiedConfig {
         return config;
     }
 
-    public static abstract class Builder<T extends Builder<T>> {
+    public abstract static class Builder<T extends Builder<T>> {
         protected Map<String, Object> configHolder;
         protected Config fallback;
 
         private final String actorSystemName;
 
-        public Builder(String actorSystemName){
+        public Builder(String actorSystemName) {
             Preconditions.checkArgument(actorSystemName != null, "Actor system name must not be null");
             this.actorSystemName = actorSystemName;
             configHolder = new HashMap<>();
         }
 
-        public T withConfigReader(AkkaConfigurationReader reader){
+        @SuppressWarnings("unchecked")
+        public T withConfigReader(AkkaConfigurationReader reader) {
             fallback = reader.read().getConfig(actorSystemName);
             return (T)this;
         }
index ca303a5c12ee54749b1ddcbaf24e1cb4bf8f522b..3a4419610a155d4cc6c853709cf0b8e1296ac544 100644 (file)
@@ -14,6 +14,8 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 public abstract class AbstractUntypedActor extends UntypedActor {
+    // The member name should be lower case but it's referenced in many subclasses. Suppressing the CS warning for now.
+    @SuppressWarnings("checkstyle:MemberName")
     protected final Logger LOG = LoggerFactory.getLogger(getClass());
 
     protected AbstractUntypedActor() {
@@ -30,8 +32,8 @@ public abstract class AbstractUntypedActor extends UntypedActor {
      * Receive and handle an incoming message. If the implementation does not handle this particular message,
      * it should call {@link #ignoreMessage(Object)} or {@link #unknownMessage(Object)}.
      *
-     * @param message Incoming message
-     * @throws Exception
+     * @param message the incoming message
+     * @throws Exception on message failure
      */
     protected abstract void handleReceive(Object message) throws Exception;
 
index 04d9a43c2d40c16c3e0058f2be5bf5256df70498..2124b24faf29ac92859b50834c8cbbe654a84bc3 100644 (file)
@@ -16,17 +16,19 @@ public abstract class AbstractUntypedActorWithMetering extends AbstractUntypedAc
     private String actorNameOverride;
 
     public AbstractUntypedActorWithMetering() {
-        if (isMetricsCaptureEnabled())
+        if (isMetricsCaptureEnabled()) {
             getContext().become(new MeteringBehavior(this));
+        }
     }
 
-    public AbstractUntypedActorWithMetering(String actorNameOverride){
+    public AbstractUntypedActorWithMetering(String actorNameOverride) {
         this.actorNameOverride = actorNameOverride;
-        if (isMetricsCaptureEnabled())
+        if (isMetricsCaptureEnabled()) {
             getContext().become(new MeteringBehavior(this));
+        }
     }
 
-    private boolean isMetricsCaptureEnabled(){
+    private boolean isMetricsCaptureEnabled() {
         CommonConfig config = new CommonConfig(getContext().system().settings().config());
         return config.isMetricCaptureEnabled();
     }
index e378fdc561fa2aedbff1d7e9719c424bec9a08e1..c50ec64e841d288bcb8fafd4f0c10745042db314 100644 (file)
@@ -14,6 +14,8 @@ import org.slf4j.LoggerFactory;
 
 public abstract class AbstractUntypedPersistentActor extends UntypedPersistentActor {
 
+    // The member name should be lower case but it's referenced in many subclasses. Suppressing the CS warning for now.
+    @SuppressWarnings("checkstyle:MemberName")
     protected final Logger LOG = LoggerFactory.getLogger(getClass());
 
     protected AbstractUntypedPersistentActor() {
index 365a5bd0157c1861b026c645115f6235b0350f0b..ed03d334919ed7b2422a64802cf8dceef0cb52b3 100644 (file)
@@ -13,11 +13,12 @@ package org.opendaylight.controller.cluster.common.actor;
 public abstract class AbstractUntypedPersistentActorWithMetering extends AbstractUntypedPersistentActor {
 
     public AbstractUntypedPersistentActorWithMetering() {
-        if (isMetricsCaptureEnabled())
+        if (isMetricsCaptureEnabled()) {
             getContext().become(new MeteringBehavior(this));
+        }
     }
 
-    private boolean isMetricsCaptureEnabled(){
+    private boolean isMetricsCaptureEnabled() {
         CommonConfig config = new CommonConfig(getContext().system().settings().config());
         return config.isMetricCaptureEnabled();
     }
index 746ef4ebb1385387b2c2167e82d148e8cab82a23..84ac92e0eddeea5f400e0bd03c6b5488fcecab13 100644 (file)
@@ -7,15 +7,13 @@
  */
 package org.opendaylight.controller.cluster.common.actor;
 
-
 import com.google.common.base.Preconditions;
 import com.typesafe.config.Config;
-import scala.concurrent.duration.Duration;
-import scala.concurrent.duration.FiniteDuration;
-
 import java.util.HashMap;
 import java.util.Map;
 import java.util.concurrent.TimeUnit;
+import scala.concurrent.duration.Duration;
+import scala.concurrent.duration.FiniteDuration;
 
 public class CommonConfig extends AbstractConfig {
 
@@ -43,8 +41,8 @@ public class CommonConfig extends AbstractConfig {
         return get().getString(TAG_ACTOR_SYSTEM_NAME);
     }
 
-    public boolean isMetricCaptureEnabled(){
-        if (cachedMetricCaptureEnableFlag != null){
+    public boolean isMetricCaptureEnabled() {
+        if (cachedMetricCaptureEnableFlag != null) {
             return cachedMetricCaptureEnableFlag;
         }
 
@@ -89,7 +87,7 @@ public class CommonConfig extends AbstractConfig {
         return cachedMailBoxPushTimeout;
     }
 
-    public static class Builder<T extends Builder<T>> extends AbstractConfig.Builder<T>{
+    public static class Builder<T extends Builder<T>> extends AbstractConfig.Builder<T> {
 
         public Builder(String actorSystemName) {
             super(actorSystemName);
@@ -101,11 +99,13 @@ public class CommonConfig extends AbstractConfig {
             configHolder.put(TAG_MAILBOX, new HashMap<String, Object>());
         }
 
+        @SuppressWarnings("unchecked")
         public T metricCaptureEnabled(boolean enabled) {
             configHolder.put(TAG_METRIC_CAPTURE_ENABLED, String.valueOf(enabled));
             return (T)this;
         }
 
+        @SuppressWarnings("unchecked")
         public T mailboxCapacity(int capacity) {
             Preconditions.checkArgument(capacity > 0, "mailbox capacity must be >0");
 
@@ -114,7 +114,8 @@ public class CommonConfig extends AbstractConfig {
             return (T)this;
         }
 
-        public T mailboxPushTimeout(String timeout){
+        @SuppressWarnings("unchecked")
+        public T mailboxPushTimeout(String timeout) {
             Duration pushTimeout = Duration.create(timeout);
             Preconditions.checkArgument(pushTimeout.isFinite(), "invalid value for mailbox push timeout");
 
index c1f7c8b2e57def8044dbf60d3af83c9e8cdb35dc..e241d880c97712d530fe86f3996a012a11e1b1d9 100644 (file)
@@ -53,7 +53,8 @@ public final class ExplicitAsk {
         return ASK_SUPPORT.ask(actor, (Function1<ActorRef, Object>)function, timeout);
     }
 
-    public static Future<Object> ask(final ActorRef actor, final Function<ActorRef, ?> function, final Timeout timeout) {
+    public static Future<Object> ask(final ActorRef actor, final Function<ActorRef, ?> function,
+            final Timeout timeout) {
         return ask(actor, toScala(function), timeout);
     }
 
index 1e3adf9d391051ef2173de187004c3c6edaa6e40..883dbd7210a97f320c12e29d2a6353d4a9b7467d 100644 (file)
@@ -23,7 +23,7 @@ public class FileAkkaConfigurationReader implements AkkaConfigurationReader {
         Preconditions.checkState(customConfigFile.exists(), "%s is missing", customConfigFile);
 
         File factoryConfigFile = new File(FACTORY_AKKA_CONF_PATH);
-        if(factoryConfigFile.exists()) {
+        if (factoryConfigFile.exists()) {
             return ConfigFactory.parseFile(customConfigFile).withFallback(ConfigFactory.parseFile(factoryConfigFile));
         }
 
index a602136229bce2a78faf805f34ad64ed651c0758..326430922c08705308e77ce835dcdd56fb46297d 100644 (file)
@@ -10,6 +10,7 @@ package org.opendaylight.controller.cluster.common.actor;
 
 import static java.util.concurrent.TimeUnit.MILLISECONDS;
 import static java.util.concurrent.TimeUnit.NANOSECONDS;
+
 import com.google.common.annotations.Beta;
 import com.google.common.annotations.VisibleForTesting;
 import com.google.common.base.Optional;
@@ -56,7 +57,7 @@ import org.slf4j.LoggerFactory;
 @Beta
 @NotThreadSafe
 public final class MessageTracker {
-    public static abstract class Context implements AutoCloseable {
+    public abstract static class Context implements AutoCloseable {
         Context() {
             // Hidden to prevent outside instantiation
         }
@@ -69,7 +70,9 @@ public final class MessageTracker {
 
     public interface Error {
         Object getLastExpectedMessage();
+
         Object getCurrentExpectedMessage();
+
         List<MessageProcessingTime> getMessageProcessingTimesSinceLastExpectedMessage();
     }
 
@@ -85,12 +88,11 @@ public final class MessageTracker {
 
         @Override
         public String toString() {
-            return "MessageProcessingTime{" +
-                    "messageClass=" + messageClass.getSimpleName() +
-                    ", elapsedTimeInMillis=" + NANOSECONDS.toMillis(elapsedTimeInNanos) +
-                    '}';
+            return "MessageProcessingTime [messageClass=" + messageClass + ", elapsedTimeInMillis="
+                   + NANOSECONDS.toMillis(elapsedTimeInNanos) + "]";
         }
 
+
         public Class<?> getMessageClass() {
             return messageClass;
         }
@@ -139,9 +141,10 @@ public final class MessageTracker {
     }
 
     /**
+     * Constructs an instance.
      *
-     * @param expectedMessageClass The class of the message to track
-     * @param expectedArrivalIntervalInMillis The expected arrival interval between two instances of the expected
+     * @param expectedMessageClass the class of the message to track
+     * @param expectedArrivalIntervalInMillis the expected arrival interval between two instances of the expected
      *                                        message
      */
     public MessageTracker(final Class<?> expectedMessageClass, final long expectedArrivalIntervalInMillis) {
@@ -234,6 +237,7 @@ public final class MessageTracker {
 
     private abstract class AbstractTimedContext extends Context {
         abstract Object message();
+
         abstract Stopwatch stopTimer();
 
         @Override
@@ -246,10 +250,10 @@ public final class MessageTracker {
         private final Stopwatch stopwatch = Stopwatch.createUnstarted(ticker);
         private Object message;
 
-        void reset(final Object message) {
-            this.message = Preconditions.checkNotNull(message);
+        void reset(final Object newMessage) {
+            this.message = Preconditions.checkNotNull(newMessage);
             Preconditions.checkState(!stopwatch.isRunning(),
-                "Trying to reset a context that is not done (%s). currentMessage = %s", this, message);
+                "Trying to reset a context that is not done (%s). currentMessage = %s", this, newMessage);
             stopwatch.start();
         }
 
index 7f3e1354cf0036797db96f947cae7d1e9dd253f1..60a5106db41b39a608aa8634de492d8c1ce249f2 100644 (file)
@@ -21,17 +21,16 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import scala.concurrent.duration.FiniteDuration;
 
-public class MeteredBoundedMailbox implements MailboxType, ProducesMessageQueue<MeteredBoundedMailbox.MeteredMessageQueue> {
-
-    private final Logger LOG = LoggerFactory.getLogger(MeteredBoundedMailbox.class);
+public class MeteredBoundedMailbox implements MailboxType,
+        ProducesMessageQueue<MeteredBoundedMailbox.MeteredMessageQueue> {
+    private static final Logger LOG = LoggerFactory.getLogger(MeteredBoundedMailbox.class);
+    private static final String QUEUE_SIZE = "q-size";
 
     private MeteredMessageQueue queue;
     private final Integer capacity;
     private final FiniteDuration pushTimeOut;
     private final MetricRegistry registry;
 
-    private final String QUEUE_SIZE = "q-size";
-
     public MeteredBoundedMailbox(ActorSystem.Settings settings, Config config) {
 
         CommonConfig commonConfig = new CommonConfig(settings.config());
@@ -57,8 +56,7 @@ public class MeteredBoundedMailbox implements MailboxType, ProducesMessageQueue<
         String actorName = owner.get().path().toStringWithoutAddress();
         String metricName = MetricRegistry.name(actorName, QUEUE_SIZE);
 
-        if (registry.getMetrics().containsKey(metricName))
-        {
+        if (registry.getMetrics().containsKey(metricName)) {
             return; //already registered
         }
 
@@ -75,16 +73,11 @@ public class MeteredBoundedMailbox implements MailboxType, ProducesMessageQueue<
         }
     }
 
-    private static Gauge<Integer> getQueueSizeGuage(final MeteredMessageQueue monitoredQueue ){
-        return new Gauge<Integer>() {
-            @Override
-            public Integer getValue() {
-                return monitoredQueue.size();
-            }
-        };
+    private static Gauge<Integer> getQueueSizeGuage(final MeteredMessageQueue monitoredQueue ) {
+        return () -> monitoredQueue.size();
     }
 
-    private void registerQueueSizeMetric(String metricName, Gauge<Integer> metric){
+    private void registerQueueSizeMetric(String metricName, Gauge<Integer> metric) {
         try {
             registry.register(metricName,metric);
         } catch (IllegalArgumentException e) {
index 36c35be30a4cc1c4438af53f7c2a558f4ad99ca8..45fe19333835e83feea0bee6a15a41f6e7959a61 100644 (file)
@@ -12,7 +12,6 @@ import akka.japi.Procedure;
 import com.codahale.metrics.MetricRegistry;
 import com.codahale.metrics.Timer;
 import com.google.common.base.Preconditions;
-import com.google.common.base.Throwables;
 import org.opendaylight.controller.cluster.reporting.MetricsReporter;
 
 /**
@@ -23,21 +22,22 @@ import org.opendaylight.controller.cluster.reporting.MetricsReporter;
  *     <li>message processing rate of actor's receive block</li>
  *     <li>message processing rate by message type</li>
  * </ul>
- *
  * The information is reported to {@link org.opendaylight.controller.cluster.reporting.MetricsReporter}
  */
 public class MeteringBehavior implements Procedure<Object> {
     public static final String DOMAIN = "org.opendaylight.controller.actor.metric";
 
+    private static final String MSG_PROCESSING_RATE = "msg-rate";
+
     private final UntypedActor meteredActor;
 
-    private final MetricRegistry METRICREGISTRY = MetricsReporter.getInstance(DOMAIN).getMetricsRegistry();
-    private final String MSG_PROCESSING_RATE = "msg-rate";
+    private final MetricRegistry metricRegistry = MetricsReporter.getInstance(DOMAIN).getMetricsRegistry();
 
     private String actorQualifiedName;
     private Timer msgProcessingTimer;
 
     /**
+     * Constructs an instance.
      *
      * @param actor whose behaviour needs to be metered
      */
@@ -59,11 +59,11 @@ public class MeteringBehavior implements Procedure<Object> {
     }
 
     private void init(final String actorName) {
-        actorQualifiedName = new StringBuilder(meteredActor.getSelf().path().parent().toStringWithoutAddress()).
-                append("/").append(actorName).toString();
+        actorQualifiedName = new StringBuilder(meteredActor.getSelf().path().parent().toStringWithoutAddress())
+                .append("/").append(actorName).toString();
 
         final String msgProcessingTime = MetricRegistry.name(actorQualifiedName, MSG_PROCESSING_RATE);
-        msgProcessingTimer = METRICREGISTRY.timer(msgProcessingTime);
+        msgProcessingTimer = metricRegistry.timer(msgProcessingTime);
     }
 
     /**
@@ -79,8 +79,8 @@ public class MeteringBehavior implements Procedure<Object> {
      * @see <a href="http://dropwizard.github.io/metrics/manual/core/#timers">
      *     http://dropwizard.github.io/metrics/manual/core/#timers</a>
      *
-     * @param message
-     * @throws Exception
+     * @param message the message to process
+     * @throws Exception on message failure
      */
     @Override
     public void apply(final Object message) throws Exception {
@@ -89,18 +89,13 @@ public class MeteringBehavior implements Procedure<Object> {
         final String msgProcessingTimeByMsgType =
                 MetricRegistry.name(actorQualifiedName, MSG_PROCESSING_RATE, messageType);
 
-        final Timer msgProcessingTimerByMsgType = METRICREGISTRY.timer(msgProcessingTimeByMsgType);
+        final Timer msgProcessingTimerByMsgType = metricRegistry.timer(msgProcessingTimeByMsgType);
 
         //start timers
         final Timer.Context context = msgProcessingTimer.time();
         final Timer.Context contextByMsgType = msgProcessingTimerByMsgType.time();
 
-        try {
-            meteredActor.onReceive(message);
-        } catch (Throwable t) {
-            Throwables.propagateIfPossible(t, Exception.class);
-            throw Throwables.propagate(t);
-        }
+        meteredActor.onReceive(message);
 
         //stop timers
         contextByMsgType.stop();
index f81b34aad843741fe41149164b9faa89cd586514..004d2897150b8c21a811f88c106094e7577d15bf 100644 (file)
@@ -9,14 +9,13 @@
 package org.opendaylight.controller.cluster.common.actor;
 
 import akka.actor.ActorRef;
-
 import java.io.Serializable;
 
 public class Monitor implements Serializable {
     private static final long serialVersionUID = 1L;
     private final ActorRef actorRef;
 
-    public Monitor(ActorRef actorRef){
+    public Monitor(ActorRef actorRef) {
         this.actorRef = actorRef;
     }
 
index a9f58898d412a94aba0bc42ea4bc5a36c159a62a..9cb592a4c7713f5d533870c92af38d0e0dfdf4e6 100644 (file)
@@ -23,12 +23,12 @@ import org.slf4j.LoggerFactory;
  * quarantined by another. Once this node gets quarantined, restart the ActorSystem to allow this
  * node to rejoin the cluster.
  *
- * @author Gary Wu <gary.wu1@huawei.com>
+ * @author Gary Wu gary.wu1@huawei.com
  *
  */
 public class QuarantinedMonitorActor extends UntypedActor {
 
-    private final Logger LOG = LoggerFactory.getLogger(QuarantinedMonitorActor.class);
+    private static final Logger LOG = LoggerFactory.getLogger(QuarantinedMonitorActor.class);
 
     public static final String ADDRESS = "quarantined-monitor";
 
@@ -55,7 +55,7 @@ public class QuarantinedMonitorActor extends UntypedActor {
 
         // check to see if we got quarantined by another node
 
-        if(quarantined) {
+        if (quarantined) {
             return;
         }
 
index 903987a0276364324936da9d99691e21ad30ea60..198ddf7ca88089d085aa0c95969bcdd4522ef3fd 100644 (file)
@@ -17,14 +17,14 @@ import com.typesafe.config.Config;
  *     <li>Config subsystem</li>
  *     <li>Akka configuration files</li>
  * </ul>
- *
  * Configurations defined in config subsystem takes precedence.
  */
 public interface UnifiedConfig {
 
     /**
-     * Returns an immutable instance of unified configuration
-     * @return
+     * Returns an immutable instance of unified configuration.
+     *
+     * @return a Config instance
      */
     Config get();
 }
index 5602b48e1b1664dc7d5b62abda1ad79bc35b7cbc..8ca0e76b014961fed6232839570cc23b71c97ee1 100644 (file)
@@ -16,7 +16,6 @@ import org.opendaylight.controller.protobuff.messages.common.NormalizedNodeMessa
 import org.opendaylight.controller.protobuff.messages.common.NormalizedNodeMessages.InstanceIdentifier;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
-import org.opendaylight.yangtools.yang.model.api.SchemaContext;
 
 public class NormalizedNodeToNodeCodec {
     public interface Encoded {
@@ -31,13 +30,10 @@ public class NormalizedNodeToNodeCodec {
         YangInstanceIdentifier getDecodedPath();
     }
 
-    private final SchemaContext ctx;
-
-    public NormalizedNodeToNodeCodec(final SchemaContext ctx){
-        this.ctx = ctx;
+    public NormalizedNodeToNodeCodec() {
     }
 
-    public NormalizedNodeMessages.Container encode(NormalizedNode<?,?> node){
+    public NormalizedNodeMessages.Container encode(NormalizedNode<?,?> node) {
         return encode(null, node).getEncodedNode();
     }
 
@@ -50,8 +46,8 @@ public class NormalizedNodeToNodeCodec {
         // Note: parent path is no longer used
         builder.setParentPath("");
 
-        if(node != null) {
-            if(path == null) {
+        if (node != null) {
+            if (path == null) {
                 builder.setNormalizedNode(NormalizedNodeSerializer.serialize(node));
             } else {
                 Serializer serializer = NormalizedNodeSerializer.newSerializer(node);
@@ -64,13 +60,13 @@ public class NormalizedNodeToNodeCodec {
     }
 
 
-    public NormalizedNode<?,?> decode(NormalizedNodeMessages.Node node){
+    public NormalizedNode<?,?> decode(NormalizedNodeMessages.Node node) {
         return decode(null, node).getDecodedNode();
     }
 
     public Decoded decode(NormalizedNodeMessages.InstanceIdentifier path,
             NormalizedNodeMessages.Node node) {
-        if(node.getIntType() < 0 || node.getSerializedSize() == 0){
+        if (node.getIntType() < 0 || node.getSerializedSize() == 0) {
             return new DecodedImpl(null, null);
         }
 
@@ -84,7 +80,7 @@ public class NormalizedNodeToNodeCodec {
         private final NormalizedNode<?, ?> decodedNode;
         private final YangInstanceIdentifier decodedPath;
 
-        public DecodedImpl(NormalizedNode<?, ?> decodedNode, YangInstanceIdentifier decodedPath) {
+        DecodedImpl(NormalizedNode<?, ?> decodedNode, YangInstanceIdentifier decodedPath) {
             this.decodedNode = decodedNode;
             this.decodedPath = decodedPath;
         }
index 296b744177f4ce82dbbfdb5282380b1085207952..a0a2d0408d5850090c70cec91d2b4984f393232c 100644 (file)
@@ -17,7 +17,8 @@ import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 
 public class AugmentationIdentifierGenerator {
-    private static final Pattern PATTERN = Pattern.compile("AugmentationIdentifier\\Q{\\EchildNames=\\Q[\\E(.*)\\Q]}\\E");
+    private static final Pattern PATTERN =
+            Pattern.compile("AugmentationIdentifier\\Q{\\EchildNames=\\Q[\\E(.*)\\Q]}\\E");
     private static final Splitter COMMA_SPLITTER = Splitter.on(',').trimResults();
 
     private final String id;
@@ -44,5 +45,4 @@ public class AugmentationIdentifierGenerator {
 
         return new YangInstanceIdentifier.AugmentationIdentifier(childNames);
     }
-
 }
index 08fd997aae4c936a33fa56eb26009b462ad8e7e3..acfb05fc389fe3d16bdc3d9d53b3610bbf061f77 100644 (file)
@@ -8,43 +8,43 @@
 
 package org.opendaylight.controller.cluster.datastore.node.utils;
 
-import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
-import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
-
 import java.util.HashMap;
 import java.util.Map;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
+import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
 
 public class NodeIdentifierFactory {
-    private static final Map<String, YangInstanceIdentifier.PathArgument> cache = new HashMap<>();
-    public static YangInstanceIdentifier.PathArgument getArgument(String id){
-        YangInstanceIdentifier.PathArgument value = cache.get(id);
-        if(value == null){
-            synchronized (cache){
-                value = cache.get(id);
-                if(value == null) {
+    private static final Map<String, YangInstanceIdentifier.PathArgument> CACHE = new HashMap<>();
+
+    public static YangInstanceIdentifier.PathArgument getArgument(String id) {
+        YangInstanceIdentifier.PathArgument value = CACHE.get(id);
+        if (value == null) {
+            synchronized (CACHE) {
+                value = CACHE.get(id);
+                if (value == null) {
                     value = createPathArgument(id, null);
-                    cache.put(id, value);
+                    CACHE.put(id, value);
                 }
             }
         }
         return value;
     }
 
-    public static YangInstanceIdentifier.PathArgument createPathArgument(String id, DataSchemaNode schemaNode){
+    public static YangInstanceIdentifier.PathArgument createPathArgument(String id, DataSchemaNode schemaNode) {
         final NodeIdentifierWithPredicatesGenerator
             nodeIdentifierWithPredicatesGenerator = new NodeIdentifierWithPredicatesGenerator(id, schemaNode);
-        if(nodeIdentifierWithPredicatesGenerator.matches()){
+        if (nodeIdentifierWithPredicatesGenerator.matches()) {
             return nodeIdentifierWithPredicatesGenerator.getPathArgument();
         }
 
         final NodeIdentifierWithValueGenerator
             nodeWithValueGenerator = new NodeIdentifierWithValueGenerator(id, schemaNode);
-        if(nodeWithValueGenerator.matches()){
+        if (nodeWithValueGenerator.matches()) {
             return nodeWithValueGenerator.getPathArgument();
         }
 
         final AugmentationIdentifierGenerator augmentationIdentifierGenerator = new AugmentationIdentifierGenerator(id);
-        if(augmentationIdentifierGenerator.matches()){
+        if (augmentationIdentifierGenerator.matches()) {
             return augmentationIdentifierGenerator.getPathArgument();
         }
 
index c8afd1df38277c40d2be20c6cebd23cf4bac3964..b10d834dd5cbf0fe3ec111fd06a0df865e2906b1 100644 (file)
@@ -12,15 +12,13 @@ import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 
 public class NodeIdentifierGenerator {
-    private final String id;
-    private final QName qName;
+    private final QName qname;
 
-    public NodeIdentifierGenerator(String id){
-        this.id = id;
-        this.qName = QNameFactory.create(id);
+    public NodeIdentifierGenerator(String id) {
+        this.qname = QNameFactory.create(id);
     }
 
-    public YangInstanceIdentifier.PathArgument getArgument(){
-        return new YangInstanceIdentifier.NodeIdentifier(qName);
+    public YangInstanceIdentifier.PathArgument getArgument() {
+        return new YangInstanceIdentifier.NodeIdentifier(qname);
     }
 }
index 11386e75a4b82cbb3b3a31ef1049f2db07bed16a..fa9783be0469895339fbb1541e4512a0101ba976 100644 (file)
@@ -8,31 +8,34 @@
 
 package org.opendaylight.controller.cluster.datastore.node.utils;
 
+import java.util.HashMap;
+import java.util.Map;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.opendaylight.yangtools.yang.data.impl.codec.TypeDefinitionAwareCodec;
 import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.ListSchemaNode;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
-import java.util.HashMap;
-import java.util.Map;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
+public class NodeIdentifierWithPredicatesGenerator {
+    private static final Logger LOG = LoggerFactory.getLogger(NodeIdentifierWithPredicatesGenerator.class);
+    private static final Pattern PATTERN = Pattern.compile("(.*)\\Q[{\\E(.*)\\Q}]\\E");
 
-public class NodeIdentifierWithPredicatesGenerator{
     private final String id;
-    private static final Pattern pattern = Pattern.compile("(.*)\\Q[{\\E(.*)\\Q}]\\E");
     private final Matcher matcher;
     private final boolean doesMatch;
     private final ListSchemaNode listSchemaNode;
 
-    public NodeIdentifierWithPredicatesGenerator(String id, DataSchemaNode schemaNode){
+    public NodeIdentifierWithPredicatesGenerator(String id, DataSchemaNode schemaNode) {
         this.id = id;
-        matcher = pattern.matcher(this.id);
+        matcher = PATTERN.matcher(this.id);
         doesMatch = matcher.matches();
 
-        if(schemaNode instanceof  ListSchemaNode){
+        if (schemaNode instanceof  ListSchemaNode) {
             this.listSchemaNode = (ListSchemaNode) schemaNode;
         } else {
             this.listSchemaNode = null;
@@ -40,35 +43,36 @@ public class NodeIdentifierWithPredicatesGenerator{
     }
 
 
-    public boolean matches(){
+    public boolean matches() {
         return doesMatch;
     }
 
-    public YangInstanceIdentifier.NodeIdentifierWithPredicates getPathArgument(){
+    public YangInstanceIdentifier.NodeIdentifierWithPredicates getPathArgument() {
         final String group = matcher.group(2);
         final String[] keyValues = group.split(",");
         Map<QName, Object> nameValues = new HashMap<>();
 
-        for(String keyValue : keyValues){
+        for (String keyValue : keyValues) {
             int eqIndex = keyValue.lastIndexOf('=');
             try {
                 final QName key = QNameFactory
                     .create(keyValue.substring(0, eqIndex));
                 nameValues.put(key, getValue(key, keyValue.substring(eqIndex + 1)));
-            } catch(IllegalArgumentException e){
-                System.out.println("Error processing identifier : " + id);
+            } catch (IllegalArgumentException e) {
+                LOG.error("Error processing identifier {}", id, e);
                 throw e;
             }
         }
 
-        return new YangInstanceIdentifier.NodeIdentifierWithPredicates(QNameFactory.create(matcher.group(1)), nameValues);
+        return new YangInstanceIdentifier.NodeIdentifierWithPredicates(
+                QNameFactory.create(matcher.group(1)), nameValues);
     }
 
 
-    private Object getValue(QName key, String value){
-        if(listSchemaNode != null){
-            for(DataSchemaNode node : listSchemaNode.getChildNodes()){
-                if(node instanceof LeafSchemaNode && node.getQName().equals(key)){
+    private Object getValue(QName key, String value) {
+        if (listSchemaNode != null) {
+            for (DataSchemaNode node : listSchemaNode.getChildNodes()) {
+                if (node instanceof LeafSchemaNode && node.getQName().equals(key)) {
                     return TypeDefinitionAwareCodec.from(LeafSchemaNode.class.cast(node).getType()).deserialize(value);
                 }
             }
index 9dce97f9aae4341933b16b5fc4c5959987e09d49..6ecf9050c365ee54698cf7813aef8e09114467ce 100644 (file)
@@ -8,49 +8,48 @@
 
 package org.opendaylight.controller.cluster.datastore.node.utils;
 
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.opendaylight.yangtools.yang.data.impl.codec.TypeDefinitionAwareCodec;
 import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode;
 
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
+public class NodeIdentifierWithValueGenerator {
+    private static final Pattern PATTERN = Pattern.compile("(.*)\\Q[\\E(.*)\\Q]\\E");
 
-public class NodeIdentifierWithValueGenerator{
-        private final String id;
+    private final String id;
     private final DataSchemaNode schemaNode;
-    private static final Pattern pattern = Pattern.compile("(.*)\\Q[\\E(.*)\\Q]\\E");
-        private final Matcher matcher;
-        private final boolean doesMatch;
-
-        public NodeIdentifierWithValueGenerator(String id, DataSchemaNode schemaNode){
-            this.id = id;
-            this.schemaNode = schemaNode;
-            matcher = pattern.matcher(this.id);
-            doesMatch = matcher.matches();
-        }
+    private final Matcher matcher;
+    private final boolean doesMatch;
+
+    public NodeIdentifierWithValueGenerator(String id, DataSchemaNode schemaNode) {
+        this.id = id;
+        this.schemaNode = schemaNode;
+        matcher = PATTERN.matcher(this.id);
+        doesMatch = matcher.matches();
+    }
 
-        public boolean matches(){
-            return doesMatch;
-        }
+    public boolean matches() {
+        return doesMatch;
+    }
 
-        public YangInstanceIdentifier.PathArgument getPathArgument(){
-            final String name = matcher.group(1);
-            final String value = matcher.group(2);
+    public YangInstanceIdentifier.PathArgument getPathArgument() {
+        final String name = matcher.group(1);
+        final String value = matcher.group(2);
 
-            return new YangInstanceIdentifier.NodeWithValue<>(
-                QNameFactory.create(name), getValue(value));
-        }
+        return new YangInstanceIdentifier.NodeWithValue<>(QNameFactory.create(name), getValue(value));
+    }
 
-        private Object getValue(String value){
-            if(schemaNode != null){
-                if(schemaNode instanceof LeafListSchemaNode){
-                    return TypeDefinitionAwareCodec
-                        .from(LeafListSchemaNode.class.cast(schemaNode).getType()).deserialize(value);
+    private Object getValue(String value) {
+        if (schemaNode != null) {
+            if (schemaNode instanceof LeafListSchemaNode) {
+                return TypeDefinitionAwareCodec.from(LeafListSchemaNode.class.cast(schemaNode).getType())
+                        .deserialize(value);
 
-                }
             }
-        return value;
         }
-
+        return value;
     }
+
+}
index 20529996f89f8aa269bcb1d32036096921b3ee18..e1e7b9f684b625e859e3b8651104d2d0cccd62fa 100644 (file)
@@ -16,21 +16,21 @@ public class NormalizedNodeGetter implements
     private final String path;
     NormalizedNode<?, ?> output;
 
-    public NormalizedNodeGetter(String path){
+    public NormalizedNodeGetter(String path) {
         Preconditions.checkNotNull(path);
         this.path = path;
     }
 
     @Override
     public void visitNode(int level, String parentPath, NormalizedNode<?, ?> normalizedNode) {
-        String nodePath = parentPath + "/"+ PathUtils.toString(normalizedNode.getIdentifier());
+        String nodePath = parentPath + "/" + PathUtils.toString(normalizedNode.getIdentifier());
 
-        if(nodePath.toString().equals(path)){
+        if (nodePath.toString().equals(path)) {
             output = normalizedNode;
         }
     }
 
-    public NormalizedNode<?, ?> getOutput(){
+    public NormalizedNode<?, ?> getOutput() {
         return output;
     }
 }
index 0b7cb373d4d671d70bfd5ed9d2bf4c3e220e0b94..a4e0b70a0216abb66af500c45bcfaff90d5bd869 100644 (file)
@@ -17,73 +17,69 @@ import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNodeContainer;
 
 /**
- * NormalizedNodeNavigator walks a {@link NormalizedNodeVisitor} through the NormalizedNode
- *
- * {@link NormalizedNode } is a tree like structure that provides a generic structure for a yang data model
- *
- * For examples of visitors
- * @see NormalizedNodePrinter
- *
- *
+ * NormalizedNodeNavigator walks a {@link NormalizedNodeVisitor} through the NormalizedNode.
  */
 public class NormalizedNodeNavigator {
 
-  private final org.opendaylight.controller.cluster.datastore.node.utils.NormalizedNodeVisitor
-      visitor;
-
-  public NormalizedNodeNavigator(
-      org.opendaylight.controller.cluster.datastore.node.utils.NormalizedNodeVisitor visitor){
-    Preconditions.checkNotNull(visitor, "visitor should not be null");
-    this.visitor = visitor;
-  }
-  public void navigate(String parentPath, NormalizedNode<?,?> normalizedNode){
-    if(parentPath == null){
-      parentPath = "";
-    }
-    navigateNormalizedNode(0, parentPath, normalizedNode);
-  }
-
-  private void navigateDataContainerNode(int level, final String parentPath, final DataContainerNode<?> dataContainerNode){
-    visitor.visitNode(level, parentPath ,dataContainerNode);
+    private final org.opendaylight.controller.cluster.datastore.node.utils.NormalizedNodeVisitor visitor;
 
-    String newParentPath = parentPath + "/" + dataContainerNode.getIdentifier().toString();
+    public NormalizedNodeNavigator(
+            org.opendaylight.controller.cluster.datastore.node.utils.NormalizedNodeVisitor visitor) {
+        Preconditions.checkNotNull(visitor, "visitor should not be null");
+        this.visitor = visitor;
+    }
 
-    final Iterable<DataContainerChild<? extends YangInstanceIdentifier.PathArgument,?>> value = dataContainerNode.getValue();
-    for(NormalizedNode<?,?> node : value){
-      if(node instanceof MixinNode && node instanceof NormalizedNodeContainer){
-        navigateNormalizedNodeContainerMixin(level, newParentPath, (NormalizedNodeContainer<?, ?, ?>) node);
-      } else {
-        navigateNormalizedNode(level, newParentPath, node);
-      }
+    public void navigate(String parentPath, NormalizedNode<?, ?> normalizedNode) {
+        if (parentPath == null) {
+            parentPath = "";
+        }
+        navigateNormalizedNode(0, parentPath, normalizedNode);
     }
 
-  }
+    private void navigateDataContainerNode(int level, final String parentPath,
+            final DataContainerNode<?> dataContainerNode) {
+        visitor.visitNode(level, parentPath, dataContainerNode);
 
-  private void navigateNormalizedNodeContainerMixin(int level, final String parentPath, NormalizedNodeContainer<?, ?, ?> node) {
-    visitor.visitNode(level, parentPath, node);
+        String newParentPath = parentPath + "/" + dataContainerNode.getIdentifier().toString();
 
-    String newParentPath = parentPath + "/" + node.getIdentifier().toString();
+        final Iterable<DataContainerChild<? extends YangInstanceIdentifier.PathArgument, ?>> value = dataContainerNode
+                .getValue();
+        for (NormalizedNode<?, ?> node : value) {
+            if (node instanceof MixinNode && node instanceof NormalizedNodeContainer) {
+                navigateNormalizedNodeContainerMixin(level, newParentPath, (NormalizedNodeContainer<?, ?, ?>) node);
+            } else {
+                navigateNormalizedNode(level, newParentPath, node);
+            }
+        }
 
-    final Iterable<? extends NormalizedNode<?, ?>> value = node.getValue();
-    for(NormalizedNode<?, ?> normalizedNode : value){
-      if(normalizedNode instanceof MixinNode && normalizedNode instanceof NormalizedNodeContainer){
-        navigateNormalizedNodeContainerMixin(level + 1, newParentPath, (NormalizedNodeContainer) normalizedNode);
-      } else {
-        navigateNormalizedNode(level, newParentPath, normalizedNode);
-      }
     }
 
-  }
+    private void navigateNormalizedNodeContainerMixin(int level, final String parentPath,
+            NormalizedNodeContainer<?, ?, ?> node) {
+        visitor.visitNode(level, parentPath, node);
+
+        String newParentPath = parentPath + "/" + node.getIdentifier().toString();
 
+        final Iterable<? extends NormalizedNode<?, ?>> value = node.getValue();
+        for (NormalizedNode<?, ?> normalizedNode : value) {
+            if (normalizedNode instanceof MixinNode && normalizedNode instanceof NormalizedNodeContainer) {
+                navigateNormalizedNodeContainerMixin(level + 1, newParentPath,
+                        (NormalizedNodeContainer<?, ?, ?>) normalizedNode);
+            } else {
+                navigateNormalizedNode(level, newParentPath, normalizedNode);
+            }
+        }
+
+    }
 
-  private void navigateNormalizedNode(int level, String parentPath, NormalizedNode<?,?> normalizedNode){
-    if(normalizedNode instanceof DataContainerNode){
+    private void navigateNormalizedNode(int level, String parentPath, NormalizedNode<?, ?> normalizedNode) {
+        if (normalizedNode instanceof DataContainerNode) {
 
-      final DataContainerNode<?> dataContainerNode = (DataContainerNode<?>) normalizedNode;
+            final DataContainerNode<?> dataContainerNode = (DataContainerNode<?>) normalizedNode;
 
-      navigateDataContainerNode(level + 1, parentPath, dataContainerNode);
-    } else {
-      visitor.visitNode(level+1, parentPath, normalizedNode);
+            navigateDataContainerNode(level + 1, parentPath, dataContainerNode);
+        } else {
+            visitor.visitNode(level + 1, parentPath, normalizedNode);
+        }
     }
-  }
 }
diff --git a/java/org/opendaylight/controller/cluster/datastore/node/utils/NormalizedNodePrinter.java b/java/org/opendaylight/controller/cluster/datastore/node/utils/NormalizedNodePrinter.java
deleted file mode 100644 (file)
index 23f314e..0000000
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- * Copyright (c) 2014, 2015 Cisco Systems, Inc. and others.  All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * 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.controller.cluster.datastore.node.utils;
-
-import org.opendaylight.yangtools.yang.data.api.schema.LeafNode;
-import org.opendaylight.yangtools.yang.data.api.schema.LeafSetEntryNode;
-import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
-
-public class NormalizedNodePrinter implements NormalizedNodeVisitor {
-
-    private static String spaces(int n){
-        StringBuilder builder = new StringBuilder();
-        for(int i=0;i<n;i++){
-            builder.append(' ');
-        }
-        return builder.toString();
-    }
-
-    @Override
-    public void visitNode(int level, String parentPath, NormalizedNode<?, ?> normalizedNode) {
-        System.out.println(spaces((level) * 4) + normalizedNode.getClass().toString() + ":" + normalizedNode.getIdentifier());
-        if(normalizedNode instanceof LeafNode || normalizedNode instanceof LeafSetEntryNode){
-            System.out.println(spaces((level) * 4) + " parentPath = " + parentPath);
-            System.out.println(spaces((level) * 4) + " key = " + normalizedNode.getClass().toString() + ":" + normalizedNode.getIdentifier());
-            System.out.println(spaces((level) * 4) + " value = " + normalizedNode.getValue());
-        }
-    }
-}
index 8324b64aaac7821683c04589016072831975903c..588fc648fd79f511cf617d3ddd504cf78f168906 100644 (file)
@@ -24,12 +24,27 @@ import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgum
 public class PathUtils {
     private static final Splitter SLASH_SPLITTER = Splitter.on('/').omitEmptyStrings();
 
+    /**
+     * Given a serialized string version of a YangInstanceIdentifier convert
+     * to a YangInstanceIdentifier.
+     *
+     * @param path the path
+     * @return a YangInstanceIdentifier
+     */
+    public static YangInstanceIdentifier toYangInstanceIdentifier(String path) {
+        List<PathArgument> pathArguments = new ArrayList<>();
+        for (String segment : SLASH_SPLITTER.split(path)) {
+            pathArguments.add(NodeIdentifierFactory.getArgument(segment));
+        }
+        return YangInstanceIdentifier.create(pathArguments);
+    }
+
     /**
      * Given a YangInstanceIdentifier return a serialized version of the same
-     * as a String
+     * as a String.
      *
-     * @param path
-     * @return
+     * @param path the path
+     * @return the path as a String
      */
     public static String toString(YangInstanceIdentifier path) {
         final Iterator<PathArgument> it = path.getPathArguments().iterator();
@@ -51,45 +66,30 @@ public class PathUtils {
 
     /**
      * Given a YangInstanceIdentifier.PathArgument return a serialized version
-     * of the same as a String
+     * of the same as a String.
      *
-     * @param pathArgument
-     * @return
+     * @param pathArgument the path argument
+     * @return the path argument as a String
      */
-    public static String toString(PathArgument pathArgument){
-        if(pathArgument instanceof NodeIdentifier){
+    public static String toString(PathArgument pathArgument) {
+        if (pathArgument instanceof NodeIdentifier) {
             return toString((NodeIdentifier) pathArgument);
-        } else if(pathArgument instanceof AugmentationIdentifier){
+        } else if (pathArgument instanceof AugmentationIdentifier) {
             return toString((AugmentationIdentifier) pathArgument);
-        } else if(pathArgument instanceof NodeWithValue){
+        } else if (pathArgument instanceof NodeWithValue) {
             return toString((NodeWithValue<?>) pathArgument);
-        } else if(pathArgument instanceof NodeIdentifierWithPredicates){
+        } else if (pathArgument instanceof NodeIdentifierWithPredicates) {
             return toString((NodeIdentifierWithPredicates) pathArgument);
         }
 
         return pathArgument.toString();
     }
 
-    /**
-     * Given a serialized string version of a YangInstanceIdentifier convert
-     * to a YangInstanceIdentifier
-     *
-     * @param path
-     * @return
-     */
-    public static YangInstanceIdentifier toYangInstanceIdentifier(String path){
-        List<PathArgument> pathArguments = new ArrayList<>();
-        for (String segment : SLASH_SPLITTER.split(path)) {
-            pathArguments.add(NodeIdentifierFactory.getArgument(segment));
-        }
-        return YangInstanceIdentifier.create(pathArguments);
-    }
-
-    private static String toString(NodeIdentifier pathArgument){
+    private static String toString(NodeIdentifier pathArgument) {
         return pathArgument.getNodeType().toString();
     }
 
-    private static String toString(AugmentationIdentifier pathArgument){
+    private static String toString(AugmentationIdentifier pathArgument) {
         Set<QName> childNames = pathArgument.getPossibleChildNames();
         final StringBuilder sb = new StringBuilder("AugmentationIdentifier{");
         sb.append("childNames=").append(childNames).append('}');
@@ -101,8 +101,7 @@ public class PathUtils {
         return pathArgument.getNodeType().toString() + "[" + pathArgument.getValue() + "]";
     }
 
-    private static String toString(NodeIdentifierWithPredicates pathArgument){
+    private static String toString(NodeIdentifierWithPredicates pathArgument) {
         return pathArgument.getNodeType().toString() + '[' + pathArgument.getKeyValues() + ']';
     }
-
 }
index 4d26f741065a10e429c295cf73bf3f37a7d9c17b..7d5379dfe0ce87d2fbd70e6b38a3fd7d432bdba6 100644 (file)
@@ -30,7 +30,7 @@ public class QNameFactory {
         );
 
 
-    public static QName create(String name){
+    public static QName create(String name) {
         return CACHE.getUnchecked(name);
     }
 }
index 0ed1317997e71df5de9a58cb968d915b09cffebe..f072a61406d57a2204356b9a8ee7fb46edd83fac 100644 (file)
@@ -10,11 +10,13 @@ package org.opendaylight.controller.cluster.datastore.node.utils.serialization;
 
 /**
  * NormalizedNodeDeSerializationContext provides methods which help in decoding
- * certain components of a NormalizedNode properly
+ * certain components of a NormalizedNode properly.
  */
 
 public interface NormalizedNodeDeSerializationContext {
     String getNamespace(int namespace);
+
     String getRevision(int revision);
+
     String getLocalName(int localName);
 }
index 192070252779d5c49df5c944721d9dfb5783d1a7..d62cc8dc897e102e046cbb1c35052eceb103b5d4 100644 (file)
@@ -10,7 +10,7 @@ package org.opendaylight.controller.cluster.datastore.node.utils.serialization;
 
 /**
  * NormalizedNodeSerializationContext provides methods which help in encoding
- * certain components of a NormalizedNode properly
+ * certain components of a NormalizedNode properly.
  */
 public interface NormalizedNodeSerializationContext {
 }
index e4ba73c3b1c49e4d8a88c9fed18067ba342f5dc3..84c2ae515a7aa5376e86fac47ddbc8b244a10b4e 100644 (file)
@@ -22,6 +22,7 @@ import static org.opendaylight.controller.cluster.datastore.node.utils.serializa
 import static org.opendaylight.controller.cluster.datastore.node.utils.serialization.NormalizedNodeType.UNKEYED_LIST_ENTRY_NODE_TYPE;
 import static org.opendaylight.controller.cluster.datastore.node.utils.serialization.NormalizedNodeType.UNKEYED_LIST_NODE_TYPE;
 import static org.opendaylight.controller.cluster.datastore.node.utils.serialization.NormalizedNodeType.getSerializableNodeType;
+
 import com.google.common.base.Preconditions;
 import com.google.common.collect.Maps;
 import java.util.EnumMap;
@@ -62,7 +63,7 @@ public class NormalizedNodeSerializer {
 
     /**
      * Serialize a NormalizedNode into a protocol buffer message
-     * <p>
+     * <p/>
      * The significant things to be aware of the Serialization process are
      * <ul>
      *     <li>Repeated strings like namespaces, revisions and localNames are
@@ -74,16 +75,15 @@ public class NormalizedNodeSerializer {
      *     figure out how to decode values
      *     </li>
      * </ul>
-     *
      * One question which may arise is why not use something like gzip to
      * compress the protocol buffer message instead of rolling our own
      * encoding scheme. This has to be explored further as it is a more
      * general solution.
      *
-     * @param node
-     * @return
+     * @param node the node
+     * @return a NormalizedNodeMessages.Node
      */
-    public static NormalizedNodeMessages.Node serialize(final NormalizedNode<?, ?> node){
+    public static NormalizedNodeMessages.Node serialize(final NormalizedNode<?, ?> node) {
         Preconditions.checkNotNull(node, "node should not be null");
         return new Serializer(node).serialize();
     }
@@ -94,22 +94,16 @@ public class NormalizedNodeSerializer {
     }
 
     /**
-     * DeSerialize a protocol buffer message back into a NormalizedNode
+     * DeSerialize a protocol buffer message back into a NormalizedNode.
      *
-     * @param node
-     * @return
+     * @param node the node
+     * @return a NormalizedNode
      */
     public static NormalizedNode<?, ?> deSerialize(final NormalizedNodeMessages.Node node) {
         Preconditions.checkNotNull(node, "node should not be null");
         return new DeSerializer(null, node).deSerialize();
     }
 
-    public static DeSerializer newDeSerializer(final NormalizedNodeMessages.InstanceIdentifier path,
-            final NormalizedNodeMessages.Node node) {
-        Preconditions.checkNotNull(node, "node should not be null");
-        return new DeSerializer(path, node);
-    }
-
     /**
      * DeSerialize a PathArgument which is in the protocol buffer format into
      * a yang PathArgument. The protocol buffer path argument is specially
@@ -118,18 +112,20 @@ public class NormalizedNodeSerializer {
      * is that during the NormalizedNode serialization process certain repeated
      * strings are encoded into a "codes" list and the actual strings are
      * replaced by an integer which is an index into that list.
-     *
-     * @param node
-     * @param pathArgument
-     * @return
      */
     public static YangInstanceIdentifier.PathArgument deSerialize(final NormalizedNodeMessages.Node node,
-            final NormalizedNodeMessages.PathArgument pathArgument){
+            final NormalizedNodeMessages.PathArgument pathArgument) {
         Preconditions.checkNotNull(node, "node should not be null");
         Preconditions.checkNotNull(pathArgument, "pathArgument should not be null");
         return new DeSerializer(null, node).deSerialize(pathArgument);
     }
 
+    public static DeSerializer newDeSerializer(final NormalizedNodeMessages.InstanceIdentifier path,
+            final NormalizedNodeMessages.Node node) {
+        Preconditions.checkNotNull(node, "node should not be null");
+        return new DeSerializer(path, node);
+    }
+
     public static class Serializer extends QNameSerializationContextImpl
                                    implements NormalizedNodeSerializationContext {
 
@@ -155,15 +151,14 @@ public class NormalizedNodeSerializer {
             return builder.addAllCode(getCodes()).build();
         }
 
-        private NormalizedNodeMessages.Node.Builder serialize(
-            final NormalizedNode<?, ?> node) {
+        private NormalizedNodeMessages.Node.Builder serialize(final NormalizedNode<?, ?> fromNode) {
             NormalizedNodeMessages.Node.Builder builder =
                 NormalizedNodeMessages.Node.newBuilder();
 
-            builder.setPathArgument(PathArgumentSerializer.serialize(this, node.getIdentifier()));
-            Integer nodeType = getSerializableNodeType(node).ordinal();
+            builder.setPathArgument(PathArgumentSerializer.serialize(this, fromNode.getIdentifier()));
+            Integer nodeType = getSerializableNodeType(fromNode).ordinal();
             builder.setIntType(nodeType);
-            Object value = node.getValue();
+            Object value = fromNode.getValue();
 
             // We need to do a specific check of the type of the node here
             // because if we looked at the value type alone we will not be
@@ -175,8 +170,8 @@ public class NormalizedNodeSerializer {
             // which is also a Collection. Without the following check being
             // done first the code would flow into the Collection if condition
             // and the Set would be added as child nodes
-            if(nodeType == NormalizedNodeType.LEAF_NODE_TYPE.ordinal() ||
-               nodeType == NormalizedNodeType.LEAF_SET_ENTRY_NODE_TYPE.ordinal()){
+            if (nodeType == NormalizedNodeType.LEAF_NODE_TYPE.ordinal()
+                    || nodeType == NormalizedNodeType.LEAF_SET_ENTRY_NODE_TYPE.ordinal()) {
 
                 ValueSerializer.serialize(builder, this, value);
 
@@ -202,117 +197,74 @@ public class NormalizedNodeSerializer {
         }
     }
 
+    @SuppressWarnings("rawtypes")
     public static class DeSerializer extends QNameDeSerializationContextImpl
                                      implements NormalizedNodeDeSerializationContext {
         private static final Map<NormalizedNodeType, DeSerializationFunction> DESERIALIZATION_FUNCTIONS;
+
         static {
             final EnumMap<NormalizedNodeType, DeSerializationFunction> m = new EnumMap<>(NormalizedNodeType.class);
 
-            m.put(CONTAINER_NODE_TYPE, new DeSerializationFunction() {
-                @Override
-                public NormalizedNode<?, ?> apply(final DeSerializer deSerializer, final NormalizedNodeMessages.Node node) {
-                    DataContainerNodeAttrBuilder<NodeIdentifier, ContainerNode> builder = Builders.containerBuilder()
-                            .withNodeIdentifier(deSerializer.toNodeIdentifier(node.getPathArgument()));
+            m.put(CONTAINER_NODE_TYPE, (deSerializer, node) -> {
+                DataContainerNodeAttrBuilder<NodeIdentifier, ContainerNode> builder = Builders.containerBuilder()
+                        .withNodeIdentifier(deSerializer.toNodeIdentifier(node.getPathArgument()));
 
-                    return deSerializer.buildDataContainer(builder, node);
-                }
+                return deSerializer.buildDataContainer(builder, node);
             });
-            m.put(LEAF_NODE_TYPE, new DeSerializationFunction() {
-                @Override
-                public NormalizedNode<?, ?> apply(final DeSerializer deSerializer, final NormalizedNodeMessages.Node node) {
-                    NormalizedNodeAttrBuilder<NodeIdentifier, Object, LeafNode<Object>> builder = Builders.leafBuilder()
-                            .withNodeIdentifier(deSerializer.toNodeIdentifier(node.getPathArgument()));
+            m.put(LEAF_NODE_TYPE, (deSerializer, node) -> {
+                NormalizedNodeAttrBuilder<NodeIdentifier, Object, LeafNode<Object>> builder = Builders.leafBuilder()
+                        .withNodeIdentifier(deSerializer.toNodeIdentifier(node.getPathArgument()));
 
-                    return deSerializer.buildNormalizedNode(builder, node);
-                }
-            });
-            m.put(MAP_NODE_TYPE, new DeSerializationFunction() {
-                @Override
-                public NormalizedNode<?, ?> apply(final DeSerializer deSerializer, final NormalizedNodeMessages.Node node) {
-                    return deSerializer.buildCollectionNode(Builders.mapBuilder(), node);
-                }
-            });
-            m.put(MAP_ENTRY_NODE_TYPE, new DeSerializationFunction() {
-                @Override
-                public NormalizedNode<?, ?> apply(final DeSerializer deSerializer, final NormalizedNodeMessages.Node node) {
-                    DataContainerNodeAttrBuilder<NodeIdentifierWithPredicates, MapEntryNode> builder =
-                            Builders.mapEntryBuilder().withNodeIdentifier(deSerializer.toNodeIdentifierWithPredicates(
-                                node.getPathArgument()));
-
-                    return deSerializer.buildDataContainer(builder, node);
-                }
-            });
-            m.put(AUGMENTATION_NODE_TYPE, new DeSerializationFunction() {
-                @Override
-                public NormalizedNode<?, ?> apply(final DeSerializer deSerializer, final NormalizedNodeMessages.Node node) {
-                    DataContainerNodeBuilder<AugmentationIdentifier, AugmentationNode> builder =
-                            Builders.augmentationBuilder().withNodeIdentifier(
-                                deSerializer.toAugmentationIdentifier(node.getPathArgument()));
-
-                    return deSerializer.buildDataContainer(builder, node);
-                }
+                return deSerializer.buildNormalizedNode(builder, node);
             });
-            m.put(LEAF_SET_NODE_TYPE, new DeSerializationFunction() {
-                @Override
-                public NormalizedNode<?, ?> apply(final DeSerializer deSerializer, final NormalizedNodeMessages.Node node) {
-                    return deSerializer.buildListNode(Builders.leafSetBuilder(), node);
-                }
-            });
-            m.put(LEAF_SET_ENTRY_NODE_TYPE, new DeSerializationFunction() {
-                @Override
-                public NormalizedNode<?, ?> apply(final DeSerializer deSerializer, final NormalizedNodeMessages.Node node) {
-                    NormalizedNodeAttrBuilder<NodeWithValue, Object, LeafSetEntryNode<Object>> builder =
-                            Builders.leafSetEntryBuilder().withNodeIdentifier(deSerializer.toNodeWithValue(
-                                node.getPathArgument()));
-
-                    return deSerializer.buildNormalizedNode(builder, node);
-                }
-            });
-            m.put(CHOICE_NODE_TYPE, new DeSerializationFunction() {
-                @Override
-                public NormalizedNode<?, ?> apply(final DeSerializer deSerializer, final NormalizedNodeMessages.Node node) {
-                    DataContainerNodeBuilder<NodeIdentifier, ChoiceNode> builder = Builders.choiceBuilder()
-                            .withNodeIdentifier(deSerializer.toNodeIdentifier(node.getPathArgument()));
+            m.put(MAP_NODE_TYPE, (deSerializer, node) -> deSerializer.buildCollectionNode(Builders.mapBuilder(), node));
+            m.put(MAP_ENTRY_NODE_TYPE, (deSerializer, node) -> {
+                DataContainerNodeAttrBuilder<NodeIdentifierWithPredicates, MapEntryNode> builder =
+                        Builders.mapEntryBuilder().withNodeIdentifier(deSerializer.toNodeIdentifierWithPredicates(
+                            node.getPathArgument()));
 
-                    return deSerializer.buildDataContainer(builder, node);
-                }
+                return deSerializer.buildDataContainer(builder, node);
             });
-            m.put(ORDERED_LEAF_SET_NODE_TYPE, new DeSerializationFunction() {
-                @Override
-                public NormalizedNode<?, ?> apply(final DeSerializer deSerializer, final NormalizedNodeMessages.Node node) {
-                    return deSerializer.buildListNode(Builders.orderedLeafSetBuilder(), node);
-                }
+            m.put(AUGMENTATION_NODE_TYPE, (deSerializer, node) -> {
+                DataContainerNodeBuilder<AugmentationIdentifier, AugmentationNode> builder =
+                        Builders.augmentationBuilder().withNodeIdentifier(
+                            deSerializer.toAugmentationIdentifier(node.getPathArgument()));
+
+                return deSerializer.buildDataContainer(builder, node);
             });
-            m.put(ORDERED_MAP_NODE_TYPE, new DeSerializationFunction() {
-                @Override
-                public NormalizedNode<?, ?> apply(final DeSerializer deSerializer, final NormalizedNodeMessages.Node node) {
-                    return deSerializer.buildCollectionNode(Builders.orderedMapBuilder(), node);
-                }
+            m.put(LEAF_SET_NODE_TYPE, (deSerializer, node)
+                -> deSerializer.buildListNode(Builders.leafSetBuilder(), node));
+            m.put(LEAF_SET_ENTRY_NODE_TYPE, (deSerializer, node) -> {
+                NormalizedNodeAttrBuilder<NodeWithValue, Object, LeafSetEntryNode<Object>> builder =
+                        Builders.leafSetEntryBuilder().withNodeIdentifier(deSerializer.toNodeWithValue(
+                            node.getPathArgument()));
+
+                return deSerializer.buildNormalizedNode(builder, node);
             });
-            m.put(UNKEYED_LIST_NODE_TYPE, new DeSerializationFunction() {
-                @Override
-                public NormalizedNode<?, ?> apply(final DeSerializer deSerializer, final NormalizedNodeMessages.Node node) {
-                    return deSerializer.buildCollectionNode(Builders.unkeyedListBuilder(), node);
-                }
+            m.put(CHOICE_NODE_TYPE, (deSerializer, node) -> {
+                DataContainerNodeBuilder<NodeIdentifier, ChoiceNode> builder = Builders.choiceBuilder()
+                        .withNodeIdentifier(deSerializer.toNodeIdentifier(node.getPathArgument()));
+
+                return deSerializer.buildDataContainer(builder, node);
             });
-            m.put(UNKEYED_LIST_ENTRY_NODE_TYPE, new DeSerializationFunction() {
-                @Override
-                public NormalizedNode<?, ?> apply(final DeSerializer deSerializer, final NormalizedNodeMessages.Node node) {
-                    DataContainerNodeAttrBuilder<NodeIdentifier, UnkeyedListEntryNode> builder =
-                            Builders.unkeyedListEntryBuilder().withNodeIdentifier(deSerializer.toNodeIdentifier(
-                                node.getPathArgument()));
-
-                    return deSerializer.buildDataContainer(builder, node);
-                }
+            m.put(ORDERED_LEAF_SET_NODE_TYPE, (deSerializer, node)
+                -> deSerializer.buildListNode(Builders.orderedLeafSetBuilder(), node));
+            m.put(ORDERED_MAP_NODE_TYPE, (deSerializer, node)
+                -> deSerializer.buildCollectionNode(Builders.orderedMapBuilder(), node));
+            m.put(UNKEYED_LIST_NODE_TYPE, (deSerializer, node)
+                -> deSerializer.buildCollectionNode(Builders.unkeyedListBuilder(), node));
+            m.put(UNKEYED_LIST_ENTRY_NODE_TYPE, (deSerializer, node) -> {
+                DataContainerNodeAttrBuilder<NodeIdentifier, UnkeyedListEntryNode> builder =
+                        Builders.unkeyedListEntryBuilder().withNodeIdentifier(deSerializer.toNodeIdentifier(
+                            node.getPathArgument()));
+
+                return deSerializer.buildDataContainer(builder, node);
             });
-            m.put(ANY_XML_NODE_TYPE, new DeSerializationFunction() {
-                @Override
-                public NormalizedNode<?, ?> apply(final DeSerializer deSerializer, final NormalizedNodeMessages.Node node) {
-                    NormalizedNodeAttrBuilder<NodeIdentifier, DOMSource, AnyXmlNode> builder = Builders.anyXmlBuilder()
-                            .withNodeIdentifier(deSerializer.toNodeIdentifier(node.getPathArgument()));
+            m.put(ANY_XML_NODE_TYPE, (deSerializer, node) -> {
+                NormalizedNodeAttrBuilder<NodeIdentifier, DOMSource, AnyXmlNode> builder = Builders.anyXmlBuilder()
+                        .withNodeIdentifier(deSerializer.toNodeIdentifier(node.getPathArgument()));
 
-                    return deSerializer.buildNormalizedNode(builder, node);
-                }
+                return deSerializer.buildNormalizedNode(builder, node);
             });
 
             DESERIALIZATION_FUNCTIONS = Maps.immutableEnumMap(m);
@@ -335,30 +287,33 @@ public class NormalizedNodeSerializer {
 
         public NormalizedNode<?, ?> deSerialize() {
             NormalizedNode<?, ?> deserializedNode = deSerialize(node);
-            if(path != null) {
+            if (path != null) {
                 deserializedPath = InstanceIdentifierUtils.fromSerializable(path, this);
             }
 
             return deserializedNode;
         }
 
-        private NormalizedNode<?, ?> deSerialize(final NormalizedNodeMessages.Node node){
-            Preconditions.checkNotNull(node, "node should not be null");
+        private NormalizedNode<?, ?> deSerialize(final NormalizedNodeMessages.Node fromNode) {
+            Preconditions.checkNotNull(fromNode, "node should not be null");
 
             DeSerializationFunction deSerializationFunction = DESERIALIZATION_FUNCTIONS.get(
-                    NormalizedNodeType.values()[node.getIntType()]);
+                    NormalizedNodeType.values()[fromNode.getIntType()]);
 
-            return deSerializationFunction.apply(this, node);
+            return deSerializationFunction.apply(this, fromNode);
         }
 
+        public YangInstanceIdentifier.PathArgument deSerialize(final NormalizedNodeMessages.PathArgument pathArgument) {
+            return PathArgumentSerializer.deSerialize(this, pathArgument);
+        }
 
-        private NormalizedNode<?, ?> buildCollectionNode(
-            final CollectionNodeBuilder builder,
-            final NormalizedNodeMessages.Node node) {
+        @SuppressWarnings("unchecked")
+        private NormalizedNode<?, ?> buildCollectionNode(final CollectionNodeBuilder builder,
+                final NormalizedNodeMessages.Node fromNode) {
 
-            builder.withNodeIdentifier(toNodeIdentifier(node.getPathArgument()));
+            builder.withNodeIdentifier(toNodeIdentifier(fromNode.getPathArgument()));
 
-            for(NormalizedNodeMessages.Node child : node.getChildList()){
+            for (NormalizedNodeMessages.Node child : fromNode.getChildList()) {
                 builder.withChild(deSerialize(child));
             }
 
@@ -366,21 +321,22 @@ public class NormalizedNodeSerializer {
         }
 
 
-        private NormalizedNode<?, ?> buildListNode(
-            final ListNodeBuilder<Object, LeafSetEntryNode<Object>> builder,
-            final NormalizedNodeMessages.Node node) {
-            builder.withNodeIdentifier(toNodeIdentifier(node.getPathArgument()));
+        @SuppressWarnings("unchecked")
+        private NormalizedNode<?, ?> buildListNode(final ListNodeBuilder<Object, LeafSetEntryNode<Object>> builder,
+                final NormalizedNodeMessages.Node fromNode) {
+            builder.withNodeIdentifier(toNodeIdentifier(fromNode.getPathArgument()));
 
-            for(NormalizedNodeMessages.Node child : node.getChildList()){
+            for (NormalizedNodeMessages.Node child : fromNode.getChildList()) {
                 builder.withChild((LeafSetEntryNode<Object>) deSerialize(child));
             }
 
             return builder.build();
         }
 
-        private NormalizedNode<?, ?> buildDataContainer(final DataContainerNodeBuilder<?, ?> builder, final NormalizedNodeMessages.Node node){
+        private NormalizedNode<?, ?> buildDataContainer(final DataContainerNodeBuilder<?, ?> builder,
+                final NormalizedNodeMessages.Node fromNode) {
 
-            for(NormalizedNodeMessages.Node child : node.getChildList()){
+            for (NormalizedNodeMessages.Node child : fromNode.getChildList()) {
                 builder.withChild((DataContainerChild<?, ?>) deSerialize(child));
             }
 
@@ -389,9 +345,11 @@ public class NormalizedNodeSerializer {
             return builder.build();
         }
 
-        private NormalizedNode<?, ?> buildNormalizedNode(final NormalizedNodeAttrBuilder builder, final NormalizedNodeMessages.Node node){
+        @SuppressWarnings("unchecked")
+        private NormalizedNode<?, ?> buildNormalizedNode(final NormalizedNodeAttrBuilder builder,
+                final NormalizedNodeMessages.Node fromNode) {
 
-            builder.withValue(ValueSerializer.deSerialize(this, node));
+            builder.withValue(ValueSerializer.deSerialize(this, fromNode));
 
             //TODO : Also handle attributes
 
@@ -400,25 +358,21 @@ public class NormalizedNodeSerializer {
         }
 
         private NodeIdentifierWithPredicates toNodeIdentifierWithPredicates(
-            final NormalizedNodeMessages.PathArgument path) {
-            return (NodeIdentifierWithPredicates) PathArgumentSerializer.deSerialize(this, path);
+                final NormalizedNodeMessages.PathArgument fromPath) {
+            return (NodeIdentifierWithPredicates) PathArgumentSerializer.deSerialize(this, fromPath);
         }
 
-        private AugmentationIdentifier toAugmentationIdentifier(final NormalizedNodeMessages.PathArgument path) {
-            return (AugmentationIdentifier) PathArgumentSerializer.deSerialize(this, path);
+        private AugmentationIdentifier toAugmentationIdentifier(final NormalizedNodeMessages.PathArgument fromPath) {
+            return (AugmentationIdentifier) PathArgumentSerializer.deSerialize(this, fromPath);
         }
 
         @SuppressWarnings("unchecked")
-        private <T> NodeWithValue<T> toNodeWithValue(final NormalizedNodeMessages.PathArgument path) {
-            return (NodeWithValue<T>) PathArgumentSerializer.deSerialize(this, path);
-        }
-
-        private NodeIdentifier toNodeIdentifier(final NormalizedNodeMessages.PathArgument path){
-            return (NodeIdentifier) PathArgumentSerializer.deSerialize(this, path);
+        private <T> NodeWithValue<T> toNodeWithValue(final NormalizedNodeMessages.PathArgument fromPath) {
+            return (NodeWithValue<T>) PathArgumentSerializer.deSerialize(this, fromPath);
         }
 
-        public YangInstanceIdentifier.PathArgument deSerialize(final NormalizedNodeMessages.PathArgument pathArgument) {
-            return PathArgumentSerializer.deSerialize(this, pathArgument);
+        private NodeIdentifier toNodeIdentifier(final NormalizedNodeMessages.PathArgument fromPath) {
+            return (NodeIdentifier) PathArgumentSerializer.deSerialize(this, fromPath);
         }
 
         private interface DeSerializationFunction {
index 01e56e89d4cbed4a4185b8155227516faae1bc82..ab6b1b4cdaeaa273011a66021fb24893364bb437 100644 (file)
@@ -39,34 +39,34 @@ public enum NormalizedNodeType {
     UNKEYED_LIST_ENTRY_NODE_TYPE,
     ANY_XML_NODE_TYPE;
 
-    public static NormalizedNodeType getSerializableNodeType(NormalizedNode<?, ?> node){
+    public static NormalizedNodeType getSerializableNodeType(NormalizedNode<?, ?> node) {
         Preconditions.checkNotNull(node, "node should not be null");
 
-        if(node instanceof LeafNode){
+        if (node instanceof LeafNode) {
             return LEAF_NODE_TYPE;
-        } else if(node instanceof LeafSetEntryNode){
+        } else if (node instanceof LeafSetEntryNode) {
             return LEAF_SET_ENTRY_NODE_TYPE;
-        } else if(node instanceof MapEntryNode){
+        } else if (node instanceof MapEntryNode) {
             return MAP_ENTRY_NODE_TYPE;
-        } else if(node instanceof ContainerNode){
+        } else if (node instanceof ContainerNode) {
             return CONTAINER_NODE_TYPE;
-        } else if(node instanceof AugmentationNode){
+        } else if (node instanceof AugmentationNode) {
             return AUGMENTATION_NODE_TYPE;
-        } else if(node instanceof ChoiceNode){
+        } else if (node instanceof ChoiceNode) {
             return CHOICE_NODE_TYPE;
-        } else if(node instanceof OrderedLeafSetNode){
+        } else if (node instanceof OrderedLeafSetNode) {
             return ORDERED_LEAF_SET_NODE_TYPE;
-        } else if(node instanceof OrderedMapNode){
+        } else if (node instanceof OrderedMapNode) {
             return ORDERED_MAP_NODE_TYPE;
-        } else if(node instanceof MapNode){
+        } else if (node instanceof MapNode) {
             return MAP_NODE_TYPE;
-        } else if(node instanceof LeafSetNode){
+        } else if (node instanceof LeafSetNode) {
             return LEAF_SET_NODE_TYPE;
-        } else if(node instanceof UnkeyedListNode){
+        } else if (node instanceof UnkeyedListNode) {
             return UNKEYED_LIST_NODE_TYPE;
-        } else if(node instanceof UnkeyedListEntryNode){
+        } else if (node instanceof UnkeyedListEntryNode) {
             return UNKEYED_LIST_ENTRY_NODE_TYPE;
-        } else if(node instanceof AnyXmlNode){
+        } else if (node instanceof AnyXmlNode) {
             return ANY_XML_NODE_TYPE;
         }
 
index 7bbb704c1c81d67d4e7c106bad02e2ba5d1d8307..ed9073b5582ad96c5cbc74f7894c24213574ac0d 100644 (file)
@@ -8,12 +8,9 @@
 
 package org.opendaylight.controller.cluster.datastore.node.utils.serialization;
 
+import static org.opendaylight.controller.cluster.datastore.node.utils.serialization.PathArgumentType.getSerializablePathArgumentType;
+
 import com.google.common.base.Preconditions;
-import org.opendaylight.controller.cluster.datastore.node.utils.NodeIdentifierFactory;
-import org.opendaylight.controller.cluster.datastore.node.utils.QNameFactory;
-import org.opendaylight.controller.protobuff.messages.common.NormalizedNodeMessages;
-import org.opendaylight.yangtools.yang.common.QName;
-import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collections;
@@ -23,14 +20,18 @@ import java.util.List;
 import java.util.Map;
 import java.util.Map.Entry;
 import java.util.Set;
-import static org.opendaylight.controller.cluster.datastore.node.utils.serialization.PathArgumentType.getSerializablePathArgumentType;
+import org.opendaylight.controller.cluster.datastore.node.utils.NodeIdentifierFactory;
+import org.opendaylight.controller.cluster.datastore.node.utils.QNameFactory;
+import org.opendaylight.controller.protobuff.messages.common.NormalizedNodeMessages;
+import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 
 public class PathArgumentSerializer {
     private static final String REVISION_ARG = "?revision=";
-    private static final Map<Class<?>, PathArgumentAttributesGetter> pathArgumentAttributesGetters = new HashMap<>();
+    private static final Map<Class<?>, PathArgumentAttributesGetter> PATH_ARGUMENT_ATTRIBUTES_GETTERS = new HashMap<>();
 
     public static NormalizedNodeMessages.PathArgument serialize(QNameSerializationContext context,
-            YangInstanceIdentifier.PathArgument pathArgument){
+            YangInstanceIdentifier.PathArgument pathArgument) {
         Preconditions.checkNotNull(context, "context should not be null");
         Preconditions.checkNotNull(pathArgument, "pathArgument should not be null");
 
@@ -54,7 +55,7 @@ public class PathArgumentSerializer {
 
 
     public static YangInstanceIdentifier.PathArgument deSerialize(QNameDeSerializationContext context,
-            NormalizedNodeMessages.PathArgument pathArgument){
+            NormalizedNodeMessages.PathArgument pathArgument) {
         Preconditions.checkNotNull(context, "context should not be null");
         Preconditions.checkNotNull(pathArgument, "pathArgument should not be null");
 
@@ -68,74 +69,52 @@ public class PathArgumentSerializer {
     }
 
     static {
-        pathArgumentAttributesGetters.put(YangInstanceIdentifier.NodeWithValue.class, new PathArgumentAttributesGetter() {
-            @Override
-            public Iterable<? extends NormalizedNodeMessages.PathArgumentAttribute> get(
-                    QNameSerializationContext context, YangInstanceIdentifier.PathArgument pathArgument) {
-
-                YangInstanceIdentifier.NodeWithValue<?> identifier
-                    = (YangInstanceIdentifier.NodeWithValue<?>) pathArgument;
+        PATH_ARGUMENT_ATTRIBUTES_GETTERS.put(YangInstanceIdentifier.NodeWithValue.class, (context, pathArgument) -> {
+            YangInstanceIdentifier.NodeWithValue<?> identifier = (YangInstanceIdentifier.NodeWithValue<?>) pathArgument;
 
-                NormalizedNodeMessages.PathArgumentAttribute attribute =
-                    buildAttribute(context, null, identifier.getValue());
+            NormalizedNodeMessages.PathArgumentAttribute attribute = buildAttribute(context, null,
+                    identifier.getValue());
 
-                return Arrays.asList(attribute);
-            }
+            return Arrays.asList(attribute);
         });
 
-        pathArgumentAttributesGetters.put(YangInstanceIdentifier.NodeIdentifierWithPredicates.class, new PathArgumentAttributesGetter() {
-            @Override
-            public Iterable<? extends NormalizedNodeMessages.PathArgumentAttribute> get(
-                    QNameSerializationContext context, YangInstanceIdentifier.PathArgument pathArgument) {
-
-                YangInstanceIdentifier.NodeIdentifierWithPredicates identifier
-                    = (YangInstanceIdentifier.NodeIdentifierWithPredicates) pathArgument;
+        PATH_ARGUMENT_ATTRIBUTES_GETTERS.put(YangInstanceIdentifier.NodeIdentifierWithPredicates.class,
+            (context, pathArgument) -> {
+                YangInstanceIdentifier.NodeIdentifierWithPredicates identifier =
+                        (YangInstanceIdentifier.NodeIdentifierWithPredicates) pathArgument;
 
                 Map<QName, Object> keyValues = identifier.getKeyValues();
-                List<NormalizedNodeMessages.PathArgumentAttribute> attributes =
-                        new ArrayList<>(keyValues.size());
+                List<NormalizedNodeMessages.PathArgumentAttribute> attributes = new ArrayList<>(keyValues.size());
                 for (Entry<QName, Object> e : keyValues.entrySet()) {
-                    NormalizedNodeMessages.PathArgumentAttribute attribute =
-                        buildAttribute(context, e.getKey(), e.getValue());
+                    NormalizedNodeMessages.PathArgumentAttribute attribute = buildAttribute(context, e.getKey(),
+                            e.getValue());
 
                     attributes.add(attribute);
                 }
 
                 return attributes;
-            }
-        });
+            });
 
-        pathArgumentAttributesGetters.put(YangInstanceIdentifier.AugmentationIdentifier.class, new PathArgumentAttributesGetter() {
-            @Override
-            public Iterable<? extends NormalizedNodeMessages.PathArgumentAttribute> get(
-                    QNameSerializationContext context, YangInstanceIdentifier.PathArgument pathArgument) {
-
-                YangInstanceIdentifier.AugmentationIdentifier identifier
-                    = (YangInstanceIdentifier.AugmentationIdentifier) pathArgument;
+        PATH_ARGUMENT_ATTRIBUTES_GETTERS.put(YangInstanceIdentifier.AugmentationIdentifier.class,
+            (context, pathArgument) -> {
+                YangInstanceIdentifier.AugmentationIdentifier identifier =
+                        (YangInstanceIdentifier.AugmentationIdentifier) pathArgument;
 
                 Set<QName> possibleChildNames = identifier.getPossibleChildNames();
-                List<NormalizedNodeMessages.PathArgumentAttribute> attributes =
-                        new ArrayList<>(possibleChildNames.size());
+                List<NormalizedNodeMessages.PathArgumentAttribute> attributes = new ArrayList<>(
+                        possibleChildNames.size());
                 for (QName key : possibleChildNames) {
                     Object value = key;
-                    NormalizedNodeMessages.PathArgumentAttribute attribute =
-                        buildAttribute(context, key, value);
+                    NormalizedNodeMessages.PathArgumentAttribute attribute = buildAttribute(context, key, value);
 
                     attributes.add(attribute);
                 }
 
                 return attributes;
-            }
-        });
+            });
 
-
-        pathArgumentAttributesGetters.put(YangInstanceIdentifier.NodeIdentifier.class, new PathArgumentAttributesGetter() {
-            @Override
-            public Iterable<? extends NormalizedNodeMessages.PathArgumentAttribute> get(
-                    QNameSerializationContext context, YangInstanceIdentifier.PathArgument pathArgument) {
-                return Collections.emptyList();
-            }
-        });
+        PATH_ARGUMENT_ATTRIBUTES_GETTERS.put(YangInstanceIdentifier.NodeIdentifier.class,
+            (context, pathArgument) -> Collections.emptyList());
     }
 
     private static NormalizedNodeMessages.PathArgumentAttribute buildAttribute(
@@ -150,45 +129,42 @@ public class PathArgumentSerializer {
 
     }
 
-    private static NormalizedNodeMessages.QName.Builder encodeQName(QNameSerializationContext context,
-            QName qName) {
-        if(qName == null) {
+    private static NormalizedNodeMessages.QName.Builder encodeQName(QNameSerializationContext context, QName qname) {
+        if (qname == null) {
             return NormalizedNodeMessages.QName.getDefaultInstance().toBuilder();
         }
-        NormalizedNodeMessages.QName.Builder qNameBuilder =
-            NormalizedNodeMessages.QName.newBuilder();
+        NormalizedNodeMessages.QName.Builder qnameBuilder = NormalizedNodeMessages.QName.newBuilder();
 
-        qNameBuilder.setNamespace(context.addNamespace(qName.getNamespace()));
+        qnameBuilder.setNamespace(context.addNamespace(qname.getNamespace()));
 
-        qNameBuilder.setRevision(context.addRevision(qName.getRevision()));
+        qnameBuilder.setRevision(context.addRevision(qname.getRevision()));
 
-        qNameBuilder.setLocalName(context.addLocalName(qName.getLocalName()));
+        qnameBuilder.setLocalName(context.addLocalName(qname.getLocalName()));
 
-        return qNameBuilder;
+        return qnameBuilder;
     }
 
     private static Iterable<? extends NormalizedNodeMessages.PathArgumentAttribute> getPathArgumentAttributes(
             QNameSerializationContext context, YangInstanceIdentifier.PathArgument pathArgument) {
 
-        return pathArgumentAttributesGetters.get(pathArgument.getClass()).get(context, pathArgument);
+        return PATH_ARGUMENT_ATTRIBUTES_GETTERS.get(pathArgument.getClass()).get(context, pathArgument);
     }
 
 
-    private static String qNameToString(QNameDeSerializationContext context,
-        NormalizedNodeMessages.QName qName){
+    private static String qNameToString(QNameDeSerializationContext context, NormalizedNodeMessages.QName qname) {
         // If this serializer is used qName cannot be null (see encodeQName)
         // adding null check only in case someone tried to deSerialize a protocol buffer node
         // that was not serialized using the PathArgumentSerializer
 //        Preconditions.checkNotNull(qName, "qName should not be null");
 //        Preconditions.checkArgument(qName.getNamespace() != -1, "qName.namespace should be valid");
 
-        String namespace = context.getNamespace(qName.getNamespace());
-        String localName = context.getLocalName(qName.getLocalName());
+        String namespace = context.getNamespace(qname.getNamespace());
+        String localName = context.getLocalName(qname.getLocalName());
         StringBuilder sb;
-        if(qName.getRevision() != -1){
-            String revision = context.getRevision(qName.getRevision());
-            sb = new StringBuilder(namespace.length() + REVISION_ARG.length() + revision.length() +
-                    localName.length() + 2);
+        if (qname.getRevision() != -1) {
+            String revision = context.getRevision(qname.getRevision());
+            sb = new StringBuilder(namespace.length() + REVISION_ARG.length() + revision.length()
+                    localName.length() + 2);
             sb.append('(').append(namespace).append(REVISION_ARG).append(
                 revision).append(')').append(localName);
         } else {
@@ -200,7 +176,7 @@ public class PathArgumentSerializer {
     }
 
     /**
-     * Parse a protocol buffer PathArgument and return an MD-SAL PathArgument
+     * Parse a protocol buffer PathArgument and return an MD-SAL PathArgument.
      *
      * @param pathArgument protocol buffer PathArgument
      * @return MD-SAL PathArgument
@@ -208,9 +184,8 @@ public class PathArgumentSerializer {
     private static YangInstanceIdentifier.PathArgument parsePathArgument(
             QNameDeSerializationContext context, NormalizedNodeMessages.PathArgument pathArgument) {
 
-        switch(PathArgumentType.values()[pathArgument.getIntType()]){
+        switch (PathArgumentType.values()[pathArgument.getIntType()]) {
             case NODE_IDENTIFIER_WITH_VALUE : {
-
                 YangInstanceIdentifier.NodeWithValue<?> nodeWithValue =
                     new YangInstanceIdentifier.NodeWithValue<>(
                         QNameFactory.create(qNameToString(context, pathArgument.getNodeType())),
@@ -220,7 +195,6 @@ public class PathArgumentSerializer {
             }
 
             case NODE_IDENTIFIER_WITH_PREDICATES : {
-
                 YangInstanceIdentifier.NodeIdentifierWithPredicates
                     nodeIdentifierWithPredicates =
                     new YangInstanceIdentifier.NodeIdentifierWithPredicates(
@@ -231,14 +205,13 @@ public class PathArgumentSerializer {
             }
 
             case AUGMENTATION_IDENTIFIER: {
+                Set<QName> qnameSet = new HashSet<>();
 
-                Set<QName> qNameSet = new HashSet<>();
-
-                for(NormalizedNodeMessages.PathArgumentAttribute attribute : pathArgument.getAttributeList()){
-                    qNameSet.add(QNameFactory.create(qNameToString(context, attribute.getName())));
+                for (NormalizedNodeMessages.PathArgumentAttribute attribute : pathArgument.getAttributeList()) {
+                    qnameSet.add(QNameFactory.create(qNameToString(context, attribute.getName())));
                 }
 
-                return new YangInstanceIdentifier.AugmentationIdentifier(qNameSet);
+                return new YangInstanceIdentifier.AugmentationIdentifier(qnameSet);
 
             }
             default: {
@@ -254,7 +227,7 @@ public class PathArgumentSerializer {
             List<NormalizedNodeMessages.PathArgumentAttribute> attributesList) {
 
         Map<QName, Object> map;
-        if(attributesList.size() == 1) {
+        if (attributesList.size() == 1) {
             NormalizedNodeMessages.PathArgumentAttribute attribute = attributesList.get(0);
             NormalizedNodeMessages.QName name = attribute.getName();
             Object value = parseAttribute(context, attribute);
@@ -262,7 +235,7 @@ public class PathArgumentSerializer {
         } else {
             map = new HashMap<>();
 
-            for(NormalizedNodeMessages.PathArgumentAttribute attribute : attributesList){
+            for (NormalizedNodeMessages.PathArgumentAttribute attribute : attributesList) {
                 NormalizedNodeMessages.QName name = attribute.getName();
                 Object value = parseAttribute(context, attribute);
 
@@ -274,8 +247,7 @@ public class PathArgumentSerializer {
     }
 
     private static Object parseAttribute(QNameDeSerializationContext context,
-            NormalizedNodeMessages.PathArgumentAttribute attribute){
+            NormalizedNodeMessages.PathArgumentAttribute attribute) {
         return ValueSerializer.deSerialize(context, attribute);
     }
-
 }
index 58a09ae88599204a4414f9844db1bb57e032be32..8209c9a5830e58dce8b0cf2fbb8862c61457a688 100644 (file)
@@ -8,9 +8,9 @@
 
 package org.opendaylight.controller.cluster.datastore.node.utils.serialization;
 
+import com.google.common.collect.ImmutableMap;
 import java.util.Map;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
-import com.google.common.collect.ImmutableMap;
 
 public enum PathArgumentType {
     AUGMENTATION_IDENTIFIER,
@@ -19,20 +19,19 @@ public enum PathArgumentType {
     NODE_IDENTIFIER_WITH_PREDICATES;
 
     private static Map<Class<?>, PathArgumentType> CLASS_TO_ENUM_MAP =
-            ImmutableMap.<Class<?>, PathArgumentType>builder().
-                put(YangInstanceIdentifier.AugmentationIdentifier.class, AUGMENTATION_IDENTIFIER).
-                put(YangInstanceIdentifier.NodeIdentifier.class, NODE_IDENTIFIER).
-                put(YangInstanceIdentifier.NodeIdentifierWithPredicates.class, NODE_IDENTIFIER_WITH_PREDICATES).
-                put(YangInstanceIdentifier.NodeWithValue.class, NODE_IDENTIFIER_WITH_VALUE).build();
+            ImmutableMap.<Class<?>, PathArgumentType>builder()
+                .put(YangInstanceIdentifier.AugmentationIdentifier.class, AUGMENTATION_IDENTIFIER)
+                .put(YangInstanceIdentifier.NodeIdentifier.class, NODE_IDENTIFIER)
+                .put(YangInstanceIdentifier.NodeIdentifierWithPredicates.class, NODE_IDENTIFIER_WITH_PREDICATES)
+                .put(YangInstanceIdentifier.NodeWithValue.class, NODE_IDENTIFIER_WITH_VALUE).build();
 
-    public static int getSerializablePathArgumentType(YangInstanceIdentifier.PathArgument pathArgument){
+    public static int getSerializablePathArgumentType(YangInstanceIdentifier.PathArgument pathArgument) {
 
         PathArgumentType type = CLASS_TO_ENUM_MAP.get(pathArgument.getClass());
-        if(type == null) {
+        if (type == null) {
             throw new IllegalArgumentException("Unknown type of PathArgument = " + pathArgument);
         }
 
         return type.ordinal();
     }
-
 }
index 09fe2efc3e767ac906bc183d63a11e0ae2343ff9..ff650a635a94301de425b62150d9669cc31e4c2c 100644 (file)
@@ -32,19 +32,19 @@ public class QNameSerializationContextImpl implements QNameSerializationContext
     @Override public int addNamespace(URI namespace) {
         int namespaceInt = getCode(namespace);
 
-        if(namespaceInt == -1) {
+        if (namespaceInt == -1) {
             namespaceInt = addCode(namespace, namespace.toString());
         }
         return namespaceInt;
     }
 
     @Override public int addRevision(Date revision) {
-        if(revision == null){
+        if (revision == null) {
             return -1;
         }
 
         int revisionInt = getCode(revision);
-        if(revisionInt == -1) {
+        if (revisionInt == -1) {
             String formattedRevision =
                 SimpleDateFormatUtil.getRevisionFormat().format(revision);
             revisionInt = addCode(revision, formattedRevision);
@@ -54,21 +54,21 @@ public class QNameSerializationContextImpl implements QNameSerializationContext
 
     @Override public int addLocalName(String localName) {
         int localNameInt = getCode(localName);
-        if(localNameInt == -1) {
+        if (localNameInt == -1) {
             localNameInt = addCode(localName, localName);
         }
         return localNameInt;
 
     }
 
-    private int addCode(Object code, String codeStr){
+    private int addCode(Object code, String codeStr) {
         int count = codes.size();
         codes.add(codeStr);
         codeMap.put(code, Integer.valueOf(count));
         return count;
     }
 
-    private int getCode(Object code){
+    private int getCode(Object code) {
         Integer value = codeMap.get(code);
         return value == null ? -1 : value.intValue();
     }
index 9e3230a623855d4add4249d68af0c2c216f4d79f..7523976a73d1c24d6fdf807f6b1297f9e5482a5e 100644 (file)
@@ -22,24 +22,24 @@ public class ValueSerializer {
             QNameSerializationContext context, Object value) {
         builder.setIntValueType(ValueType.getSerializableType(value).ordinal());
 
-        if(value instanceof YangInstanceIdentifier) {
+        if (value instanceof YangInstanceIdentifier) {
             builder.setInstanceIdentifierValue(
                 InstanceIdentifierUtils.toSerializable((YangInstanceIdentifier) value, context));
-        } else if(value instanceof Set) {
+        } else if (value instanceof Set) {
             Set<?> set = (Set<?>) value;
             if (!set.isEmpty()) {
                 for (Object o : set) {
                     if (o instanceof String) {
                         builder.addBitsValue(o.toString());
                     } else {
-                        throw new IllegalArgumentException("Expected value type to be Bits but was : " +
-                                value.toString());
+                        throw new IllegalArgumentException("Expected value type to be Bits but was : "
+                            + value.toString());
                     }
                 }
             }
-        } else if(value instanceof byte[]) {
+        } else if (value instanceof byte[]) {
             builder.setBytesValue(ByteString.copyFrom((byte[]) value));
-        } else if(value == null){
+        } else if (value == null) {
             builder.setValue(NULL_VALUE);
         } else {
             builder.setValue(value.toString());
@@ -47,28 +47,28 @@ public class ValueSerializer {
     }
 
     public static void serialize(NormalizedNodeMessages.PathArgumentAttribute.Builder builder,
-            QNameSerializationContext context, Object value){
+            QNameSerializationContext context, Object value) {
 
         builder.setType(ValueType.getSerializableType(value).ordinal());
 
-        if(value instanceof YangInstanceIdentifier) {
+        if (value instanceof YangInstanceIdentifier) {
             builder.setInstanceIdentifierValue(
                     InstanceIdentifierUtils.toSerializable((YangInstanceIdentifier) value, context));
-        } else if(value instanceof Set) {
+        } else if (value instanceof Set) {
             Set<?> set = (Set<?>) value;
             if (!set.isEmpty()) {
                 for (Object o : set) {
                     if (o instanceof String) {
                         builder.addBitsValue(o.toString());
                     } else {
-                        throw new IllegalArgumentException("Expected value type to be Bits but was : " +
-                                value.toString());
+                        throw new IllegalArgumentException("Expected value type to be Bits but was : "
+                            + value.toString());
                     }
                 }
             }
-        } else if(value instanceof byte[]){
+        } else if (value instanceof byte[]) {
             builder.setBytesValue(ByteString.copyFrom((byte[]) value));
-        } else if(value == null){
+        } else if (value == null) {
             builder.setValue(NULL_VALUE);
         } else {
             builder.setValue(value.toString());
@@ -77,12 +77,11 @@ public class ValueSerializer {
 
     public static Object deSerialize(QNameDeSerializationContext context,
             NormalizedNodeMessages.Node node) {
-        if(node.getIntValueType() == ValueType.YANG_IDENTIFIER_TYPE.ordinal()){
-            return InstanceIdentifierUtils.fromSerializable(
-                    node.getInstanceIdentifierValue(), context);
-        } else if(node.getIntValueType() == ValueType.BITS_TYPE.ordinal()){
+        if (node.getIntValueType() == ValueType.YANG_IDENTIFIER_TYPE.ordinal()) {
+            return InstanceIdentifierUtils.fromSerializable(node.getInstanceIdentifierValue(), context);
+        } else if (node.getIntValueType() == ValueType.BITS_TYPE.ordinal()) {
             return new HashSet<>(node.getBitsValueList());
-        } else if(node.getIntValueType() == ValueType.BINARY_TYPE.ordinal()){
+        } else if (node.getIntValueType() == ValueType.BINARY_TYPE.ordinal()) {
             return node.getBytesValue().toByteArray();
         }
         return deSerializeBasicTypes(node.getIntValueType(), node.getValue());
@@ -91,12 +90,11 @@ public class ValueSerializer {
     public static Object deSerialize(QNameDeSerializationContext context,
             NormalizedNodeMessages.PathArgumentAttribute attribute) {
 
-        if(attribute.getType() == ValueType.YANG_IDENTIFIER_TYPE.ordinal()){
-            return InstanceIdentifierUtils.fromSerializable(
-                    attribute.getInstanceIdentifierValue(), context);
-        } else if(attribute.getType() == ValueType.BITS_TYPE.ordinal()){
+        if (attribute.getType() == ValueType.YANG_IDENTIFIER_TYPE.ordinal()) {
+            return InstanceIdentifierUtils.fromSerializable(attribute.getInstanceIdentifierValue(), context);
+        } else if (attribute.getType() == ValueType.BITS_TYPE.ordinal()) {
             return new HashSet<>(attribute.getBitsValueList());
-        } else if(attribute.getType() == ValueType.BINARY_TYPE.ordinal()){
+        } else if (attribute.getType() == ValueType.BINARY_TYPE.ordinal()) {
             return attribute.getBytesValue().toByteArray();
         }
         return deSerializeBasicTypes(attribute.getType(), attribute.getValue());
index 0015a06149ffe84f6a180f8971ed3bd461d30248..fe0c97b77f2bb8bf70a9df629719cef83c972b2b 100644 (file)
@@ -120,7 +120,7 @@ public enum ValueType {
     abstract Object deserialize(String str);
 
     public static final ValueType getSerializableType(Object node) {
-        if(node == null){
+        if (node == null) {
             return NULL_TYPE;
         }
 
index 3dc8f1c591d37e18027cc1d886c5f6b9b5acafd4..51a9c1c24eafe5ee29289f202679ce0e39730172 100644 (file)
@@ -56,95 +56,97 @@ abstract class AbstractNormalizedNodeDataOutput implements NormalizedNodeDataOut
     }
 
     protected abstract short streamVersion();
+
     protected abstract void writeQName(QName qname) throws IOException;
+
     protected abstract void writeString(String string) throws IOException;
 
     @Override
-    public final void write(final int b) throws IOException {
+    public final void write(final int value) throws IOException {
         ensureHeaderWritten();
-        output.write(b);
+        output.write(value);
     }
 
     @Override
-    public final void write(final byte[] b) throws IOException {
+    public final void write(final byte[] bytes) throws IOException {
         ensureHeaderWritten();
-        output.write(b);
+        output.write(bytes);
     }
 
     @Override
-    public final void write(final byte[] b, final int off, final int len) throws IOException {
+    public final void write(final byte[] bytes, final int off, final int len) throws IOException {
         ensureHeaderWritten();
-        output.write(b, off, len);
+        output.write(bytes, off, len);
     }
 
     @Override
-    public final void writeBoolean(final boolean v) throws IOException {
+    public final void writeBoolean(final boolean value) throws IOException {
         ensureHeaderWritten();
-        output.writeBoolean(v);
+        output.writeBoolean(value);
     }
 
     @Override
-    public final void writeByte(final int v) throws IOException {
+    public final void writeByte(final int value) throws IOException {
         ensureHeaderWritten();
-        output.writeByte(v);
+        output.writeByte(value);
     }
 
     @Override
-    public final void writeShort(final int v) throws IOException {
+    public final void writeShort(final int value) throws IOException {
         ensureHeaderWritten();
-        output.writeShort(v);
+        output.writeShort(value);
     }
 
     @Override
-    public final void writeChar(final int v) throws IOException {
+    public final void writeChar(final int value) throws IOException {
         ensureHeaderWritten();
-        output.writeChar(v);
+        output.writeChar(value);
     }
 
     @Override
-    public final void writeInt(final int v) throws IOException {
+    public final void writeInt(final int value) throws IOException {
         ensureHeaderWritten();
-        output.writeInt(v);
+        output.writeInt(value);
     }
 
     @Override
-    public final void writeLong(final long v) throws IOException {
+    public final void writeLong(final long value) throws IOException {
         ensureHeaderWritten();
-        output.writeLong(v);
+        output.writeLong(value);
     }
 
     @Override
-    public final void writeFloat(final float v) throws IOException {
+    public final void writeFloat(final float value) throws IOException {
         ensureHeaderWritten();
-        output.writeFloat(v);
+        output.writeFloat(value);
     }
 
     @Override
-    public final void writeDouble(final double v) throws IOException {
+    public final void writeDouble(final double value) throws IOException {
         ensureHeaderWritten();
-        output.writeDouble(v);
+        output.writeDouble(value);
     }
 
     @Override
-    public final void writeBytes(final String s) throws IOException {
+    public final void writeBytes(final String str) throws IOException {
         ensureHeaderWritten();
-        output.writeBytes(s);
+        output.writeBytes(str);
     }
 
     @Override
-    public final void writeChars(final String s) throws IOException {
+    public final void writeChars(final String str) throws IOException {
         ensureHeaderWritten();
-        output.writeChars(s);
+        output.writeChars(str);
     }
 
     @Override
-    public final void writeUTF(final String s) throws IOException {
+    public final void writeUTF(final String str) throws IOException {
         ensureHeaderWritten();
-        output.writeUTF(s);
+        output.writeUTF(str);
     }
 
     private NormalizedNodeWriter normalizedNodeWriter() {
-        if(normalizedNodeWriter == null) {
+        if (normalizedNodeWriter == null) {
             normalizedNodeWriter = NormalizedNodeWriter.forStreamWriter(this);
         }
 
@@ -167,7 +169,9 @@ abstract class AbstractNormalizedNodeDataOutput implements NormalizedNodeDataOut
     }
 
     @Override
-    public void startLeafSet(final NodeIdentifier name, final int childSizeHint) throws IOException, IllegalArgumentException {
+    public void startLeafSet(final NodeIdentifier name, final int childSizeHint)
+
+            throws IOException, IllegalArgumentException {
         Preconditions.checkNotNull(name, "Node identifier should not be null");
         LOG.debug("Starting a new leaf set");
 
@@ -176,7 +180,8 @@ abstract class AbstractNormalizedNodeDataOutput implements NormalizedNodeDataOut
     }
 
     @Override
-    public void startOrderedLeafSet(final NodeIdentifier name, final int childSizeHint) throws IOException, IllegalArgumentException {
+    public void startOrderedLeafSet(final NodeIdentifier name, final int childSizeHint)
+            throws IOException, IllegalArgumentException {
         Preconditions.checkNotNull(name, "Node identifier should not be null");
         LOG.debug("Starting a new ordered leaf set");
 
@@ -192,7 +197,7 @@ abstract class AbstractNormalizedNodeDataOutput implements NormalizedNodeDataOut
 
         // lastLeafSetQName is set if the parent LeafSetNode was previously written. Otherwise this is a
         // stand alone LeafSetEntryNode so write out it's name here.
-        if(lastLeafSetQName == null) {
+        if (lastLeafSetQName == null) {
             writeQName(name);
         }
 
@@ -200,7 +205,8 @@ abstract class AbstractNormalizedNodeDataOutput implements NormalizedNodeDataOut
     }
 
     @Override
-    public void startContainerNode(final NodeIdentifier name, final int childSizeHint) throws IOException, IllegalArgumentException {
+    public void startContainerNode(final NodeIdentifier name, final int childSizeHint)
+            throws IOException, IllegalArgumentException {
         Preconditions.checkNotNull(name, "Node identifier should not be null");
 
         LOG.debug("Starting a new container node");
@@ -209,7 +215,8 @@ abstract class AbstractNormalizedNodeDataOutput implements NormalizedNodeDataOut
     }
 
     @Override
-    public void startYangModeledAnyXmlNode(final NodeIdentifier name, final int childSizeHint) throws IOException, IllegalArgumentException {
+    public void startYangModeledAnyXmlNode(final NodeIdentifier name, final int childSizeHint)
+            throws IOException, IllegalArgumentException {
         Preconditions.checkNotNull(name, "Node identifier should not be null");
 
         LOG.debug("Starting a new yang modeled anyXml node");
@@ -218,7 +225,8 @@ abstract class AbstractNormalizedNodeDataOutput implements NormalizedNodeDataOut
     }
 
     @Override
-    public void startUnkeyedList(final NodeIdentifier name, final int childSizeHint) throws IOException, IllegalArgumentException {
+    public void startUnkeyedList(final NodeIdentifier name, final int childSizeHint)
+            throws IOException, IllegalArgumentException {
         Preconditions.checkNotNull(name, "Node identifier should not be null");
         LOG.debug("Starting a new unkeyed list");
 
@@ -226,7 +234,8 @@ abstract class AbstractNormalizedNodeDataOutput implements NormalizedNodeDataOut
     }
 
     @Override
-    public void startUnkeyedListItem(final NodeIdentifier name, final int childSizeHint) throws IOException, IllegalStateException {
+    public void startUnkeyedListItem(final NodeIdentifier name, final int childSizeHint)
+            throws IOException, IllegalStateException {
         Preconditions.checkNotNull(name, "Node identifier should not be null");
         LOG.debug("Starting a new unkeyed list item");
 
@@ -234,7 +243,8 @@ abstract class AbstractNormalizedNodeDataOutput implements NormalizedNodeDataOut
     }
 
     @Override
-    public void startMapNode(final NodeIdentifier name, final int childSizeHint) throws IOException, IllegalArgumentException {
+    public void startMapNode(final NodeIdentifier name, final int childSizeHint)
+            throws IOException, IllegalArgumentException {
         Preconditions.checkNotNull(name, "Node identifier should not be null");
         LOG.debug("Starting a new map node");
 
@@ -242,7 +252,8 @@ abstract class AbstractNormalizedNodeDataOutput implements NormalizedNodeDataOut
     }
 
     @Override
-    public void startMapEntryNode(final NodeIdentifierWithPredicates identifier, final int childSizeHint) throws IOException, IllegalArgumentException {
+    public void startMapEntryNode(final NodeIdentifierWithPredicates identifier, final int childSizeHint)
+            throws IOException, IllegalArgumentException {
         Preconditions.checkNotNull(identifier, "Node identifier should not be null");
         LOG.debug("Starting a new map entry node");
         startNode(identifier.getNodeType(), NodeTypes.MAP_ENTRY_NODE);
@@ -252,7 +263,8 @@ abstract class AbstractNormalizedNodeDataOutput implements NormalizedNodeDataOut
     }
 
     @Override
-    public void startOrderedMapNode(final NodeIdentifier name, final int childSizeHint) throws IOException, IllegalArgumentException {
+    public void startOrderedMapNode(final NodeIdentifier name, final int childSizeHint)
+            throws IOException, IllegalArgumentException {
         Preconditions.checkNotNull(name, "Node identifier should not be null");
         LOG.debug("Starting a new ordered map node");
 
@@ -260,7 +272,8 @@ abstract class AbstractNormalizedNodeDataOutput implements NormalizedNodeDataOut
     }
 
     @Override
-    public void startChoiceNode(final NodeIdentifier name, final int childSizeHint) throws IOException, IllegalArgumentException {
+    public void startChoiceNode(final NodeIdentifier name, final int childSizeHint)
+            throws IOException, IllegalArgumentException {
         Preconditions.checkNotNull(name, "Node identifier should not be null");
         LOG.debug("Starting a new choice node");
 
@@ -268,7 +281,8 @@ abstract class AbstractNormalizedNodeDataOutput implements NormalizedNodeDataOut
     }
 
     @Override
-    public void startAugmentationNode(final AugmentationIdentifier identifier) throws IOException, IllegalArgumentException {
+    public void startAugmentationNode(final AugmentationIdentifier identifier)
+            throws IOException, IllegalArgumentException {
         Preconditions.checkNotNull(identifier, "Node identifier should not be null");
         LOG.debug("Starting a new augmentation node");
 
@@ -311,16 +325,15 @@ abstract class AbstractNormalizedNodeDataOutput implements NormalizedNodeDataOut
         }
     }
 
-    private void startNode(final QName qName, final byte nodeType) throws IOException {
-
-        Preconditions.checkNotNull(qName, "QName of node identifier should not be null.");
+    private void startNode(final QName qname, final byte nodeType) throws IOException {
+        Preconditions.checkNotNull(qname, "QName of node identifier should not be null.");
 
         ensureHeaderWritten();
 
         // First write the type of node
         output.writeByte(nodeType);
         // Write Start Tag
-        writeQName(qName);
+        writeQName(qname);
     }
 
     private void writeObjSet(final Set<?> set) throws IOException {
@@ -343,7 +356,7 @@ abstract class AbstractNormalizedNodeDataOutput implements NormalizedNodeDataOut
         Collection<PathArgument> pathArguments = identifier.getPathArguments();
         output.writeInt(pathArguments.size());
 
-        for(PathArgument pathArgument : pathArguments) {
+        for (PathArgument pathArgument : pathArguments) {
             writePathArgument(pathArgument);
         }
     }
@@ -355,7 +368,7 @@ abstract class AbstractNormalizedNodeDataOutput implements NormalizedNodeDataOut
 
         output.writeByte(type);
 
-        switch(type) {
+        switch (type) {
             case PathArgumentTypes.NODE_IDENTIFIER:
 
                 NodeIdentifier nodeIdentifier = (NodeIdentifier) pathArgument;
@@ -388,7 +401,8 @@ abstract class AbstractNormalizedNodeDataOutput implements NormalizedNodeDataOut
                 writeQNameSet(augmentationIdentifier.getPossibleChildNames());
                 break;
             default :
-                throw new IllegalStateException("Unknown node identifier type is found : " + pathArgument.getClass().toString() );
+                throw new IllegalStateException("Unknown node identifier type is found : "
+                        + pathArgument.getClass().toString() );
         }
     }
 
@@ -396,9 +410,9 @@ abstract class AbstractNormalizedNodeDataOutput implements NormalizedNodeDataOut
         if (keyValueMap != null && !keyValueMap.isEmpty()) {
             output.writeInt(keyValueMap.size());
 
-            for (QName qName : keyValueMap.keySet()) {
-                writeQName(qName);
-                writeObject(keyValueMap.get(qName));
+            for (QName qname : keyValueMap.keySet()) {
+                writeQName(qname);
+                writeObject(keyValueMap.get(qname));
             }
         } else {
             output.writeInt(0);
@@ -409,8 +423,8 @@ abstract class AbstractNormalizedNodeDataOutput implements NormalizedNodeDataOut
         // Write each child's qname separately, if list is empty send count as 0
         if (children != null && !children.isEmpty()) {
             output.writeInt(children.size());
-            for (QName qName : children) {
-                writeQName(qName);
+            for (QName qname : children) {
+                writeQName(qname);
             }
         } else {
             LOG.debug("augmentation node does not have any child");
index 10f412c9e2ae357b30a6990fe65c10013cc69340..0c3422488383324c1a49840e04ee1989ea2ceb2c 100644 (file)
@@ -20,7 +20,9 @@ import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
 @Beta
 public interface NormalizedNodeDataOutput extends AutoCloseable, DataOutput {
     void writeNormalizedNode(NormalizedNode<?, ?> normalizedNode) throws IOException;
+
     void writePathArgument(PathArgument pathArgument) throws IOException;
+
     void writeYangInstanceIdentifier(YangInstanceIdentifier identifier) throws IOException;
 
     @Override
index 8a114893e66b7c0bca923af23f2c69323e1925d8..ec043560496cefc2ec031bb61e2972e66779ee6d 100644 (file)
@@ -46,12 +46,10 @@ import org.xml.sax.InputSource;
 import org.xml.sax.SAXException;
 
 /**
- * NormalizedNodeInputStreamReader reads the byte stream and constructs the normalized node including its children nodes.
- * This process goes in recursive manner, where each NodeTypes object signifies the start of the object, except END_NODE.
- * If a node can have children, then that node's end is calculated based on appearance of END_NODE.
- *
+ * NormalizedNodeInputStreamReader reads the byte stream and constructs the normalized node including its children
+ * nodes. This process goes in recursive manner, where each NodeTypes object signifies the start of the object, except
+ * END_NODE. If a node can have children, then that node's end is calculated based on appearance of END_NODE.
  */
-
 public class NormalizedNodeInputStreamReader implements NormalizedNodeDataInput {
 
     private static final Logger LOG = LoggerFactory.getLogger(NormalizedNodeInputStreamReader.class);
@@ -67,6 +65,7 @@ public class NormalizedNodeInputStreamReader implements NormalizedNodeDataInput
     private NormalizedNodeAttrBuilder<YangInstanceIdentifier.NodeIdentifier,
                                       Object, LeafNode<Object>> leafBuilder;
 
+    @SuppressWarnings("rawtypes")
     private NormalizedNodeAttrBuilder<NodeWithValue, Object, LeafSetEntryNode<Object>> leafSetEntryBuilder;
 
     private final StringBuilder reusableStringBuilder = new StringBuilder(50);
@@ -74,6 +73,8 @@ public class NormalizedNodeInputStreamReader implements NormalizedNodeDataInput
     private boolean readSignatureMarker = true;
 
     /**
+     * Constructs an instance.
+     *
      * @deprecated Use {@link NormalizedNodeInputOutput#newDataInput(DataInput)} instead.
      */
     @Deprecated
@@ -93,7 +94,7 @@ public class NormalizedNodeInputStreamReader implements NormalizedNodeDataInput
     }
 
     private void readSignatureMarkerAndVersionIfNeeded() throws IOException {
-        if(readSignatureMarker) {
+        if (readSignatureMarker) {
             readSignatureMarker = false;
 
             final byte marker = input.readByte();
@@ -113,24 +114,24 @@ public class NormalizedNodeInputStreamReader implements NormalizedNodeDataInput
         // each node should start with a byte
         byte nodeType = input.readByte();
 
-        if(nodeType == NodeTypes.END_NODE) {
+        if (nodeType == NodeTypes.END_NODE) {
             LOG.debug("End node reached. return");
             return null;
         }
 
-        switch(nodeType) {
+        switch (nodeType) {
             case NodeTypes.AUGMENTATION_NODE :
                 YangInstanceIdentifier.AugmentationIdentifier augIdentifier =
                     new YangInstanceIdentifier.AugmentationIdentifier(readQNameSet());
 
                 LOG.debug("Reading augmentation node {} ", augIdentifier);
 
-                return addDataContainerChildren(Builders.augmentationBuilder().
-                        withNodeIdentifier(augIdentifier)).build();
+                return addDataContainerChildren(Builders.augmentationBuilder()
+                        .withNodeIdentifier(augIdentifier)).build();
 
             case NodeTypes.LEAF_SET_ENTRY_NODE :
                 QName name = lastLeafSetQName;
-                if(name == null) {
+                if (name == null) {
                     name = readQName();
                 }
 
@@ -147,8 +148,8 @@ public class NormalizedNodeInputStreamReader implements NormalizedNodeDataInput
 
                 LOG.debug("Reading map entry node {} ", entryIdentifier);
 
-                return addDataContainerChildren(Builders.mapEntryBuilder().
-                        withNodeIdentifier(entryIdentifier)).build();
+                return addDataContainerChildren(Builders.mapEntryBuilder()
+                        .withNodeIdentifier(entryIdentifier)).build();
 
             default :
                 return readNodeIdentifierDependentNode(nodeType, new NodeIdentifier(readQName()));
@@ -157,16 +158,17 @@ public class NormalizedNodeInputStreamReader implements NormalizedNodeDataInput
 
     private NormalizedNodeAttrBuilder<YangInstanceIdentifier.NodeIdentifier,
                                       Object, LeafNode<Object>> leafBuilder() {
-        if(leafBuilder == null) {
+        if (leafBuilder == null) {
             leafBuilder = Builders.leafBuilder();
         }
 
         return leafBuilder;
     }
 
+    @SuppressWarnings("rawtypes")
     private NormalizedNodeAttrBuilder<NodeWithValue, Object,
                                       LeafSetEntryNode<Object>> leafSetEntryBuilder() {
-        if(leafSetEntryBuilder == null) {
+        if (leafSetEntryBuilder == null) {
             leafSetEntryBuilder = Builders.leafSetEntryBuilder();
         }
 
@@ -176,7 +178,7 @@ public class NormalizedNodeInputStreamReader implements NormalizedNodeDataInput
     private NormalizedNode<?, ?> readNodeIdentifierDependentNode(final byte nodeType, final NodeIdentifier identifier)
         throws IOException {
 
-        switch(nodeType) {
+        switch (nodeType) {
             case NodeTypes.LEAF_NODE :
                 LOG.debug("Read leaf node {}", identifier);
                 // Read the object value
@@ -188,33 +190,28 @@ public class NormalizedNodeInputStreamReader implements NormalizedNodeDataInput
 
             case NodeTypes.MAP_NODE :
                 LOG.debug("Read map node {}", identifier);
-                return addDataContainerChildren(Builders.mapBuilder().
-                        withNodeIdentifier(identifier)).build();
+                return addDataContainerChildren(Builders.mapBuilder().withNodeIdentifier(identifier)).build();
 
-            case NodeTypes.CHOICE_NODE :
+            case NodeTypes.CHOICE_NODE:
                 LOG.debug("Read choice node {}", identifier);
-                return addDataContainerChildren(Builders.choiceBuilder().
-                        withNodeIdentifier(identifier)).build();
+                return addDataContainerChildren(Builders.choiceBuilder().withNodeIdentifier(identifier)).build();
 
-            case NodeTypes.ORDERED_MAP_NODE :
+            case NodeTypes.ORDERED_MAP_NODE:
                 LOG.debug("Reading ordered map node {}", identifier);
-                return addDataContainerChildren(Builders.orderedMapBuilder().
-                        withNodeIdentifier(identifier)).build();
+                return addDataContainerChildren(Builders.orderedMapBuilder().withNodeIdentifier(identifier)).build();
 
-            case NodeTypes.UNKEYED_LIST :
+            case NodeTypes.UNKEYED_LIST:
                 LOG.debug("Read unkeyed list node {}", identifier);
-                return addDataContainerChildren(Builders.unkeyedListBuilder().
-                        withNodeIdentifier(identifier)).build();
+                return addDataContainerChildren(Builders.unkeyedListBuilder().withNodeIdentifier(identifier)).build();
 
-            case NodeTypes.UNKEYED_LIST_ITEM :
+            case NodeTypes.UNKEYED_LIST_ITEM:
                 LOG.debug("Read unkeyed list item node {}", identifier);
-                return addDataContainerChildren(Builders.unkeyedListEntryBuilder().
-                        withNodeIdentifier(identifier)).build();
+                return addDataContainerChildren(Builders.unkeyedListEntryBuilder()
+                        .withNodeIdentifier(identifier)).build();
 
-            case NodeTypes.CONTAINER_NODE :
+            case NodeTypes.CONTAINER_NODE:
                 LOG.debug("Read container node {}", identifier);
-                return addDataContainerChildren(Builders.containerBuilder().
-                        withNodeIdentifier(identifier)).build();
+                return addDataContainerChildren(Builders.containerBuilder().withNodeIdentifier(identifier)).build();
 
             case NodeTypes.LEAF_SET :
                 LOG.debug("Read leaf set node {}", identifier);
@@ -252,25 +249,24 @@ public class NormalizedNodeInputStreamReader implements NormalizedNodeDataInput
         String namespace = readCodedString();
         String revision = readCodedString();
 
-        String qName;
-        if(!Strings.isNullOrEmpty(revision)) {
-            qName = reusableStringBuilder.append('(').append(namespace).append(REVISION_ARG).
-                        append(revision).append(')').append(localName).toString();
+        String qname;
+        if (!Strings.isNullOrEmpty(revision)) {
+            qname = reusableStringBuilder.append('(').append(namespace).append(REVISION_ARG).append(revision)
+                    .append(')').append(localName).toString();
         } else {
-            qName = reusableStringBuilder.append('(').append(namespace).append(')').
-                        append(localName).toString();
+            qname = reusableStringBuilder.append('(').append(namespace).append(')').append(localName).toString();
         }
 
         reusableStringBuilder.delete(0, reusableStringBuilder.length());
-        return QNameFactory.create(qName);
+        return QNameFactory.create(qname);
     }
 
 
     private String readCodedString() throws IOException {
         byte valueType = input.readByte();
-        if(valueType == TokenTypes.IS_CODE_VALUE) {
+        if (valueType == TokenTypes.IS_CODE_VALUE) {
             return codedStringMap.get(input.readInt());
-        } else if(valueType == TokenTypes.IS_STRING_VALUE) {
+        } else if (valueType == TokenTypes.IS_STRING_VALUE) {
             String value = input.readUTF().intern();
             codedStringMap.put(Integer.valueOf(codedStringMap.size()), value);
             return value;
@@ -279,11 +275,11 @@ public class NormalizedNodeInputStreamReader implements NormalizedNodeDataInput
         return null;
     }
 
-    private Set<QName> readQNameSet() throws IOException{
+    private Set<QName> readQNameSet() throws IOException {
         // Read the children count
         int count = input.readInt();
         Set<QName> children = new HashSet<>(count);
-        for(int i = 0; i < count; i++) {
+        for (int i = 0; i < count; i++) {
             children.add(readQName());
         }
         return children;
@@ -293,7 +289,7 @@ public class NormalizedNodeInputStreamReader implements NormalizedNodeDataInput
         int count = input.readInt();
         Map<QName, Object> keyValueMap = new HashMap<>(count);
 
-        for(int i = 0; i < count; i++) {
+        for (int i = 0; i < count; i++) {
             keyValueMap.put(readQName(), readObject());
         }
 
@@ -302,7 +298,7 @@ public class NormalizedNodeInputStreamReader implements NormalizedNodeDataInput
 
     private Object readObject() throws IOException {
         byte objectType = input.readByte();
-        switch(objectType) {
+        switch (objectType) {
             case ValueTypes.BITS_TYPE:
                 return readObjSet();
 
@@ -366,7 +362,7 @@ public class NormalizedNodeInputStreamReader implements NormalizedNodeDataInput
 
         List<PathArgument> pathArguments = new ArrayList<>(size);
 
-        for(int i = 0; i < size; i++) {
+        for (int i = 0; i < size; i++) {
             pathArguments.add(readPathArgument());
         }
         return YangInstanceIdentifier.create(pathArguments);
@@ -375,7 +371,7 @@ public class NormalizedNodeInputStreamReader implements NormalizedNodeDataInput
     private Set<String> readObjSet() throws IOException {
         int count = input.readInt();
         Set<String> children = new HashSet<>(count);
-        for(int i = 0; i < count; i++) {
+        for (int i = 0; i < count; i++) {
             children.add(readCodedString());
         }
         return children;
@@ -386,7 +382,7 @@ public class NormalizedNodeInputStreamReader implements NormalizedNodeDataInput
         // read Type
         int type = input.readByte();
 
-        switch(type) {
+        switch (type) {
 
             case PathArgumentTypes.AUGMENTATION_IDENTIFIER :
                 return new YangInstanceIdentifier.AugmentationIdentifier(readQNameSet());
@@ -415,7 +411,7 @@ public class NormalizedNodeInputStreamReader implements NormalizedNodeDataInput
 
         LeafSetEntryNode<Object> child = (LeafSetEntryNode<Object>)readNormalizedNodeInternal();
 
-        while(child != null) {
+        while (child != null) {
             builder.withChild(child);
             child = (LeafSetEntryNode<Object>)readNormalizedNodeInternal();
         }
@@ -429,7 +425,7 @@ public class NormalizedNodeInputStreamReader implements NormalizedNodeDataInput
 
         NormalizedNode<?, ?> child = readNormalizedNodeInternal();
 
-        while(child != null) {
+        while (child != null) {
             builder.addChild(child);
             child = readNormalizedNodeInternal();
         }
@@ -437,21 +433,21 @@ public class NormalizedNodeInputStreamReader implements NormalizedNodeDataInput
     }
 
     @Override
-    public void readFully(final byte[] b) throws IOException {
+    public void readFully(final byte[] value) throws IOException {
         readSignatureMarkerAndVersionIfNeeded();
-        input.readFully(b);
+        input.readFully(value);
     }
 
     @Override
-    public void readFully(final byte[] b, final int off, final int len) throws IOException {
+    public void readFully(final byte[] str, final int off, final int len) throws IOException {
         readSignatureMarkerAndVersionIfNeeded();
-        input.readFully(b, off, len);
+        input.readFully(str, off, len);
     }
 
     @Override
-    public int skipBytes(final int n) throws IOException {
+    public int skipBytes(final int num) throws IOException {
         readSignatureMarkerAndVersionIfNeeded();
-        return input.skipBytes(n);
+        return input.skipBytes(num);
     }
 
     @Override
index 5eaa7fc1b7cf1d9a82ae44a454f09cd8fa089853..94d1baddc5a86b5f115a19a53e19656d1e53a03e 100644 (file)
@@ -24,7 +24,7 @@ import org.opendaylight.yangtools.yang.common.QName;
  * then will call
  * {@link #leafNode(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier, Object)} twice
  * and then, {@link #endNode()} to end container node.
- *
+ * <p/>
  * Based on the each node, the node type is also written to the stream, that helps in reconstructing the object,
  * while reading.
  */
@@ -36,7 +36,7 @@ final class NormalizedNodeOutputStreamWriter extends AbstractNormalizedNodeDataO
     }
 
     @Override
-    protected final short streamVersion() {
+    protected short streamVersion() {
         return TokenTypes.LITHIUM_VERSION;
     }
 
index dd140ca410156d028175243dbd66fba67e339794..b372d8f9157ae645b56ff2c99d3c509f77074e5a 100644 (file)
@@ -23,12 +23,11 @@ final class PathArgumentTypes {
         throw new UnsupportedOperationException("Utility class");
     }
 
-    private static final Map<Class<?>, Byte> CLASS_TO_ENUM_MAP =
-            ImmutableMap.<Class<?>, Byte>builder().
-                put(YangInstanceIdentifier.AugmentationIdentifier.class, AUGMENTATION_IDENTIFIER).
-                put(YangInstanceIdentifier.NodeIdentifier.class, NODE_IDENTIFIER).
-                put(YangInstanceIdentifier.NodeIdentifierWithPredicates.class, NODE_IDENTIFIER_WITH_PREDICATES).
-                put(YangInstanceIdentifier.NodeWithValue.class, NODE_IDENTIFIER_WITH_VALUE).build();
+    private static final Map<Class<?>, Byte> CLASS_TO_ENUM_MAP = ImmutableMap.<Class<?>, Byte>builder()
+            .put(YangInstanceIdentifier.AugmentationIdentifier.class, AUGMENTATION_IDENTIFIER)
+            .put(YangInstanceIdentifier.NodeIdentifier.class, NODE_IDENTIFIER)
+            .put(YangInstanceIdentifier.NodeIdentifierWithPredicates.class, NODE_IDENTIFIER_WITH_PREDICATES)
+            .put(YangInstanceIdentifier.NodeWithValue.class, NODE_IDENTIFIER_WITH_VALUE).build();
 
     public static byte getSerializablePathArgumentType(YangInstanceIdentifier.PathArgument pathArgument) {
         final Byte type = CLASS_TO_ENUM_MAP.get(pathArgument.getClass());
index 1afc73a3c8deb04a471eee01b437ffd06ed769f3..dd9e102464550702d24d41b4ff8c523354d44b0c 100644 (file)
@@ -59,14 +59,14 @@ final class ValueTypes {
         throw new UnsupportedOperationException("Utility class");
     }
 
-    public static final byte getSerializableType(Object node) {
-        if(node == null){
+    public static byte getSerializableType(Object node) {
+        if (node == null) {
             return NULL_TYPE;
         }
 
         final Byte type = TYPES.get(node.getClass());
         if (type != null) {
-            if(type == STRING_TYPE && ((String) node).length() >= STRING_BYTES_LENGTH_THRESHOLD ){
+            if (type == STRING_TYPE && ((String) node).length() >= STRING_BYTES_LENGTH_THRESHOLD) {
                 return STRING_BYTES_TYPE;
             }
             return type;
index 259529eaa9b37d8cb50af973e365c093eaac2838..4654ec9cc1832d1b0ba2c8dcdeb91bbc965d02a0 100644 (file)
@@ -26,15 +26,16 @@ public class NormalizedNodeBuilderWrapper {
         this.schemaNode = schemaNode;
     }
 
-    public NormalizedNodeContainerBuilder builder(){
+    @SuppressWarnings("rawtypes")
+    public NormalizedNodeContainerBuilder builder() {
         return builder;
     }
 
-    public QName nodeType(){
+    public QName nodeType() {
         return identifier.getNodeType();
     }
 
-    public YangInstanceIdentifier.PathArgument identifier(){
+    public YangInstanceIdentifier.PathArgument identifier() {
         return identifier;
     }
 
index 91d323ea73b69cb52797b30423bbc3ca54d1d8f2..5363661c0e69518027647ef5c905188ff0d6735c 100644 (file)
@@ -33,8 +33,7 @@ import org.slf4j.LoggerFactory;
 
 /**
  * The NormalizedNodePruner removes all nodes from the input NormalizedNode that do not have a corresponding
- * schema element in the passed in SchemaContext
- *
+ * schema element in the passed in SchemaContext.
  */
 public class NormalizedNodePruner implements NormalizedNodeStreamWriter {
     private static final Logger LOG = LoggerFactory.getLogger(NormalizedNodePruner.class);
@@ -51,19 +50,20 @@ public class NormalizedNodePruner implements NormalizedNodeStreamWriter {
 
     @SuppressWarnings("unchecked")
     @Override
-    public void leafNode(YangInstanceIdentifier.NodeIdentifier nodeIdentifier, Object o) throws IOException, IllegalArgumentException {
+    public void leafNode(YangInstanceIdentifier.NodeIdentifier nodeIdentifier, Object value)
+            throws IOException, IllegalArgumentException {
 
         checkNotSealed();
 
         NormalizedNodeBuilderWrapper parent = stack.peek();
-        LeafNode<Object> leafNode = Builders.leafBuilder().withNodeIdentifier(nodeIdentifier).withValue(o).build();
-        if(parent != null) {
-            if(hasValidSchema(nodeIdentifier.getNodeType(), parent)) {
+        LeafNode<Object> leafNode = Builders.leafBuilder().withNodeIdentifier(nodeIdentifier).withValue(value).build();
+        if (parent != null) {
+            if (hasValidSchema(nodeIdentifier.getNodeType(), parent)) {
                 parent.builder().addChild(leafNode);
             }
         } else {
             // If there's no parent node then this is a stand alone LeafNode.
-            if(nodePathSchemaNode != null) {
+            if (nodePathSchemaNode != null) {
                 this.normalizedNode = leafNode;
             }
 
@@ -72,16 +72,16 @@ public class NormalizedNodePruner implements NormalizedNodeStreamWriter {
     }
 
     @Override
-    public void startLeafSet(YangInstanceIdentifier.NodeIdentifier nodeIdentifier, int i) throws IOException, IllegalArgumentException {
-
+    public void startLeafSet(YangInstanceIdentifier.NodeIdentifier nodeIdentifier, int count)
+            throws IOException, IllegalArgumentException {
         checkNotSealed();
 
         addBuilder(Builders.leafSetBuilder().withNodeIdentifier(nodeIdentifier), nodeIdentifier);
     }
 
     @Override
-    public void startOrderedLeafSet(YangInstanceIdentifier.NodeIdentifier nodeIdentifier, int i) throws IOException, IllegalArgumentException {
-
+    public void startOrderedLeafSet(YangInstanceIdentifier.NodeIdentifier nodeIdentifier, int str)
+            throws IOException, IllegalArgumentException {
         checkNotSealed();
 
         addBuilder(Builders.orderedLeafSetBuilder().withNodeIdentifier(nodeIdentifier), nodeIdentifier);
@@ -89,20 +89,22 @@ public class NormalizedNodePruner implements NormalizedNodeStreamWriter {
 
     @SuppressWarnings({ "unchecked" })
     @Override
-    public void leafSetEntryNode(QName name, Object o) throws IOException, IllegalArgumentException {
+    public void leafSetEntryNode(QName name, Object value) throws IOException, IllegalArgumentException {
         checkNotSealed();
 
         NormalizedNodeBuilderWrapper parent = stack.peek();
-        if(parent != null) {
-            if(hasValidSchema(name, parent)) {
-                parent.builder().addChild(Builders.leafSetEntryBuilder().withValue(o).withNodeIdentifier(
-                        new YangInstanceIdentifier.NodeWithValue<>(parent.nodeType(), o)).build());
+        if (parent != null) {
+            if (hasValidSchema(name, parent)) {
+                parent.builder().addChild(Builders.leafSetEntryBuilder().withValue(value)
+                        .withNodeIdentifier(new YangInstanceIdentifier.NodeWithValue<>(parent.nodeType(), value))
+                        .build());
             }
         } else {
-            // If there's no parent LeafSetNode then this is a stand alone LeafSetEntryNode.
-            if(nodePathSchemaNode != null) {
-                this.normalizedNode = Builders.leafSetEntryBuilder().withValue(o).withNodeIdentifier(
-                        new YangInstanceIdentifier.NodeWithValue<>(name, o)).build();
+            // If there's no parent LeafSetNode then this is a stand alone
+            // LeafSetEntryNode.
+            if (nodePathSchemaNode != null) {
+                this.normalizedNode = Builders.leafSetEntryBuilder().withValue(value).withNodeIdentifier(
+                        new YangInstanceIdentifier.NodeWithValue<>(name, value)).build();
             }
 
             sealed = true;
@@ -110,68 +112,71 @@ public class NormalizedNodePruner implements NormalizedNodeStreamWriter {
     }
 
     @Override
-    public void startContainerNode(YangInstanceIdentifier.NodeIdentifier nodeIdentifier, int i) throws IOException, IllegalArgumentException {
-
+    public void startContainerNode(YangInstanceIdentifier.NodeIdentifier nodeIdentifier, int count)
+            throws IOException, IllegalArgumentException {
         checkNotSealed();
 
         addBuilder(Builders.containerBuilder().withNodeIdentifier(nodeIdentifier), nodeIdentifier);
     }
 
     @Override
-    public void startYangModeledAnyXmlNode(YangInstanceIdentifier.NodeIdentifier nodeIdentifier, int i) throws IOException, IllegalArgumentException {
+    public void startYangModeledAnyXmlNode(YangInstanceIdentifier.NodeIdentifier nodeIdentifier, int count)
+            throws IOException, IllegalArgumentException {
         throw new UnsupportedOperationException("Not implemented yet");
     }
 
     @Override
-    public void startUnkeyedList(YangInstanceIdentifier.NodeIdentifier nodeIdentifier, int i) throws IOException, IllegalArgumentException {
-
+    public void startUnkeyedList(YangInstanceIdentifier.NodeIdentifier nodeIdentifier, int count)
+            throws IOException, IllegalArgumentException {
         checkNotSealed();
 
         addBuilder(Builders.unkeyedListBuilder().withNodeIdentifier(nodeIdentifier), nodeIdentifier);
     }
 
     @Override
-    public void startUnkeyedListItem(YangInstanceIdentifier.NodeIdentifier nodeIdentifier, int i) throws IOException, IllegalStateException {
-
+    public void startUnkeyedListItem(YangInstanceIdentifier.NodeIdentifier nodeIdentifier, int count)
+            throws IOException, IllegalStateException {
         checkNotSealed();
 
         addBuilder(Builders.unkeyedListEntryBuilder().withNodeIdentifier(nodeIdentifier), nodeIdentifier);
     }
 
     @Override
-    public void startMapNode(YangInstanceIdentifier.NodeIdentifier nodeIdentifier, int i) throws IOException, IllegalArgumentException {
-
+    public void startMapNode(YangInstanceIdentifier.NodeIdentifier nodeIdentifier, int count)
+            throws IOException, IllegalArgumentException {
         checkNotSealed();
 
         addBuilder(Builders.mapBuilder().withNodeIdentifier(nodeIdentifier), nodeIdentifier);
     }
 
     @Override
-    public void startMapEntryNode(YangInstanceIdentifier.NodeIdentifierWithPredicates nodeIdentifierWithPredicates, int i) throws IOException, IllegalArgumentException {
-
+    public void startMapEntryNode(YangInstanceIdentifier.NodeIdentifierWithPredicates nodeIdentifierWithPredicates,
+            int count)  throws IOException, IllegalArgumentException {
         checkNotSealed();
 
-        addBuilder(Builders.mapEntryBuilder().withNodeIdentifier(nodeIdentifierWithPredicates), nodeIdentifierWithPredicates);
+        addBuilder(Builders.mapEntryBuilder().withNodeIdentifier(nodeIdentifierWithPredicates),
+                nodeIdentifierWithPredicates);
     }
 
     @Override
-    public void startOrderedMapNode(YangInstanceIdentifier.NodeIdentifier nodeIdentifier, int i) throws IOException, IllegalArgumentException {
-
+    public void startOrderedMapNode(YangInstanceIdentifier.NodeIdentifier nodeIdentifier, int count)
+            throws IOException, IllegalArgumentException {
         checkNotSealed();
 
         addBuilder(Builders.orderedMapBuilder().withNodeIdentifier(nodeIdentifier), nodeIdentifier);
     }
 
     @Override
-    public void startChoiceNode(YangInstanceIdentifier.NodeIdentifier nodeIdentifier, int i) throws IOException, IllegalArgumentException {
-
+    public void startChoiceNode(YangInstanceIdentifier.NodeIdentifier nodeIdentifier, int count)
+            throws IOException, IllegalArgumentException {
         checkNotSealed();
 
         addBuilder(Builders.choiceBuilder().withNodeIdentifier(nodeIdentifier), nodeIdentifier);
     }
 
     @Override
-    public void startAugmentationNode(YangInstanceIdentifier.AugmentationIdentifier augmentationIdentifier) throws IOException, IllegalArgumentException {
+    public void startAugmentationNode(YangInstanceIdentifier.AugmentationIdentifier augmentationIdentifier)
+            throws IOException, IllegalArgumentException {
 
         checkNotSealed();
 
@@ -180,19 +185,20 @@ public class NormalizedNodePruner implements NormalizedNodeStreamWriter {
 
     @SuppressWarnings("unchecked")
     @Override
-    public void anyxmlNode(YangInstanceIdentifier.NodeIdentifier nodeIdentifier, Object o) throws IOException, IllegalArgumentException {
+    public void anyxmlNode(YangInstanceIdentifier.NodeIdentifier nodeIdentifier, Object value)
+            throws IOException, IllegalArgumentException {
         checkNotSealed();
 
         NormalizedNodeBuilderWrapper parent = stack.peek();
-        AnyXmlNode anyXmlNode = Builders.anyXmlBuilder().withNodeIdentifier(nodeIdentifier).
-                withValue((DOMSource) o).build();
-        if(parent != null) {
-            if(hasValidSchema(nodeIdentifier.getNodeType(), parent)) {
+        AnyXmlNode anyXmlNode = Builders.anyXmlBuilder().withNodeIdentifier(nodeIdentifier).withValue((DOMSource) value)
+                .build();
+        if (parent != null) {
+            if (hasValidSchema(nodeIdentifier.getNodeType(), parent)) {
                 parent.builder().addChild(anyXmlNode);
             }
         } else {
             // If there's no parent node then this is a stand alone AnyXmlNode.
-            if(nodePathSchemaNode != null) {
+            if (nodePathSchemaNode != null) {
                 this.normalizedNode = anyXmlNode;
             }
 
@@ -200,27 +206,27 @@ public class NormalizedNodePruner implements NormalizedNodeStreamWriter {
         }
     }
 
+    @SuppressWarnings("unchecked")
     @Override
     public void endNode() throws IOException, IllegalStateException {
-
         checkNotSealed();
 
         NormalizedNodeBuilderWrapper child = stack.pop();
 
         Preconditions.checkState(child != null, "endNode called on an empty stack");
 
-        if(!child.getSchema().isPresent()) {
+        if (!child.getSchema().isPresent()) {
             LOG.debug("Schema not found for {}", child.identifier());
             return;
         }
 
-        NormalizedNode<?,?> normalizedNode = child.builder().build();
+        NormalizedNode<?,?> newNode = child.builder().build();
 
-        if(stack.size() > 0) {
+        if (stack.size() > 0) {
             NormalizedNodeBuilderWrapper parent = stack.peek();
-            parent.builder().addChild(normalizedNode);
+            parent.builder().addChild(newNode);
         } else {
-            this.normalizedNode = normalizedNode;
+            this.normalizedNode = newNode;
             sealed = true;
         }
     }
@@ -235,17 +241,17 @@ public class NormalizedNodePruner implements NormalizedNodeStreamWriter {
 
     }
 
-    public NormalizedNode<?,?> normalizedNode(){
+    public NormalizedNode<?,?> normalizedNode() {
         return normalizedNode;
     }
 
-    private void checkNotSealed(){
+    private void checkNotSealed() {
         Preconditions.checkState(!sealed, "Pruner can be used only once");
     }
 
     private static boolean hasValidSchema(QName name, NormalizedNodeBuilderWrapper parent) {
         boolean valid = parent.getSchema().isPresent() && parent.getSchema().get().getChild(name) != null;
-        if(!valid) {
+        if (!valid) {
             LOG.debug("Schema not found for {}", name);
         }
 
@@ -253,12 +259,12 @@ public class NormalizedNodePruner implements NormalizedNodeStreamWriter {
     }
 
     private NormalizedNodeBuilderWrapper addBuilder(NormalizedNodeContainerBuilder<?,?,?,?> builder,
-            PathArgument identifier){
+            PathArgument identifier) {
         final Optional<DataSchemaContextNode<?>> schemaNode;
         NormalizedNodeBuilderWrapper parent = stack.peek();
-        if(parent == null) {
+        if (parent == null) {
             schemaNode = Optional.fromNullable(nodePathSchemaNode);
-        } else if(parent.getSchema().isPresent()) {
+        } else if (parent.getSchema().isPresent()) {
             schemaNode = Optional.fromNullable(parent.getSchema().get().getChild(identifier));
         } else {
             schemaNode = Optional.absent();
@@ -272,9 +278,9 @@ public class NormalizedNodePruner implements NormalizedNodeStreamWriter {
     private static DataSchemaContextNode<?> findSchemaNodeForNodePath(YangInstanceIdentifier nodePath,
             SchemaContext schemaContext) {
         DataSchemaContextNode<?> schemaNode = DataSchemaContextTree.from(schemaContext).getRoot();
-        for(PathArgument arg : nodePath.getPathArguments()) {
+        for (PathArgument arg : nodePath.getPathArguments()) {
             schemaNode = schemaNode.getChild(arg);
-            if(schemaNode == null) {
+            if (schemaNode == null) {
                 break;
             }
         }
@@ -286,26 +292,26 @@ public class NormalizedNodePruner implements NormalizedNodeStreamWriter {
     static class SimpleStack<E> {
         List<E> stack = new LinkedList<>();
 
-        void push(E element){
+        void push(E element) {
             stack.add(element);
         }
 
-        E pop(){
-            if(size() == 0){
+        E pop() {
+            if (size() == 0) {
                 return null;
             }
             return stack.remove(stack.size() - 1);
         }
 
-        E peek(){
-            if(size() == 0){
+        E peek() {
+            if (size() == 0) {
                 return null;
             }
 
             return stack.get(stack.size() - 1);
         }
 
-        int size(){
+        int size() {
             return stack.size();
         }
     }
index b72ca5800a43b7af12e1f5dfc5d0f81682e21a00..312eeef6d5bf7c53ebf2a1c09886ba6690a37512 100644 (file)
@@ -8,6 +8,12 @@
 
 package org.opendaylight.controller.cluster.datastore.util;
 
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
 import org.opendaylight.controller.cluster.datastore.node.utils.NodeIdentifierFactory;
 import org.opendaylight.controller.cluster.datastore.node.utils.QNameFactory;
 import org.opendaylight.controller.cluster.datastore.node.utils.serialization.PathArgumentSerializer;
@@ -25,17 +31,11 @@ import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeWithV
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
 
 /**
  * This class contains utility methods for converting an MD-SAL
  * YangInstanceIdentifier to and from other representations.
- * <p>
+ * <p/>
  * The representations convered for now are,
  *
  * <ul>
@@ -44,12 +44,10 @@ import java.util.Set;
  * </ul>
  */
 public class InstanceIdentifierUtils {
-
-    protected static final Logger logger = LoggerFactory
-        .getLogger(InstanceIdentifierUtils.class);
+    private static final Logger LOG = LoggerFactory.getLogger(InstanceIdentifierUtils.class);
 
     /**
-     * Convert an MD-SAL YangInstanceIdentifier into a protocol buffer version of it
+     * Convert an MD-SAL YangInstanceIdentifier into a protocol buffer version of it.
      *
      * @param path an MD-SAL YangInstanceIdentifier
      * @return a protocol buffer version of the MD-SAL YangInstanceIdentifier
@@ -65,6 +63,7 @@ public class InstanceIdentifierUtils {
         return toSerializableBuilder(path, context).build();
     }
 
+    @SuppressWarnings("checkstyle:IllegalCatch")
     private static NormalizedNodeMessages.InstanceIdentifier.Builder toSerializableBuilder(
             YangInstanceIdentifier path, QNameSerializationContext context) {
         NormalizedNodeMessages.InstanceIdentifier.Builder builder =
@@ -73,7 +72,7 @@ public class InstanceIdentifierUtils {
         try {
             for (PathArgument pathArgument : path.getPathArguments()) {
                 NormalizedNodeMessages.PathArgument serializablePathArgument;
-                if(context == null) {
+                if (context == null) {
                     String nodeType = "";
                     if (!(pathArgument instanceof AugmentationIdentifier)) {
                         nodeType = pathArgument.getNodeType().toString();
@@ -90,8 +89,8 @@ public class InstanceIdentifierUtils {
 
                 builder.addArguments(serializablePathArgument);
             }
-        } catch(Exception e){
-            logger.error("An exception occurred", e);
+        } catch (Exception e) {
+            LOG.error("An exception occurred", e);
         }
 
         return builder;
@@ -100,7 +99,7 @@ public class InstanceIdentifierUtils {
 
     /**
      * Convert a protocol buffer version of the MD-SAL YangInstanceIdentifier into
-     * the MD-SAL version of the YangInstanceIdentifier
+     * the MD-SAL version of the YangInstanceIdentifier.
      *
      * @param path a protocol buffer version of the MD-SAL YangInstanceIdentifier
      * @return  an MD-SAL YangInstanceIdentifier
@@ -114,8 +113,8 @@ public class InstanceIdentifierUtils {
 
         List<PathArgument> pathArguments = new ArrayList<>();
 
-        for(NormalizedNodeMessages.PathArgument pathArgument : path.getArgumentsList()) {
-            if(context == null || pathArgument.hasType()) {
+        for (NormalizedNodeMessages.PathArgument pathArgument : path.getArgumentsList()) {
+            if (context == null || pathArgument.hasType()) {
                 pathArguments.add(parsePathArgument(pathArgument));
             } else {
                 pathArguments.add(PathArgumentSerializer.deSerialize(context, pathArgument));
@@ -128,8 +127,7 @@ public class InstanceIdentifierUtils {
     /**
      * Take the various attributes of a PathArgument and package them up as
      * protocol buffer attributes.
-     * <p>
-     *
+     * <p/>
      * PathArguments have 4 subtypes and each of the various subtypes have
      * different attributes
      * <ul>
@@ -154,8 +152,6 @@ public class InstanceIdentifierUtils {
      *         an augmentation entry.
      *     </li>
      * </ul>
-     * @param pathArgument
-     * @return
      */
     private static Iterable<? extends NormalizedNodeMessages.Attribute> getPathArgumentAttributes(
         PathArgument pathArgument) {
@@ -188,7 +184,7 @@ public class InstanceIdentifierUtils {
 
             }
 
-        } else if(pathArgument instanceof AugmentationIdentifier) {
+        } else if (pathArgument instanceof AugmentationIdentifier) {
             AugmentationIdentifier identifier = (AugmentationIdentifier) pathArgument;
 
             for (QName key : identifier.getPossibleChildNames()) {
@@ -210,7 +206,7 @@ public class InstanceIdentifierUtils {
 
 
     /**
-     * Parse a protocol buffer PathArgument and return an MD-SAL PathArgument
+     * Parse a protocol buffer PathArgument and return an MD-SAL PathArgument.
      *
      * @param pathArgument protocol buffer PathArgument
      * @return MD-SAL PathArgument
@@ -225,23 +221,23 @@ public class InstanceIdentifierUtils {
 
             return nodeWithValue;
 
-        } else if(NodeIdentifierWithPredicates.class.getSimpleName().equals(pathArgument.getType())){
+        } else if (NodeIdentifierWithPredicates.class.getSimpleName().equals(pathArgument.getType())) {
 
             NodeIdentifierWithPredicates nodeIdentifierWithPredicates =
-                new NodeIdentifierWithPredicates(
-                    QNameFactory.create(pathArgument.getNodeType().getValue()), toAttributesMap(pathArgument.getAttributesList()));
+                    new NodeIdentifierWithPredicates(QNameFactory.create(pathArgument.getNodeType().getValue()),
+                            toAttributesMap(pathArgument.getAttributesList()));
 
             return nodeIdentifierWithPredicates;
 
-        } else if(AugmentationIdentifier.class.getSimpleName().equals(pathArgument.getType())){
+        } else if (AugmentationIdentifier.class.getSimpleName().equals(pathArgument.getType())) {
 
-            Set<QName> qNameSet = new HashSet<>();
+            Set<QName> qnameSet = new HashSet<>();
 
-            for(NormalizedNodeMessages.Attribute attribute : pathArgument.getAttributesList()){
-                qNameSet.add(QNameFactory.create(attribute.getValue()));
+            for (NormalizedNodeMessages.Attribute attribute : pathArgument.getAttributesList()) {
+                qnameSet.add(QNameFactory.create(attribute.getValue()));
             }
 
-            return new AugmentationIdentifier(qNameSet);
+            return new AugmentationIdentifier(qnameSet);
         }
 
         return NodeIdentifierFactory.getArgument(pathArgument.getValue());
@@ -252,7 +248,7 @@ public class InstanceIdentifierUtils {
 
         Map<QName, Object> map = new HashMap<>();
 
-        for(NormalizedNodeMessages.Attribute attribute : attributesList){
+        for (NormalizedNodeMessages.Attribute attribute : attributesList) {
             String name = attribute.getName();
             Object value = parseAttribute(attribute);
 
@@ -263,19 +259,16 @@ public class InstanceIdentifierUtils {
     }
 
     /**
-     * FIXME: This method only covers a subset of values that may go in an InstanceIdentifier
-     *
-     * @param attribute
-     * @return
+     * FIXME: This method only covers a subset of values that may go in an InstanceIdentifier.
      */
-    private static Object parseAttribute(NormalizedNodeMessages.Attribute attribute){
-        if(Short.class.getSimpleName().equals(attribute.getType())) {
+    private static Object parseAttribute(NormalizedNodeMessages.Attribute attribute) {
+        if (Short.class.getSimpleName().equals(attribute.getType())) {
             return Short.parseShort(attribute.getValue());
-        } else if(Long.class.getSimpleName().equals(attribute.getType())){
+        } else if (Long.class.getSimpleName().equals(attribute.getType())) {
             return Long.parseLong(attribute.getValue());
-        } else if(Boolean.class.getSimpleName().equals(attribute.getType())){
+        } else if (Boolean.class.getSimpleName().equals(attribute.getType())) {
             return Boolean.parseBoolean(attribute.getValue());
-        } else if(Integer.class.getSimpleName().equals(attribute.getType())){
+        } else if (Integer.class.getSimpleName().equals(attribute.getType())) {
             return Integer.parseInt(attribute.getValue());
         }
 
index b9ba36943c6d29cebd09b9e4eb3cfe89e143008f..49286799987c446d1b074762fac1f490153e25c8 100644 (file)
@@ -11,9 +11,8 @@ package org.opendaylight.controller.cluster.notifications;
 import java.io.Serializable;
 
 /**
- * Message sent from the listener of Role Change messages to register itself to the Role Change Notifier
- *
- * The Listener could be in a separate ActorSystem and hence this message needs to be Serializable
+ * Message sent from the listener of Role Change messages to register itself to the Role Change Notifier.
+ * The Listener could be in a separate ActorSystem and hence this message needs to be Serializable.
  */
 public class RegisterRoleChangeListener implements Serializable {
     private static final long serialVersionUID = 8370459011119791506L;
index 608130dad2d5ce7e75c4365e4738c674604172f7..eea87ae9d7cf93cfb63bd49e0556323ba0489203 100644 (file)
@@ -11,8 +11,7 @@ package org.opendaylight.controller.cluster.notifications;
 import java.io.Serializable;
 
 /**
- * Reply message sent from a RoleChangeNotifier to the Role Change Listener
- *
+ * Reply message sent from a RoleChangeNotifier to the Role Change Listener.
  * Can be sent to a separate actor system and hence should be made serializable.
  */
 public class RegisterRoleChangeListenerReply implements Serializable {
index 44b8bf4a532771b1f47533f323445fb38c97ee02..370ce1f3bbf00d9731207b28a77e36981bf03450 100644 (file)
@@ -11,17 +11,15 @@ package org.opendaylight.controller.cluster.notifications;
 import java.io.Serializable;
 
 /**
- * Notification message representing a Role change of a cluster member
- *
- * Roles generally are Leader, Follower and Candidate. But can be based on the consensus strategy/implementation
- *
- * The Listener could be in a separate ActorSystem and hence this message needs to be Serializable
+ * Notification message representing a Role change of a cluster member.
+ * Roles generally are Leader, Follower and Candidate. But can be based on the consensus strategy/implementation.
+ * The Listener could be in a separate ActorSystem and hence this message needs to be Serializable.
  */
 public class RoleChangeNotification implements Serializable {
     private static final long serialVersionUID = -2873869509490117116L;
-    private String memberId;
-    private String oldRole;
-    private String newRole;
+    private final String memberId;
+    private final String oldRole;
+    private final String newRole;
 
     public RoleChangeNotification(String memberId, String oldRole, String newRole) {
         this.memberId = memberId;
index 1e07332e514116a970c99439eb2558474d8b296a..c41d707fd86bb77425fb6189d65ed8b079605dc0 100644 (file)
@@ -63,7 +63,7 @@ public class RoleChangeNotifier extends AbstractUntypedActor implements AutoClos
 
             getSender().tell(new RegisterRoleChangeListenerReply(), getSelf());
 
-            if(latestLeaderStateChanged != null) {
+            if (latestLeaderStateChanged != null) {
                 getSender().tell(latestLeaderStateChanged, getSelf());
             }
 
index 6154e1f6595b6fec452d5195981d56267ee1446e..711025bfa9251e3d332adddfef6b5c79b7093ebb 100644 (file)
@@ -10,14 +10,12 @@ package org.opendaylight.controller.cluster.notifications;
 
 /**
  * Role Change message initiated internally from the  Raft Actor when a the behavior/role changes.
- *
  * Since its internal , need not be serialized
- *
  */
 public class RoleChanged {
-    private String memberId;
-    private String oldRole;
-    private String newRole;
+    private final String memberId;
+    private final String oldRole;
+    private final String newRole;
 
     public RoleChanged(String memberId, String oldRole, String newRole) {
         this.memberId = memberId;
@@ -39,10 +37,6 @@ public class RoleChanged {
 
     @Override
     public String toString() {
-        return "RoleChanged{" +
-                "memberId='" + memberId + '\'' +
-                ", oldRole='" + oldRole + '\'' +
-                ", newRole='" + newRole + '\'' +
-                '}';
+        return "RoleChanged [memberId=" + memberId + ", oldRole=" + oldRole + ", newRole=" + newRole + "]";
     }
 }
index bd48f1fd0d9900dbad8a350e8c61a1a6fafd19da..1d0a10345af8cb7f88193d214cf635087e930ed9 100644 (file)
@@ -8,13 +8,10 @@
 
 package org.opendaylight.controller.cluster.raft.protobuff.client.messages;
 
-
-
 /**
  * An instance of a Payload class is meant to be used as the Payload for
  * AppendEntries.
- * <p>
- *
+ * <p/>
  * When an actor which is derived from RaftActor attempts to persistData it
  * must pass an instance of the Payload class. Similarly when state needs to
  * be applied to the derived RaftActor it will be passed an instance of the
index e2a42b2f5e9be8e01a598c9ae0369e0c0008fb2c..3208e390a44104e2c245ca8c47b448bb175611d4 100644 (file)
@@ -38,8 +38,8 @@ public class RemoteSchemaProvider implements SchemaSourceProvider<YangTextSchema
     private static final ExceptionMapper<SchemaSourceException> MAPPER = new ExceptionMapper<SchemaSourceException>(
             "schemaDownload", SchemaSourceException.class) {
         @Override
-        protected SchemaSourceException newWithCause(final String s, final Throwable throwable) {
-            return new SchemaSourceException(s, throwable);
+        protected SchemaSourceException newWithCause(final String message, final Throwable throwable) {
+            return new SchemaSourceException(message, throwable);
         }
     };
 
@@ -57,11 +57,12 @@ public class RemoteSchemaProvider implements SchemaSourceProvider<YangTextSchema
         final SettableFuture<YangTextSchemaSource> res = SettableFuture.create();
         result.onComplete(new OnComplete<YangTextSchemaSourceSerializationProxy>() {
             @Override
-            public void onComplete(Throwable throwable, YangTextSchemaSourceSerializationProxy yangTextSchemaSourceSerializationProxy) {
-                if(yangTextSchemaSourceSerializationProxy != null) {
+            public void onComplete(Throwable throwable,
+                    YangTextSchemaSourceSerializationProxy yangTextSchemaSourceSerializationProxy) {
+                if (yangTextSchemaSourceSerializationProxy != null) {
                     res.set(yangTextSchemaSourceSerializationProxy.getRepresentation());
                 }
-                if(throwable != null) {
+                if (throwable != null) {
                     res.setException(throwable);
                 }
             }
index 0b07eeb19bb049305d2fff05f481daba4ee25bc8..882f2a84c954555f5dbf067dc3086c3132050e22 100644 (file)
@@ -48,7 +48,8 @@ public class RemoteYangTextSourceProviderImpl implements RemoteYangTextSourcePro
         LOG.trace("Sending yang schema source for {}", identifier);
 
         final Promise<YangTextSchemaSourceSerializationProxy> promise = akka.dispatch.Futures.promise();
-        CheckedFuture<YangTextSchemaSource, ?> future = repository.getSchemaSource(identifier, YangTextSchemaSource.class);
+        CheckedFuture<YangTextSchemaSource, ?> future =
+                repository.getSchemaSource(identifier, YangTextSchemaSource.class);
 
         Futures.addCallback(future, new FutureCallback<YangTextSchemaSource>() {
             @Override
@@ -62,9 +63,9 @@ public class RemoteYangTextSourceProviderImpl implements RemoteYangTextSourcePro
             }
 
             @Override
-            public void onFailure(Throwable t) {
-                LOG.warn("Unable to retrieve schema source from provider", t);
-                promise.failure(t);
+            public void onFailure(Throwable failure) {
+                LOG.warn("Unable to retrieve schema source from provider", failure);
+                promise.failure(failure);
             }
         });