Bug 4969: NPE in JSONCodecFactory by attempt to find codec for a leafref
[yangtools.git] / yang / yang-model-util / src / main / java / org / opendaylight / yangtools / yang / model / util / BaseConstraints.java
index 9fe6805c815a3abfd42dca8e452c8f00d8d00bfb..9b904c563e53ac231b881a1ae05c79244b2e3e8c 100644 (file)
@@ -7,28 +7,26 @@
  */
 package org.opendaylight.yangtools.yang.model.util;
 
+import com.google.common.base.Optional;
 import org.opendaylight.yangtools.yang.model.api.type.LengthConstraint;
 import org.opendaylight.yangtools.yang.model.api.type.PatternConstraint;
 import org.opendaylight.yangtools.yang.model.api.type.RangeConstraint;
 
-import com.google.common.base.Optional;
-
 /**
  * Utility class which provides factory methods to construct Constraints.
  *
  * Provides static factory methods which constructs instances of
  * <ul>
- * <li>{@link LengthConstraint} - {@link #lengthConstraint(Number, Number, String, String)}
- * <li>{@link RangeConstraint} - {@link #rangeConstraint(Number, Number, String, String)}
- * <li>{@link PatternConstraint} - {@link #patternConstraint(String, String, String)}
+ * <li>{@link LengthConstraint} - {@link #newLengthConstraint(Number, Number, Optional, Optional)}
+ * <li>{@link RangeConstraint} - {@link #newRangeConstraint(Number, Number, Optional, Optional)}
+ * <li>{@link PatternConstraint} - {@link #newPatternConstraint(String, Optional, Optional)}
  * </ul>
  */
 public final class BaseConstraints {
-
     private BaseConstraints() {
+        throw new UnsupportedOperationException();
     }
 
-
     /**
      * Creates a {@link LengthConstraint}.
      *
@@ -67,18 +65,18 @@ public final class BaseConstraints {
      *
      * @see RangeConstraint
      *
+     * @param <T> Type of constraint
      * @param min value-restricting lower bound value. The value MUST NOT Be null.
      * @param max value-restricting upper bound value. The value MUST NOT Be null.
      * @param description Description associated with constraint. {@link Optional#absent()} if description is undefined.
      * @param reference Reference associated with constraint. {@link Optional#absent()} if reference is undefined.
      * @return Instance of {@link RangeConstraint}
      */
-    public static RangeConstraint newRangeConstraint(final Number min, final Number max, final Optional<String> description,
+    public static <T extends Number> RangeConstraint newRangeConstraint(final T min, final T max, final Optional<String> description,
             final Optional<String> reference) {
         return new RangeConstraintImpl(min, max, description, reference);
     }
 
-
     /**
      * Creates a {@link PatternConstraint}.
      *
@@ -100,83 +98,4 @@ public final class BaseConstraints {
             final Optional<String> reference) {
         return new PatternConstraintImpl(pattern, description, reference);
     }
-
-
-    /**
-     * Creates a {@link LengthConstraint}.
-     *
-     * Creates an instance of Length constraint based on supplied parameters
-     * with additional behaviour:
-     *
-     * <ul>
-     * <li>{@link LengthConstraint#getErrorAppTag()} returns <code>length-out-of-specified-bounds</code>
-     * <li>{@link LengthConstraint#getErrorMessage()} returns <code>The argument is out of bounds &lt;<i>min</i>, <i>max</i> &gt;</code>
-     * </ul>
-     *
-     * @see LengthConstraint
-     *
-     * @param min  length-restricting lower bound value. The value MUST NOT be negative.
-     * @param max length-restricting upper bound value. The value MUST NOT be negative.
-     * @param description Description associated with constraint.
-     * @param reference Reference associated with constraint.
-     * @return Instance of {@link LengthConstraint}
-     * @deprecated Use {@link #newLengthConstraint(Number, Number, Optional, Optional)} instead.
-     */
-    @Deprecated
-    public static LengthConstraint lengthConstraint(final Number min, final Number max, final String description,
-            final String reference) {
-        return newLengthConstraint(min, max, Optional.fromNullable(description), Optional.fromNullable(reference));
-    }
-
-    /**
-     * Creates a {@link RangeConstraint}.
-     *
-     * Creates an instance of Range constraint based on supplied parameters
-     * with additional behaviour:
-     *
-     * <ul>
-     * <li>{@link RangeConstraint#getErrorAppTag()} returns <code>range-out-of-specified-bounds</code>
-     * <li>{@link RangeConstraint#getErrorMessage()} returns <code>The argument is out of bounds &lt;<i>min</i>, <i>max</i> &gt;</code>
-     * </ul>
-     *
-     *
-     * @see RangeConstraint
-     *
-     * @param min value-restricting lower bound value. The value MUST NOT Be null.
-     * @param max value-restricting upper bound value. The value MUST NOT Be null.
-     * @param description Description associated with constraint.
-     * @param reference Reference associated with constraint.
-     * @return Instance of {@link RangeConstraint}
-     * @deprecated Use {@link #newRangeConstraint(Number, Number, Optional, Optional)} instead.
-     */
-    @Deprecated
-    public static RangeConstraint rangeConstraint(final Number min, final Number max, final String description,
-            final String reference) {
-        return newRangeConstraint(min, max, Optional.fromNullable(description), Optional.fromNullable(reference));
-    }
-
-    /**
-     * Creates a {@link PatternConstraint}.
-     *
-     * Creates an instance of Range constraint based on supplied parameters
-     * with additional behaviour:
-     *
-     * <ul>
-     * <li>{@link PatternConstraint#getErrorAppTag()} returns <code>invalid-regular-expression</code>
-     * </ul>
-     *
-     *
-     * @see PatternConstraint
-     *
-     * @param pattern Regular expression, MUST NOT
-     * @param description Description associated with constraint.
-     * @param reference Reference associated with constraint.
-     * @return Instance of {@link PatternConstraint}
-     * @deprecated Use {@link #newPatternConstraint(String, Optional, Optional)} Instead.
-     */
-    @Deprecated
-    public static PatternConstraint patternConstraint(final String pattern, final String description,
-            final String reference) {
-        return newPatternConstraint(pattern, Optional.fromNullable(description), Optional.fromNullable(reference));
-    }
 }