public class ArgumentUtils
extends java.lang.Object
| Modifier and Type | Field and Description |
|---|---|
static java.lang.String[] |
EMPTY_STRING_ARRAY
An empty String array.
|
| Constructor and Description |
|---|
ArgumentUtils() |
| Modifier and Type | Method and Description |
|---|---|
static java.lang.Object[] |
findMissingElements(java.lang.Object[] array,
java.util.Collection<?> elements)
Searches for elements in a given array and returns the elements not found.
|
static java.lang.Object[] |
findMissingElements(java.lang.Object[] array,
java.lang.Object[] elements)
Searches for elements in a given array and returns the elements not found.
|
static int |
indexOf(java.lang.Object[] array,
java.lang.Object element)
Returns the index of an element in a given array.
|
static int |
indexOf(java.lang.String[] array,
java.lang.String element,
FieldSelector fieldSelector)
Returns the index of a header, when headers are selected using a
FieldSelector. |
static java.io.Reader |
newReader(java.io.File file)
Creates a
Reader for a given a file |
static java.io.Reader |
newReader(java.io.File file,
java.nio.charset.Charset encoding)
Creates a
Reader for a given a file |
static java.io.Reader |
newReader(java.io.File file,
java.lang.String encoding)
Creates a
Reader for a given a file |
static java.io.Reader |
newReader(java.io.InputStream input)
Creates a
Reader from an input stream |
static java.io.Reader |
newReader(java.io.InputStream input,
java.nio.charset.Charset encoding)
Creates a
Reader from an input stream |
static java.io.Reader |
newReader(java.io.InputStream input,
java.lang.String encoding)
Creates a
Reader from an input stream |
static java.io.Writer |
newWriter(java.io.File file)
Creates a
Writer from a file |
static java.io.Writer |
newWriter(java.io.File file,
java.nio.charset.Charset encoding)
Creates a
Writer from a file |
static java.io.Writer |
newWriter(java.io.File file,
java.lang.String encoding)
Creates a
Writer from a file |
static java.io.Writer |
newWriter(java.io.OutputStream output)
Creates a
Writer from an output stream |
static java.io.Writer |
newWriter(java.io.OutputStream output,
java.nio.charset.Charset encoding)
Creates a
Writer from an output stream |
static java.io.Writer |
newWriter(java.io.OutputStream output,
java.lang.String encoding)
Creates a
Writer from an output stream |
static <T> void |
noNulls(java.lang.String argDescription,
T... args)
Throws an IllegalArgumentException if the given array is null,empty, or contains null values
|
static void |
normalize(java.util.Collection<java.lang.String> strings)
Normalizes the Strings in a given array by trimming all elements and converting them to lower case.
|
static java.lang.String |
normalize(java.lang.String string)
Normalizes a given String by trimming whitespaces and converting it to lower case.
|
static java.lang.String[] |
normalize(java.lang.String[] strings)
Normalizes the Strings in a given array by trimming all elements and converting them to lower case.
|
static <T> void |
notEmpty(java.lang.String argDescription,
T... args)
Throws an IllegalArgumentException if the given array is null or empty.
|
static java.lang.String |
restrictContent(int length,
java.lang.CharSequence content) |
static java.lang.String |
restrictContent(int length,
java.lang.Object content) |
private static <T extends java.lang.Exception> |
throwsUnchecked(java.lang.Throwable toThrow) |
static void |
throwUnchecked(java.lang.Throwable error)
Allows rethrowing a checked exception instead of wrapping it into a runtime exception.
|
static java.lang.String[] |
toArray(java.util.List<java.lang.Enum> enums)
Converts a list of enumerations to an array of their
Enum.toString() representation |
static byte[] |
toByteArray(int... ints)
Converts a sequence of int numbers into a byte array.
|
static char[] |
toCharArray(java.util.Collection<java.lang.Character> characters)
Converts any collection of
Character into a char array. |
static int[] |
toIntArray(java.util.Collection<java.lang.Integer> ints)
Converts any collection of
Integer into an int array. |
public static final java.lang.String[] EMPTY_STRING_ARRAY
public static <T> void notEmpty(java.lang.String argDescription,
T... args)
T - Type of arguments to be validatedargDescription - the description of the elementsargs - the elements to be validated.public static <T> void noNulls(java.lang.String argDescription,
T... args)
T - Type of arguments to be validatedargDescription - the description of the elementsargs - the elements to be validated.public static int indexOf(java.lang.String[] array,
java.lang.String element,
FieldSelector fieldSelector)
FieldSelector.array - the element arrayelement - the element to be looked for in the array.fieldSelector - a field selector that indicates which elements of the given array are selected.public static int indexOf(java.lang.Object[] array,
java.lang.Object element)
array - the element arrayelement - the element to be looked for in the array.public static java.lang.Object[] findMissingElements(java.lang.Object[] array,
java.util.Collection<?> elements)
array - An array with elementselements - the elements to be foundpublic static java.lang.Object[] findMissingElements(java.lang.Object[] array,
java.lang.Object[] elements)
array - An array with elementselements - the elements to be foundpublic static java.lang.String[] normalize(java.lang.String[] strings)
strings - a String array with elements to be normalized.public static java.lang.String normalize(java.lang.String string)
string - a String to be normalized.public static void normalize(java.util.Collection<java.lang.String> strings)
strings - a String collection with elements to be normalized. The original contents of the collection will be modified.public static java.io.Writer newWriter(java.io.OutputStream output)
Writer from an output streamoutput - the output streamWriter wrapping the given output streampublic static java.io.Writer newWriter(java.io.OutputStream output,
java.lang.String encoding)
Writer from an output streamoutput - the output streamencoding - the encoding to use when writing to the output streamWriter wrapping the given output streampublic static java.io.Writer newWriter(java.io.OutputStream output,
java.nio.charset.Charset encoding)
Writer from an output streamoutput - the output streamencoding - the encoding to use when writing to the output streamWriter wrapping the given output streampublic static java.io.Writer newWriter(java.io.File file)
Writer from a filefile - the file to be writtenWriter for the given filepublic static java.io.Writer newWriter(java.io.File file,
java.lang.String encoding)
Writer from a filefile - the file to be writtenencoding - the encoding to use when writing to the fileWriter for the given filepublic static java.io.Writer newWriter(java.io.File file,
java.nio.charset.Charset encoding)
Writer from a filefile - the file to be writtenencoding - the encoding to use when writing to the fileWriter for the given filepublic static java.io.Reader newReader(java.io.InputStream input)
Reader from an input streaminput - the input streamReader wrapping the given input streampublic static java.io.Reader newReader(java.io.InputStream input,
java.lang.String encoding)
Reader from an input streaminput - the input streamencoding - the encoding to use when reading from the input streamReader wrapping the given input streampublic static java.io.Reader newReader(java.io.InputStream input,
java.nio.charset.Charset encoding)
Reader from an input streaminput - the input streamencoding - the encoding to use when reading from the input streamReader wrapping the given input streampublic static java.io.Reader newReader(java.io.File file)
Reader for a given a filefile - the file to be readReader for reading the given filepublic static java.io.Reader newReader(java.io.File file,
java.lang.String encoding)
Reader for a given a filefile - the file to be readencoding - the encoding to be used when reading from the fileReader for reading the given filepublic static java.io.Reader newReader(java.io.File file,
java.nio.charset.Charset encoding)
Reader for a given a filefile - the file to be readencoding - the encoding to be used when reading from the fileReader for reading the given filepublic static java.lang.String[] toArray(java.util.List<java.lang.Enum> enums)
Enum.toString() representationenums - a list of enumerations to convertString with the values produced by each element's Enum.toString() method.public static int[] toIntArray(java.util.Collection<java.lang.Integer> ints)
Integer into an int array.ints - a collection of (boxed) integers.int array with the unboxed integer values.public static char[] toCharArray(java.util.Collection<java.lang.Character> characters)
Character into a char array.characters - a collection of (boxed) characters.char array with the unboxed character values.public static java.lang.String restrictContent(int length,
java.lang.CharSequence content)
public static java.lang.String restrictContent(int length,
java.lang.Object content)
public static void throwUnchecked(java.lang.Throwable error)
error - the (potentially checked) exception to the thrown.private static <T extends java.lang.Exception> void throwsUnchecked(java.lang.Throwable toThrow)
throws T extends java.lang.Exception
T extends java.lang.Exceptionpublic static byte[] toByteArray(int... ints)
ints - the integers to be cast to by