Class Parameters


  • public final class Parameters
    extends java.lang.Object
    This class provides a few static utility methods to manipulate arguments to methods.
    Author:
    Fabrizio Giudici
    Status: stable API
    • Constructor Summary

      Constructors 
      Constructor Description
      Parameters()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static <T> java.util.Collection<T> find​(java.lang.Class<T> parameterClass, java.lang.Object... parameters)
      Extracts multiple-value parameters of the given type from an array.
      static <T> T find​(java.lang.Class<T> parameterClass, T defaultOption, java.lang.Object... parameters)
      Extracts a singled-value parameter of the given type from an array.
      static java.lang.Object mustNotBeArrayOrCollection​(java.lang.Object object, java.lang.String message)
      This method is for internal implementation only. Ensures that a given object is neither an array nor a collection.
      static java.util.Collection<java.lang.Object> r​(java.lang.Object... roles)
      A convenience method for transforming a varargs of roles to a Collection.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • Parameters

        public Parameters()
    • Method Detail

      • r

        @Nonnull
        public static java.util.Collection<java.lang.Object> r​(@Nonnull
                                                               java.lang.Object... roles)
        A convenience method for transforming a varargs of roles to a Collection. It supports concatenating collections: that is, each varargs item that is a Collection is flattened.
        Parameters:
        roles - the roles as varargs
        Returns:
        the roles as collection
        Since:
        3.2-ALPHA-3
      • find

        @CheckForNull
        public static <T> T find​(@Nonnull
                                 java.lang.Class<T> parameterClass,
                                 @CheckForNull
                                 T defaultOption,
                                 @Nonnull
                                 java.lang.Object... parameters)
                          throws java.lang.IllegalArgumentException
        Extracts a singled-value parameter of the given type from an array. If the parameter is not found, the default value is returned. If more than a single parameter is found, an IllegalArgumentException is thrown.
        Type Parameters:
        T - the static type of the parameter
        Parameters:
        parameterClass - the dynamic type of the parameter
        defaultOption - the default value of the parameter
        parameters - the array of parameters
        Returns:
        the value of the parameter
        Throws:
        java.lang.IllegalArgumentException - if more than a single value is found
      • find

        @Nonnull
        public static <T> java.util.Collection<T> find​(@Nonnull
                                                       java.lang.Class<T> parameterClass,
                                                       @Nonnull
                                                       java.lang.Object... parameters)
        Extracts multiple-value parameters of the given type from an array. If the parameter is not found, an empty collection is returned.
        Type Parameters:
        T - the static type of the parameter
        Parameters:
        parameterClass - the class of the parameter to retrieve
        parameters - the array of parameters
        Returns:
        the value of the parameter
      • mustNotBeArrayOrCollection

        @Nonnull
        public static java.lang.Object mustNotBeArrayOrCollection​(@Nonnull
                                                                  java.lang.Object object,
                                                                  @Nonnull
                                                                  java.lang.String message)
        This method is for internal implementation only. Ensures that a given object is neither an array nor a collection.
        Parameters:
        object - the object to check
        message - the message to put in the exception
        Returns:
        the object itself for calling this method as a function