Package it.tidalwave.util
Class Parameters
- java.lang.Object
-
- it.tidalwave.util.Parameters
-
public final class Parameters extends java.lang.ObjectThis 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,O>
java.util.Collection<T>find(java.lang.Class<T> parameterClass, O... parameters)Extracts multiple-value parameters of the given type from an array.static <T,O>
Tfind(java.lang.Class<T> parameterClass, T defaultOption, O... parameters)Extracts a singled-value parameter of the given type from an array.static java.lang.ObjectmustNotBeArrayOrCollection(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 aCollection.
-
-
-
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 aCollection. It supports concatenating collections: that is, each varargs item that is aCollectionis flattened.- Parameters:
roles- the roles as varargs- Returns:
- the roles as collection
- Since:
- 3.2-ALPHA-3
-
find
@CheckForNull public static <T,O> T find(@Nonnull java.lang.Class<T> parameterClass, @CheckForNull T defaultOption, @Nonnull O... parameters) throws java.lang.IllegalArgumentExceptionExtracts 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, anIllegalArgumentExceptionis thrown.- Type Parameters:
T- the static type of the parameterO- ?- 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,O> java.util.Collection<T> find(@Nonnull java.lang.Class<T> parameterClass, @Nonnull O... 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 parameterO- ?- 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
-
-