Class Parameters

java.lang.Object
it.tidalwave.util.Parameters

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

    • Parameters

      public Parameters()
  • Method Details

    • r

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

      @CheckForNull public static <T> T find(@Nonnull Class<? extends T> parameterClass, @CheckForNull T defaultOption, @Nonnull Object... parameters) throws 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:
      IllegalArgumentException - if more than a single value is found
    • find

      @Nonnull public static <T> Collection<T> find(@Nonnull Class<? extends T> parameterClass, @Nonnull 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 Object mustNotBeArrayOrCollection(@Nonnull Object object, @Nonnull 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