public final class Utils extends Object
Modifier and Type | Field and Description |
---|---|
static String |
APP_LOGGER_NAME
Name of the logger to measure performances "fr.cnes.doi.logging.app".
|
static Object[] |
EMPTY_OBJECT_ARRAY
An empty immutable
Object array. |
static String |
HTTP_LOGGER_NAME
Name of the logger for http requests and answers
"fr.cnes.doi.logging.api".
|
static String |
SECURITY_LOGGER_NAME
Name of the logger to measure performances
"fr.cnes.doi.logging.security".
|
static String |
SHELL_LOGGER_NAME
Name of the logger in console without date.
|
Modifier | Constructor and Description |
---|---|
private |
Utils()
"Static" class cannot be instantiated
|
Modifier and Type | Method and Description |
---|---|
static <T,E> Set<T> |
getKeysByValue(Map<T,E> map,
E value)
Returns the keys related to a value within a map.
|
static int |
getLength(Object array)
Returns the length of the specified array.
|
static boolean |
isEmpty(CharSequence charSeq)
Checks whether the char sequence is empty.
|
static boolean |
isEmpty(Object[] array)
Checks if an array of Objects is empty or
null . |
static boolean |
isNotEmpty(CharSequence charSeq)
Checks whether the char sequence is not empty.
|
static Object[] |
nullToEmpty(Object[] array)
Defensive programming technique to change a
null reference to an
empty one. |
static <T> T[] |
nullToEmpty(T[] array,
Class<T[]> type)
Defensive programming technique to change a
null reference to an
empty one. |
static String |
transformPasswordToStars(String password)
Transform password to stars
|
public static final Object[] EMPTY_OBJECT_ARRAY
Object
array.public static final String SHELL_LOGGER_NAME
public static final String HTTP_LOGGER_NAME
public static final String APP_LOGGER_NAME
public static final String SECURITY_LOGGER_NAME
public static boolean isEmpty(CharSequence charSeq)
charSeq
- the char sequencepublic static boolean isNotEmpty(CharSequence charSeq)
charSeq
- the char sequencepublic static <T,E> Set<T> getKeysByValue(Map<T,E> map, E value)
T
- the type of the keyE
- the type of the valuemap
- mapvalue
- value to searchpublic static <T> T[] nullToEmpty(T[] array, Class<T[]> type) throws IllegalArgumentException
Defensive programming technique to change a null
reference to an
empty one.
This method returns an empty array for a null
input array.
T
- the class typearray
- the array to check for null
or emptytype
- the class representation of the desired arraypublic static
empty array if null
IllegalArgumentException
- if the type argument is nullpublic static Object[] nullToEmpty(Object[] array)
Defensive programming technique to change a null
reference to an
empty one.
This method returns an empty array for a null
input array.
As a memory optimizing technique an empty array passed in will be
overridden with the empty public static
references in this class.
array
- the array to check for null
or emptypublic static
empty array if null
or empty inputpublic static boolean isEmpty(Object[] array)
Checks if an array of Objects is empty or null
.
array
- the array to testtrue
if the array is empty or null
public static int getLength(Object array) throws IllegalArgumentException
Returns the length of the specified array. This method can deal with
Object
arrays and with primitive arrays.
If the input array is null
, 0
is returned.
Utils.getLength(null) = 0 Utils.getLength([]) = 0 Utils.getLength([null]) = 1 Utils.getLength([true, false]) = 2 Utils.getLength([1, 2, 3]) = 3 Utils.getLength(["a", "b", "c"]) = 3
array
- the array to retrieve the length from, may be null0
if the array is
null
IllegalArgumentException
- if the object argument is not an array.Copyright © 2017–2020 CNES. All rights reserved.