Correct mandatory leaf enforcement
[yangtools.git] / yang / yang-data-impl / src / main / java / org / opendaylight / yangtools / yang / data / impl / schema / NormalizedNodeResult.java
index 76b28e93aaad9a7775068b3a37e383cdf9738ac1..85d41a78a16c5cada404315015a36daba7ad1b0e 100644 (file)
@@ -7,24 +7,22 @@
  */
 package org.opendaylight.yangtools.yang.data.impl.schema;
 
-import com.google.common.base.Preconditions;
 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
 
 /**
- * Client allocated result holder for {@link ImmutableNormalizedNodeStreamWriter}.
- * which produces instance of NormalizedNode.
+ * Client allocated result holder for {@link ImmutableNormalizedNodeStreamWriter} which produces instance
+ * of NormalizedNode.
  *
- * Client may supply result holder to {@link ImmutableNormalizedNodeStreamWriter}
- * which will be once updated, when result is available.
- *
- * This is intended for using {@link ImmutableNormalizedNodeStreamWriter}
- * without supplying builder, so instantiated writer will select
- * correct builder based on first event and sets resulting
- *  {@link NormalizedNode} when end event is invoked for node.
+ * <p>
+ * Client may supply result holder to {@link ImmutableNormalizedNodeStreamWriter} which will be once updated when
+ * the result is available.
  *
+ * <p>
+ * This is intended for using {@link ImmutableNormalizedNodeStreamWriter} without supplying builder, so instantiated
+ * writer will select correct builder based on first event and sets resulting {@link NormalizedNode} when end event is
+ * invoked for node.
  */
 public class NormalizedNodeResult {
-
     private boolean finished = false;
     private NormalizedNode<?,?> result;
 
@@ -33,7 +31,9 @@ public class NormalizedNodeResult {
     }
 
     void setResult(final NormalizedNode<?, ?> result) {
-        Preconditions.checkState(!this.finished, "Result was already set.");
+        if (finished) {
+            throw new ResultAlreadySetException("Normalized Node result was already set.", this.result);
+        }
         this.finished = true;
         this.result = result;
     }
@@ -41,5 +41,4 @@ public class NormalizedNodeResult {
     public boolean isFinished() {
         return finished;
     }
-
 }