public class ArgumentUtils extends Object
Modifier and Type | Field and Description |
---|---|
static NormalizedString[] |
EMPTY_NORMALIZED_STRING_ARRAY |
static String[] |
EMPTY_STRING_ARRAY
An empty String array.
|
Constructor and Description |
---|
ArgumentUtils() |
Modifier and Type | Method and Description |
---|---|
static String |
displayLineSeparators(String str,
boolean addNewLine)
Displays line separators in a string by replacing all instances
of `\r` and `\n` with `[cr]` and `[lf]`.
|
static <T> T[] |
findDuplicates(T[] array)
Identifies duplicate values in a given array and returns them
|
static Object[] |
findMissingElements(Object[] array,
Collection<?> elements)
Searches for elements in a given array and returns the elements not found.
|
static Object[] |
findMissingElements(Object[] array,
Object[] elements)
Searches for elements in a given array and returns the elements not found.
|
static int[] |
indexesOf(Object[] array,
Object element)
Returns the indexes of an element in a given array.
|
static int |
indexOf(char[] array,
char element,
int from)
Returns the index of a character in a given array.
|
static int |
indexOf(NormalizedString[] array,
NormalizedString element,
FieldSelector fieldSelector)
Returns the index of a header, when headers are selected using a
FieldSelector . |
static int |
indexOf(Object[] array,
Object element)
Returns the index of an element in a given array.
|
static Reader |
newReader(File file)
Creates a
Reader for a given a file |
static Reader |
newReader(File file,
Charset encoding)
Creates a
Reader for a given a file |
static Reader |
newReader(File file,
String encoding)
Creates a
Reader for a given a file |
static Reader |
newReader(InputStream input)
Creates a
Reader from an input stream |
static Reader |
newReader(InputStream input,
Charset encoding)
Creates a
Reader from an input stream |
static Reader |
newReader(InputStream input,
String encoding)
Creates a
Reader from an input stream |
static Writer |
newWriter(File file)
Creates a
Writer from a file |
static Writer |
newWriter(File file,
Charset encoding)
Creates a
Writer from a file |
static Writer |
newWriter(File file,
String encoding)
Creates a
Writer from a file |
static Writer |
newWriter(OutputStream output)
Creates a
Writer from an output stream |
static Writer |
newWriter(OutputStream output,
Charset encoding)
Creates a
Writer from an output stream |
static Writer |
newWriter(OutputStream output,
String encoding)
Creates a
Writer from an output stream |
static <T> void |
noNulls(String argDescription,
T... args)
Throws an IllegalArgumentException if the given array is null,empty, or contains null values
|
static <T> void |
notEmpty(String argDescription,
T... args)
Throws an IllegalArgumentException if the given array is null or empty.
|
static int[] |
removeAll(int[] array,
int e)
Removes all instances of a given element from an int array.
|
static String |
restrictContent(int length,
CharSequence content)
Restricts the length of a given content.
|
static String |
restrictContent(int length,
Object content)
Restricts the length of a given content.
|
static void |
throwUnchecked(Throwable error)
Allows rethrowing a checked exception instead of wrapping it into a runtime exception.
|
static String[] |
toArray(List<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(Collection<Character> characters)
Converts any collection of
Character into a char array. |
static int[] |
toIntArray(Collection<Integer> ints)
Converts any collection of
Integer into an int array. |
static String |
trim(String input,
boolean left,
boolean right)
Removes surrounding spaces from a given
String , from its right or left side, or both. |
public static final String[] EMPTY_STRING_ARRAY
public static final NormalizedString[] EMPTY_NORMALIZED_STRING_ARRAY
public static <T> void notEmpty(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(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(NormalizedString[] array, NormalizedString 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[] indexesOf(Object[] array, Object element)
array
- the element arrayelement
- the element to be looked for in the array.public static int indexOf(Object[] array, Object element)
array
- the element arrayelement
- the element to be looked for in the array.public static int indexOf(char[] array, char element, int from)
array
- the character arrayelement
- the character to be looked for in the array.from
- the starting position of the array from where to start the searchpublic static Object[] findMissingElements(Object[] array, Collection<?> elements)
array
- An array with elementselements
- the elements to be foundpublic static Object[] findMissingElements(Object[] array, Object[] elements)
array
- An array with elementselements
- the elements to be foundpublic static Writer newWriter(OutputStream output)
Writer
from an output streamoutput
- the output streamWriter
wrapping the given output streampublic static Writer newWriter(OutputStream output, 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 Writer newWriter(OutputStream output, 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 Writer newWriter(File file)
Writer
from a filefile
- the file to be writtenWriter
for the given filepublic static Writer newWriter(File file, 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 Writer newWriter(File file, 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 Reader newReader(InputStream input)
Reader
from an input streaminput
- the input streamReader
wrapping the given input streampublic static Reader newReader(InputStream input, 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 Reader newReader(InputStream input, 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 Reader newReader(File file)
Reader
for a given a filefile
- the file to be readReader
for reading the given filepublic static Reader newReader(File file, 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 Reader newReader(File file, 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 String[] toArray(List<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(Collection<Integer> ints)
Integer
into an int
array.ints
- a collection of (boxed) integers.int
array with the unboxed integer values.public static char[] toCharArray(Collection<Character> characters)
Character
into a char array.characters
- a collection of (boxed) characters.char
array with the unboxed character values.public static String restrictContent(int length, CharSequence content)
length
- the maximum length to be displayed. If 0
, the "<omitted>"
string will be returned.content
- the content whose length should be restricted.public static String restrictContent(int length, Object content)
length
- the maximum length to be displayed. If 0
, the "<omitted>"
string will be returned.content
- the content whose length should be restricted.public static void throwUnchecked(Throwable error)
error
- the (potentially checked) exception to the thrown.public static byte[] toByteArray(int... ints)
ints
- the integers to be cast to bypublic static <T> T[] findDuplicates(T[] array)
T
- the type of elements held in the given array.array
- the search arraynull
if the input is null
.public static String trim(String input, boolean left, boolean right)
String
, from its right or left side, or both.input
- the content to trimleft
- flag to indicate whether spaces on the left side of the string should be removed.right
- flag to indicate whether spaces on the right side of the string should be removed.public static String displayLineSeparators(String str, boolean addNewLine)
str
- the string to have its line separators displayedaddNewLine
- flag indicating whether the original `\r` or `\n` characters should be kept in the string.
if true
, `\r` will be replaced by `[cr]\r` for example.public static int[] removeAll(int[] array, int e)
array
- the array to be checkede
- the element to be removedCopyright © 2022 Univocity Software Pty Ltd. All rights reserved.