com.univocity.api.common
Class Args

java.lang.Object
  extended by com.univocity.api.common.Args

public class Args
extends Object

Utility class used to validate arguments and configuration options passed to objects in uniVocity's API.

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

Constructor Summary
protected Args()
          Protected to allow subclassing
 
Method Summary
static String decode(Object value)
          Decodes a URL encoded value using UTF-8.
static String decode(Object value, String charsetName)
          Decodes a URL encoded value.
static String decode(String parameterName, Object value, String charsetName)
          Decodes a URL encoded value.
static String encode(Object parameterValue)
          Encodes a value using UTF-8 so it can be used as part of a URL.
static String encode(Object parameterValue, String charsetName)
          Encodes a value so it can be used as part of a URL.
static String encode(String parameterName, Object parameterValue, String charsetName)
          Encodes a value so it can be used as part of a URL.
static boolean equals(Collection<Object[]> c1, Collection<Object[]> c2)
          Determines whether two collections of Object[] contain the same values.
static String guessAndValidateName(String name, File file, String fieldName)
          Attempts to discover the plain name of a given file, without directories or its extension
static boolean isBlank(String s)
          Tests if a given String is null/empty/blank/
static boolean isNotBlank(String s)
          Tests if a given String is not null/empty/blank/
static Calendar isoDateStringToCalendar(String s)
          Converts a yyyy-MM-dd formatted string to a Calendar instance.
static void noBlanks(Object[] o, String fieldName)
          Ensures the elements in a given array are not null/empty/blank.
static
<T> void
noneEmpty(Collection<T> elements, String fieldName)
          Ensures a given collection is not null/empty and doesn't contain null/empty objects or blank Strings
static void notBlank(CharSequence o, String fieldName)
          Ensures a given CharSequence argument is not null/empty/blank
static void notEmpty(char[] field, String fieldName)
          Ensures a given char array argument is not null/empty
static void notEmpty(CharSequence o, String fieldName)
          Ensures a given CharSequence argument is not null/empty
static void notEmpty(Collection<?> field, String fieldName)
          Ensures a given collection is not null/empty
static void notEmpty(int[] field, String fieldName)
          Ensures a given int[] array argument is not null/empty
static
<T> void
notEmpty(T[] sequence, String fieldName)
          Ensures a given array argument is not null/empty and no elements are null/empty
static void notNull(Object o, String fieldName)
          Ensures a given argument is not null.
static void positive(Number o, String fieldName)
          Ensures a given number is positive (and greater than zero).
static void positiveOrZero(Number o, String fieldName)
          Ensures a given number is positive or equal to zero.
static String replaceSystemProperties(String string)
          Replaces system properties between { and } in a given String with the property values, and returns the result.
static void validFile(File file, String fieldName)
          Ensures a given File argument is not null, exists and does not point to a directory
static void validTransactionIsolationLevel(int transactionIsolationLevel)
          Ensures a given SQL isolation level is a valid and known JDBC value that exists int Connection
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Args

protected Args()
Protected to allow subclassing

Method Detail

notNull

public static final void notNull(Object o,
                                 String fieldName)
Ensures a given argument is not null.

Parameters:
o - the object to validate
fieldName - the description of the field

positive

public static final void positive(Number o,
                                  String fieldName)
Ensures a given number is positive (and greater than zero).

Parameters:
o - the number to validate
fieldName - the description of the field

positiveOrZero

public static final void positiveOrZero(Number o,
                                        String fieldName)
Ensures a given number is positive or equal to zero.

Parameters:
o - the number to validate
fieldName - the description of the field

notEmpty

public static <T> void notEmpty(T[] sequence,
                                String fieldName)
Ensures a given array argument is not null/empty and no elements are null/empty

Type Parameters:
T - the type of elements in the array
Parameters:
sequence - the array of objects
fieldName - the description of the field

notEmpty

public static void notEmpty(Collection<?> field,
                            String fieldName)
Ensures a given collection is not null/empty

Parameters:
field - the collection of objects
fieldName - the description of the field

noneEmpty

public static <T> void noneEmpty(Collection<T> elements,
                                 String fieldName)
Ensures a given collection is not null/empty and doesn't contain null/empty objects or blank Strings

Type Parameters:
T - the type of elements in the collection
Parameters:
elements - the collection of objects
fieldName - the description of the field

notEmpty

public static final void notEmpty(int[] field,
                                  String fieldName)
Ensures a given int[] array argument is not null/empty

Parameters:
field - the array of objects
fieldName - the description of the field

notEmpty

public static final void notEmpty(char[] field,
                                  String fieldName)
Ensures a given char array argument is not null/empty

Parameters:
field - the array of objects
fieldName - the description of the field

notEmpty

public static final void notEmpty(CharSequence o,
                                  String fieldName)
Ensures a given CharSequence argument is not null/empty

Parameters:
o - a character sequence
fieldName - the description of the field

notBlank

public static final void notBlank(CharSequence o,
                                  String fieldName)
Ensures a given CharSequence argument is not null/empty/blank

Parameters:
o - a character sequence
fieldName - the description of the field

noBlanks

public static final void noBlanks(Object[] o,
                                  String fieldName)
Ensures the elements in a given array are not null/empty/blank. The array itself can be empty but not null.

Parameters:
o - the array of elements to be validated.
fieldName - description of the array.

validFile

public static final void validFile(File file,
                                   String fieldName)
Ensures a given File argument is not null, exists and does not point to a directory

Parameters:
file - a file
fieldName - the description of the field

validTransactionIsolationLevel

public static final void validTransactionIsolationLevel(int transactionIsolationLevel)
Ensures a given SQL isolation level is a valid and known JDBC value that exists int Connection

Parameters:
transactionIsolationLevel - code of the transaction isolation level

guessAndValidateName

public static final String guessAndValidateName(String name,
                                                File file,
                                                String fieldName)
Attempts to discover the plain name of a given file, without directories or its extension

Parameters:
name - a name if known. Will be returned if provided.
file - a file whose path will be analyzed in order to extract a name from
fieldName - name of field associated with the file name. Used for validation messages only
Returns:
the given name or the file name if possible. If neither can be provided, an IllegalArgumentException will be thrown

isBlank

public static final boolean isBlank(String s)
Tests if a given String is null/empty/blank/

Parameters:
s - the string
Returns:
true if the given String is null, empty or blank, otherwise returns false

isNotBlank

public static final boolean isNotBlank(String s)
Tests if a given String is not null/empty/blank/

Parameters:
s - the string
Returns:
true if the given String is not null, empty or blank, otherwise returns false

replaceSystemProperties

public static final String replaceSystemProperties(String string)
Replaces system properties between { and } in a given String with the property values, and returns the result. Unknown properties won't be replaced.

Parameters:
string - the String with potential system properties.
Returns:
the resulting String with all known system properties replaced.

decode

public static final String decode(Object value)
Decodes a URL encoded value using UTF-8.

Parameters:
value - the value to be decoded.
Returns:
the decoded value.

decode

public static final String decode(Object value,
                                  String charsetName)
Decodes a URL encoded value.

Parameters:
value - the value to be decoded.
charsetName - the charset to use for decoding the given value. If null, then UTF-8 will be used.
Returns:
the decoded value.

decode

public static final String decode(String parameterName,
                                  Object value,
                                  String charsetName)
Decodes a URL encoded value.

Parameters:
parameterName - name of the parameter associated with the value
value - the value to be decoded.
charsetName - the charset to use for decoding the given value. If null, then UTF-8 will be used.
Returns:
the decoded value.

encode

public static final String encode(Object parameterValue)
Encodes a value using UTF-8 so it can be used as part of a URL. If the value is already encoded, its original String representation will be returned.

Parameters:
parameterValue - the value to be encoded.
Returns:
the encoded value.

encode

public static final String encode(Object parameterValue,
                                  String charsetName)
Encodes a value so it can be used as part of a URL. If the value is already encoded, its original String representation will be returned.

Parameters:
parameterValue - the value to be encoded.
charsetName - charset to use for encoding the given value. If null, then UTF-8 will be used.
Returns:
the encoded value.

encode

public static final String encode(String parameterName,
                                  Object parameterValue,
                                  String charsetName)
Encodes a value so it can be used as part of a URL. If the value is already encoded, its original String representation will be returned.

Parameters:
parameterName - name of the parameter associated with the value
parameterValue - the value to be encoded.
charsetName - charset to use for encoding the given value. If null, then UTF-8 will be used.
Returns:
the encoded value.

isoDateStringToCalendar

public static final Calendar isoDateStringToCalendar(String s)
Converts a yyyy-MM-dd formatted string to a Calendar instance.

Parameters:
s - the yyyy-MM-dd formatted string
Returns:
the corresponding Calendar instance

equals

public static boolean equals(Collection<Object[]> c1,
                             Collection<Object[]> c2)
Determines whether two collections of Object[] contain the same values.

Parameters:
c1 - the first collection
c2 - the second collection.
Returns:
true if both collections contain the same values, false otherwise.


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