com.univocity.parsers.common
Class ArgumentUtils

java.lang.Object
  extended by com.univocity.parsers.common.ArgumentUtils

public class ArgumentUtils
extends Object

An utility class for validating inputs.

Author:
uniVocity Software Pty Ltd - parsers@univocity.com

Field Summary
static String[] EMPTY_STRING_ARRAY
          An empty String array.
 
Constructor Summary
ArgumentUtils()
           
 
Method Summary
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 indexOf(Object[] array, Object element)
          Returns the index of an element in a given array.
static int indexOf(String[] array, String element, FieldSelector fieldSelector)
          Returns the index of a header, when headers are selected using a FieldSelector.
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 void normalize(Collection<String> strings)
          Normalizes the Strings in a given array by trimming all elements and converting them to lower case.
static String normalize(String string)
          Normalizes a given String by trimming whitespaces and converting it to lower case.
static String[] normalize(String[] strings)
          Normalizes the Strings in a given array by trimming all elements and converting them to lower case.
static
<T> void
notEmpty(String argDescription, T... args)
          Throws an IllegalArgumentException if the given array is null or empty.
static String[] toArray(List<Enum> enums)
          Converts a list of enumerations to an array of their Enum.toString() representation
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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

EMPTY_STRING_ARRAY

public static final String[] EMPTY_STRING_ARRAY
An empty String array.

Constructor Detail

ArgumentUtils

public ArgumentUtils()
Method Detail

notEmpty

public static <T> void notEmpty(String argDescription,
                                T... args)
Throws an IllegalArgumentException if the given array is null or empty.

Type Parameters:
T - Type of arguments to be validated
Parameters:
argDescription - the description of the elements
args - the elements to be validated.

noNulls

public static <T> void noNulls(String argDescription,
                               T... args)
Throws an IllegalArgumentException if the given array is null,empty, or contains null values

Type Parameters:
T - Type of arguments to be validated
Parameters:
argDescription - the description of the elements
args - the elements to be validated.

indexOf

public static int indexOf(String[] array,
                          String element,
                          FieldSelector fieldSelector)
Returns the index of a header, when headers are selected using a FieldSelector.

Parameters:
array - the element array
element - the element to be looked for in the array.
fieldSelector - a field selector that indicates which elements of the given array are selected.
Returns:
the index of the given element in the array, or -1 if the element could not be found.

indexOf

public static int indexOf(Object[] array,
                          Object element)
Returns the index of an element in a given array.

Parameters:
array - the element array
element - the element to be looked for in the array.
Returns:
the index of the given element in the array, or -1 if the element could not be found.

findMissingElements

public static Object[] findMissingElements(Object[] array,
                                           Collection<?> elements)
Searches for elements in a given array and returns the elements not found.

Parameters:
array - An array with elements
elements - the elements to be found
Returns:
the elements not found in the array.

findMissingElements

public static Object[] findMissingElements(Object[] array,
                                           Object[] elements)
Searches for elements in a given array and returns the elements not found.

Parameters:
array - An array with elements
elements - the elements to be found
Returns:
the elements not found in the array.

normalize

public static String[] normalize(String[] strings)
Normalizes the Strings in a given array by trimming all elements and converting them to lower case.

Parameters:
strings - a String array with elements to be normalized.
Returns:
the normalized version of the original string array.

normalize

public static String normalize(String string)
Normalizes a given String by trimming whitespaces and converting it to lower case.

Parameters:
string - a String to be normalized.
Returns:
the normalized version of the original String.

normalize

public static void normalize(Collection<String> strings)
Normalizes the Strings in a given array by trimming all elements and converting them to lower case.

Parameters:
strings - a String collection with elements to be normalized. The original contents of the collection will be modified.

newWriter

public static Writer newWriter(OutputStream output)
Creates a Writer from an output stream

Parameters:
output - the output stream
Returns:
Writer wrapping the given output stream

newWriter

public static Writer newWriter(OutputStream output,
                               String encoding)
Creates a Writer from an output stream

Parameters:
output - the output stream
encoding - the encoding to use when writing to the output stream
Returns:
Writer wrapping the given output stream

newWriter

public static Writer newWriter(OutputStream output,
                               Charset encoding)
Creates a Writer from an output stream

Parameters:
output - the output stream
encoding - the encoding to use when writing to the output stream
Returns:
Writer wrapping the given output stream

newWriter

public static Writer newWriter(File file)
Creates a Writer from a file

Parameters:
file - the file to be written
Returns:
Writer for the given file

newWriter

public static Writer newWriter(File file,
                               String encoding)
Creates a Writer from a file

Parameters:
file - the file to be written
encoding - the encoding to use when writing to the file
Returns:
Writer for the given file

newWriter

public static Writer newWriter(File file,
                               Charset encoding)
Creates a Writer from a file

Parameters:
file - the file to be written
encoding - the encoding to use when writing to the file
Returns:
Writer for the given file

newReader

public static Reader newReader(InputStream input)
Creates a Reader from an input stream

Parameters:
input - the input stream
Returns:
a Reader wrapping the given input stream

newReader

public static Reader newReader(InputStream input,
                               String encoding)
Creates a Reader from an input stream

Parameters:
input - the input stream
encoding - the encoding to use when reading from the input stream
Returns:
a Reader wrapping the given input stream

newReader

public static Reader newReader(InputStream input,
                               Charset encoding)
Creates a Reader from an input stream

Parameters:
input - the input stream
encoding - the encoding to use when reading from the input stream
Returns:
a Reader wrapping the given input stream

newReader

public static Reader newReader(File file)
Creates a Reader for a given a file

Parameters:
file - the file to be read
Returns:
a Reader for reading the given file

newReader

public static Reader newReader(File file,
                               String encoding)
Creates a Reader for a given a file

Parameters:
file - the file to be read
encoding - the encoding to be used when reading from the file
Returns:
a Reader for reading the given file

newReader

public static Reader newReader(File file,
                               Charset encoding)
Creates a Reader for a given a file

Parameters:
file - the file to be read
encoding - the encoding to be used when reading from the file
Returns:
a Reader for reading the given file

toArray

public static String[] toArray(List<Enum> enums)
Converts a list of enumerations to an array of their Enum.toString() representation

Parameters:
enums - a list of enumerations to convert
Returns:
an array of String with the values produced by each element's Enum.toString() method.

toIntArray

public static int[] toIntArray(Collection<Integer> ints)
Converts any collection of Integer into an int array.

Parameters:
ints - a collection of (boxed) integers.
Returns:
a primitive int array with the unboxed integer values.

toCharArray

public static char[] toCharArray(Collection<Character> characters)
Converts any collection of Character into a char array.

Parameters:
characters - a collection of (boxed) characters.
Returns:
a primitive char array with the unboxed character values.


Copyright © 2016 uniVocity Software Pty Ltd. All rights reserved.