Package it.tidalwave.util
Class Parameters
- java.lang.Object
-
- it.tidalwave.util.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<? extends T> parameterClass, java.lang.Object... parameters)
Extracts multiple-value parameters of the given type from an array.static <T> T
find(java.lang.Class<? extends 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... objects)
A convenience method for transforming a varargs of objects to aCollection
.
-
-
-
Method Detail
-
r
@Nonnull public static java.util.Collection<java.lang.Object> r(@Nonnull java.lang.Object... objects)
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 java.lang.Class<? extends 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, 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:
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<? extends 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 retrieveparameters
- 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 checkmessage
- the message to put in the exception- Returns:
- the object itself for calling this method as a function
-
-