com.ibm.commerce.price.utils

Class Param

  • java.lang.Object
    • com.ibm.commerce.price.utils.Param


  • public final class Param
    extends java.lang.Object
    Param helps check constraints on method and constructor parameters. This is in accordance with the "fail fast" principle so that errors can be found much faster than if invalid parameters and states were ignored.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method and Description
      static <T> void equals(T param, T expected, java.lang.String name)
      Returns whether the given parameter is what is expected.
      static void greaterThanOrEqual(java.lang.Comparable first, java.lang.Comparable second, java.lang.String firstName, java.lang.String secondName)
      Checks that first is greater than or equal to second.
      static void notNull(java.lang.Object param, java.lang.String name)
      Checks that the param is not null.
      static void notNullOrEmpty(java.util.Collection param, java.lang.String name)
      Checks that the param is not null or empty.
      static void notNullOrEmpty(java.lang.String param, java.lang.String name)
      Checks that the param is not null or empty.
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • equals

        public static <T> void equals(T param,
                                      T expected,
                                      java.lang.String name)
                               throws java.lang.IllegalArgumentException
        Returns whether the given parameter is what is expected. This can be used to ensure consistency between objects that must have a common attribute.
        Type Parameters:
        T - The type of the input parameter. This cannot be a Double, Float, or array.
        Parameters:
        param - The value to check. May be null.
        expected - The expected value. May be null.
        name - The name of the parameter in the code. This is used to construct the message for the exception. If null or empty, the message will be malformed.
        Throws:
        java.lang.IllegalArgumentException - If param is not the same as expected, or the type is invalid.
      • greaterThanOrEqual

        public static void greaterThanOrEqual(java.lang.Comparable first,
                                              java.lang.Comparable second,
                                              java.lang.String firstName,
                                              java.lang.String secondName)
                                       throws java.lang.NullPointerException,
                                              java.lang.IllegalArgumentException
        Checks that first is greater than or equal to second. Normally this is used to compare numbers, but can also be used on any Comparable object if that makes sense to check.
        Parameters:
        first - The first value to compare. Cannot be null.
        second - The second value to compare. Cannot be null.
        firstName - The name of the first value in the code. This is used to construct the message for the exception. If null or empty, the message will be malformed.
        secondName - The name of the second value in the code. This is used to construct the message for the exception. If null or empty, the message will be malformed.
        Throws:
        java.lang.NullPointerException - If first or second is null.
        java.lang.IllegalArgumentException - If first is less than second.
      • notNull

        public static void notNull(java.lang.Object param,
                                   java.lang.String name)
                            throws java.lang.NullPointerException
        Checks that the param is not null. If so, a NullPointerException is thrown.
        Parameters:
        param - The parameter value to check. Cannot be null.
        name - The name of the parameter in the code. This is used to construct the message for the exception. If null or empty, the message will be malformed.
        Throws:
        java.lang.NullPointerException - If param is null.
      • notNullOrEmpty

        public static void notNullOrEmpty(java.util.Collection param,
                                          java.lang.String name)
                                   throws java.lang.NullPointerException,
                                          java.lang.IllegalArgumentException
        Checks that the param is not null or empty.
        Parameters:
        param - The parameter value to check. Cannot be null or empty.
        name - The name of the parameter in the code. This is used to construct the message for the exception. If null or empty, the message will be malformed.
        Throws:
        java.lang.NullPointerException - If param is null.
        java.lang.IllegalArgumentException - If param is empty.
      • notNullOrEmpty

        public static void notNullOrEmpty(java.lang.String param,
                                          java.lang.String name)
                                   throws java.lang.NullPointerException,
                                          java.lang.IllegalArgumentException
        Checks that the param is not null or empty.
        Parameters:
        param - The parameter value to check. Cannot be null or empty.
        name - The name of the parameter in the code. This is used to construct the message for the exception. If null or empty, the message will be malformed.
        Throws:
        java.lang.NullPointerException - If param is null.
        java.lang.IllegalArgumentException - If param is empty.