Package it.tidalwave.util
Class Parameters
java.lang.Object
it.tidalwave.util.Parameters
This class provides a few static utility methods to manipulate arguments to methods.
- Author:
- Fabrizio Giudici
- Status: stable API
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic <T> Collection
<T> Extracts multiple-value parameters of the given type from an array.static <T> T
Extracts a singled-value parameter of the given type from an array.static Object
mustNotBeArrayOrCollection
(Object object, String message) This method is for internal implementation only. Ensures that a given object is neither an array nor a collection.static Collection
<Object> A convenience method for transforming a varargs of objects to aCollection
.
-
Constructor Details
-
Parameters
public Parameters()
-
-
Method Details
-
r
A convenience method for transforming a varargs of objects to aCollection
. It supports concatenating collections: that is, each varargs item that is aCollection
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, anIllegalArgumentException
is thrown.- Type Parameters:
T
- the static type of the parameter- Parameters:
parameterClass
- the dynamic type of the parameterdefaultOption
- the default value of the parameterparameters
- 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 retrieveparameters
- 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 checkmessage
- the message to put in the exception- Returns:
- the object itself for calling this method as a function
-