Added validation of range and length constraints. 62/662/1
authorMartin Vitez <mvitez@cisco.com>
Mon, 17 Jun 2013 13:04:54 +0000 (15:04 +0200)
committerMartin Vitez <mvitez@cisco.com>
Wed, 24 Jul 2013 11:44:53 +0000 (13:44 +0200)
Fixed base range constraints of yang uint built-in types. Made rpc input and output statement optional.
Changed formatting of files to conform new sun_coding_style template. Added more tests.

Signed-off-by: Martin Vitez <mvitez@cisco.com>
yang-model-api/src/main/java/org/opendaylight/controller/yang/model/api/ChoiceNode.java
yang-model-util/src/main/java/org/opendaylight/controller/yang/model/util/AbstractUnsignedInteger.java
yang-model-util/src/main/java/org/opendaylight/controller/yang/model/util/Uint16.java
yang-model-util/src/main/java/org/opendaylight/controller/yang/model/util/Uint32.java
yang-model-util/src/main/java/org/opendaylight/controller/yang/model/util/Uint64.java
yang-model-util/src/main/java/org/opendaylight/controller/yang/model/util/Uint8.java

index b67da660cc0dcca222d7d44ddc380fc091fbbb0d..03a8962d552c26031e51f178e0160c30a77e8d8f 100644 (file)
@@ -19,5 +19,7 @@ public interface ChoiceNode extends DataSchemaNode, AugmentationTarget {
      * @return ChoiceCaseNode objects defined in this node
      */
     Set<ChoiceCaseNode> getCases();
+    
+    String getDefaultCase();
 
 }
index 6d5b5be8a0378dfa27fee06687e6174c860a1078..79b211f263e3fc40415463eb48a9743185d2eba5 100644 (file)
@@ -19,7 +19,7 @@ import org.opendaylight.controller.yang.model.api.type.UnsignedIntegerTypeDefini
  * interface which represents UNSIGNED Integer values defined in Yang language. <br>
  * The integer built-in types in Yang are uint8, uint16, uint32, and uint64.
  * They represent unsigned integers of different sizes:
- *
+ * 
  * <ul>
  * <li>uint8 - represents integer values between 0 and 255, inclusively.</li>
  * <li>uint16 - represents integer values between 0 and 65535, inclusively.</li>
@@ -28,10 +28,10 @@ import org.opendaylight.controller.yang.model.api.type.UnsignedIntegerTypeDefini
  * <li>uint64 - represents integer values between 0 and 18446744073709551615,
  * inclusively.</li>
  * </ul>
- *
+ * 
  */
-public abstract class AbstractUnsignedInteger implements
-        UnsignedIntegerTypeDefinition {
+public abstract class AbstractUnsignedInteger implements UnsignedIntegerTypeDefinition {
+    private static final long MIN_VALUE = 0;
     private final QName name;
     private final SchemaPath path;
     private final String description;
@@ -40,28 +40,25 @@ public abstract class AbstractUnsignedInteger implements
     private final List<RangeConstraint> rangeStatements;
 
     /**
-     *
+     * 
      * @param actualPath
      * @param namespace
      * @param revision
      * @param name
      * @param description
-     * @param minRange
+     * @param MIN_VALUE
      * @param maxRange
      * @param units
      */
-    public AbstractUnsignedInteger(final SchemaPath path, final QName name,
-            final String description, final Number minRange,
+    public AbstractUnsignedInteger(final SchemaPath path, final QName name, final String description,
             final Number maxRange, final String units) {
         this.name = name;
         this.description = description;
         this.path = path;
         this.units = units;
         this.rangeStatements = new ArrayList<RangeConstraint>();
-        final String rangeDescription = "Integer values between " + minRange
-                + " and " + maxRange + ", inclusively.";
-        this.rangeStatements.add(BaseConstraints.rangeConstraint(minRange,
-                maxRange, rangeDescription,
+        final String rangeDescription = "Integer values between " + MIN_VALUE + " and " + maxRange + ", inclusively.";
+        this.rangeStatements.add(BaseConstraints.rangeConstraint(MIN_VALUE, maxRange, rangeDescription,
                 "https://tools.ietf.org/html/rfc6020#section-9.2.4"));
     }
 
@@ -71,8 +68,7 @@ public abstract class AbstractUnsignedInteger implements
      * @param rangeStatements
      * @param units
      */
-    public AbstractUnsignedInteger(final SchemaPath path, final QName name,
-            final String description,
+    public AbstractUnsignedInteger(final SchemaPath path, final QName name, final String description,
             final List<RangeConstraint> rangeStatements, final String units) {
         this.name = name;
         this.description = description;
@@ -125,14 +121,11 @@ public abstract class AbstractUnsignedInteger implements
     public int hashCode() {
         final int prime = 31;
         int result = 1;
-        result = prime * result
-                + ((description == null) ? 0 : description.hashCode());
+        result = prime * result + ((description == null) ? 0 : description.hashCode());
         result = prime * result + ((name == null) ? 0 : name.hashCode());
         result = prime * result + ((path == null) ? 0 : path.hashCode());
-        result = prime * result
-                + ((rangeStatements == null) ? 0 : rangeStatements.hashCode());
-        result = prime * result
-                + ((reference == null) ? 0 : reference.hashCode());
+        result = prime * result + ((rangeStatements == null) ? 0 : rangeStatements.hashCode());
+        result = prime * result + ((reference == null) ? 0 : reference.hashCode());
         result = prime * result + ((units == null) ? 0 : units.hashCode());
         return result;
     }
index 79ae4674b0b48971005c09ad76cad8d528b6a215..6cae33b8f5ae67614f6479b032de10a949f70ead 100644 (file)
@@ -18,13 +18,14 @@ import org.opendaylight.controller.yang.model.api.type.UnsignedIntegerTypeDefini
  *
  */
 public final class Uint16 extends AbstractUnsignedInteger {
+    public static final int MAX_VALUE = 65535;
     private static final QName name = BaseTypes.constructQName("uint16");
     private Integer defaultValue = null;
     private static final String description = "uint16 represents integer values between 0 and 65535, inclusively.";
     private final UnsignedIntegerTypeDefinition baseType;
 
     public Uint16(final SchemaPath path) {
-        super(path, name, description, Short.MIN_VALUE, Short.MAX_VALUE, "");
+        super(path, name, description, MAX_VALUE, "");
         this.baseType = this;
     }
 
@@ -55,8 +56,7 @@ public final class Uint16 extends AbstractUnsignedInteger {
     public int hashCode() {
         final int prime = 31;
         int result = super.hashCode();
-        result = prime * result
-                + ((defaultValue == null) ? 0 : defaultValue.hashCode());
+        result = prime * result + ((defaultValue == null) ? 0 : defaultValue.hashCode());
         return result;
     }
 
@@ -92,4 +92,5 @@ public final class Uint16 extends AbstractUnsignedInteger {
         builder.append("]");
         return builder.toString();
     }
+
 }
index fddf0c4008f9c172486a891f49012ef466412a1b..2a06a603e88c0a559a4d90a0470a282831d83005 100644 (file)
@@ -13,18 +13,18 @@ import org.opendaylight.controller.yang.model.api.type.UnsignedIntegerTypeDefini
 
 /**
  * Implementation of Yang uint32 built-in type. <br>
- * uint32 represents integer values between 0 and 4294967295, inclusively. The
- * Java counterpart of Yang uint32 built-in type is {@link Long}.
+ * uint32 represents integer values between 0 and 4294967295, inclusively.
  *
  */
 public final class Uint32 extends AbstractUnsignedInteger {
+    public static final long MAX_VALUE = 4294967295L;
     private static final QName name = BaseTypes.constructQName("uint32");
     private final Long defaultValue = null;
     private static final String description = "uint32 represents integer values between 0 and 4294967295, inclusively.";
     private final UnsignedIntegerTypeDefinition baseType;
 
     public Uint32(final SchemaPath path) {
-        super(path, name, description, Short.MIN_VALUE, Short.MAX_VALUE, "");
+        super(path, name, description, MAX_VALUE, "");
         this.baseType = this;
     }
 
@@ -55,8 +55,7 @@ public final class Uint32 extends AbstractUnsignedInteger {
     public int hashCode() {
         final int prime = 31;
         int result = super.hashCode();
-        result = prime * result
-                + ((defaultValue == null) ? 0 : defaultValue.hashCode());
+        result = prime * result + ((defaultValue == null) ? 0 : defaultValue.hashCode());
         return result;
     }
 
@@ -92,4 +91,5 @@ public final class Uint32 extends AbstractUnsignedInteger {
         builder.append("]");
         return builder.toString();
     }
+
 }
index 9252c08f577715c6744201d1a1b507373ff6f9e8..e95a6232dbb0102e48db2a9e721c106bc87fe98a 100644 (file)
@@ -21,13 +21,14 @@ import org.opendaylight.controller.yang.model.api.type.UnsignedIntegerTypeDefini
  *
  */
 public final class Uint64 extends AbstractUnsignedInteger {
+    public static final BigInteger MAX_VALUE = new BigInteger("18446744073709551615");
     private static final QName name = BaseTypes.constructQName("uint64");
     private final BigInteger defaultValue = null;
     private static final String description = "uint64 represents integer values between 0 and 18446744073709551615, inclusively.";
     private final UnsignedIntegerTypeDefinition baseType;
 
     public Uint64(final SchemaPath path) {
-        super(path, name, description, Short.MIN_VALUE, Short.MAX_VALUE, "");
+        super(path, name, description, MAX_VALUE, "");
         this.baseType = this;
     }
 
@@ -58,8 +59,7 @@ public final class Uint64 extends AbstractUnsignedInteger {
     public int hashCode() {
         final int prime = 31;
         int result = super.hashCode();
-        result = prime * result
-                + ((defaultValue == null) ? 0 : defaultValue.hashCode());
+        result = prime * result + ((defaultValue == null) ? 0 : defaultValue.hashCode());
         return result;
     }
 
@@ -95,4 +95,5 @@ public final class Uint64 extends AbstractUnsignedInteger {
         builder.append("]");
         return builder.toString();
     }
+
 }
index fa9d35ea291b2635aab13dc8f420df9dde1a4b86..85e7aab15553104d3d79674e1389ea19381ade75 100644 (file)
@@ -1,10 +1,10 @@
 /*
 * Copyright (c) 2013 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
 */
+ * Copyright (c) 2013 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.yang.model.util;
 
 import org.opendaylight.controller.yang.common.QName;
@@ -12,30 +12,28 @@ import org.opendaylight.controller.yang.model.api.SchemaPath;
 import org.opendaylight.controller.yang.model.api.type.UnsignedIntegerTypeDefinition;
 
 /**
- * Implementation of Yang uint8 built-in type.
- * <br>
- * uint8 represents integer values between 0 and 255, inclusively. The Java counterpart of
- * Yang uint8 built-in type is {@link Short}.
+ * Implementation of Yang uint8 built-in type. <br>
+ * uint8 represents integer values between 0 and 255, inclusively.
  *
  * @see AbstractUnsignedInteger
  */
 public final class Uint8 extends AbstractUnsignedInteger {
-
+    public static final int MAX_VALUE = 255;
     private static final QName name = BaseTypes.constructQName("uint8");
     private final Short defaultValue = null;
-    private static final String description =
-            "uint8  represents integer values between 0 and 255, inclusively.";
+    private static final String description = "uint8  represents integer values between 0 and 255, inclusively.";
     private final UnsignedIntegerTypeDefinition baseType;
 
     public Uint8(final SchemaPath path) {
-        super(path, name, description, Short.MIN_VALUE, Short.MAX_VALUE, "");
+        super(path, name, description, MAX_VALUE, "");
         this.baseType = this;
     }
 
     /*
      * (non-Javadoc)
      *
-     * @see org.opendaylight.controller.yang.model.api.TypeDefinition#getBaseType()
+     * @see
+     * org.opendaylight.controller.yang.model.api.TypeDefinition#getBaseType()
      */
     @Override
     public UnsignedIntegerTypeDefinition getBaseType() {
@@ -45,7 +43,9 @@ public final class Uint8 extends AbstractUnsignedInteger {
     /*
      * (non-Javadoc)
      *
-     * @see org.opendaylight.controller.yang.model.api.TypeDefinition#getDefaultValue()
+     * @see
+     * org.opendaylight.controller.yang.model.api.TypeDefinition#getDefaultValue
+     * ()
      */
     @Override
     public Object getDefaultValue() {
@@ -56,8 +56,7 @@ public final class Uint8 extends AbstractUnsignedInteger {
     public int hashCode() {
         final int prime = 31;
         int result = super.hashCode();
-        result = prime * result
-                + ((defaultValue == null) ? 0 : defaultValue.hashCode());
+        result = prime * result + ((defaultValue == null) ? 0 : defaultValue.hashCode());
         return result;
     }
 
@@ -93,4 +92,5 @@ public final class Uint8 extends AbstractUnsignedInteger {
         builder.append("]");
         return builder.toString();
     }
+
 }