Package org.parboiled.common
Class Utils
java.lang.Object
org.parboiled.common.Utils
General utility methods.
-
Field Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic <T> T[]
arrayOf
(T[] firstElements, T lastElement) Joins the given arguments into one array.static <T> T[]
arrayOf
(T firstElement, T... moreElements) Joins the given arguments into one array.static <T> T[]
arrayOf
(T firstElement, T secondElement, T... moreElements) Joins the given arguments into one array.static <T> boolean
equal
(T a, T b) Null enabled equals().static Constructor
findConstructor
(Class<?> type, Object[] args) Finds the constructor of the given class that is compatible with the given arguments.static Class<?>
Get the underlying class for a type, or null if the type is a variable type.getTypeArguments
(Class<?> base, Class<?> implementation) Gets the actual type arguments that are used in a given implementation of a given generic base class or interface.static String
humanize
(long value) Formats the given long value into a human readable notation using the Kilo, Mega, Giga, etc.static boolean
isBoxedType
(Class<?> primitive, Class<?> boxed) Determines if the primitive type is boxed as the boxed typestatic Boolean[]
toObjectArray
(boolean[] array) static Byte[]
toObjectArray
(byte[] array) static Character[]
toObjectArray
(char[] array) static Double[]
toObjectArray
(double[] array) static Float[]
toObjectArray
(float[] array) static Integer[]
toObjectArray
(int[] array) static Long[]
toObjectArray
(long[] array) static Short[]
toObjectArray
(short[] array) static String
Null enabled toString().
-
Field Details
-
EMPTY_CHARACTER_OBJECT_ARRAY
-
EMPTY_INTEGER_OBJECT_ARRAY
-
EMPTY_LONG_OBJECT_ARRAY
-
EMPTY_SHORT_OBJECT_ARRAY
-
EMPTY_BYTE_OBJECT_ARRAY
-
EMPTY_FLOAT_OBJECT_ARRAY
-
EMPTY_DOUBLE_OBJECT_ARRAY
-
EMPTY_BOOLEAN_OBJECT_ARRAY
-
-
Method Details
-
toObjectArray
-
toObjectArray
-
toObjectArray
-
toObjectArray
-
toObjectArray
-
toObjectArray
-
toObjectArray
-
toObjectArray
-
arrayOf
public static <T> T[] arrayOf(T firstElement, T... moreElements) Joins the given arguments into one array.- Parameters:
firstElement
- the first elementmoreElements
- more elements (optional)- Returns:
- a new array containing all arguments.
-
arrayOf
public static <T> T[] arrayOf(T firstElement, T secondElement, T... moreElements) Joins the given arguments into one array.- Parameters:
firstElement
- the first elementsecondElement
- the second elementmoreElements
- more elements (optional)- Returns:
- a new array containing all arguments.
-
arrayOf
public static <T> T[] arrayOf(T[] firstElements, T lastElement) Joins the given arguments into one array.- Parameters:
firstElements
- the first elementslastElement
- the element to append- Returns:
- a new array containing all arguments.
-
toString
Null enabled toString().- Parameters:
obj
- the object- Returns:
- the empty string of obj is null, otherwise obj.toString()
-
equal
public static <T> boolean equal(T a, T b) Null enabled equals().- Parameters:
a
- the first objectb
- the second object- Returns:
- true if both are null or both are equal
-
getTypeArguments
Gets the actual type arguments that are used in a given implementation of a given generic base class or interface. (Based on code copyright 2007 by Ian Robertson).- Parameters:
base
- the generic base class or interfaceimplementation
- the type (potentially) implementing the given base class or interface- Returns:
- a list of the raw classes for the actual type arguments.
-
getClass
Get the underlying class for a type, or null if the type is a variable type. (Copyright 2007 by Ian Robertson).- Parameters:
type
- the type- Returns:
- the underlying class
-
isBoxedType
Determines if the primitive type is boxed as the boxed type- Parameters:
primitive
- the primitive type to check if boxed is the boxed typeboxed
- the possible boxed type of the primitive- Returns:
- true if boxed is the boxed type of primitive, false otherwise.
-
findConstructor
Finds the constructor of the given class that is compatible with the given arguments.- Parameters:
type
- the class to find the constructor ofargs
- the arguments- Returns:
- the constructor
-
humanize
Formats the given long value into a human readable notation using the Kilo, Mega, Giga, etc. abbreviations.- Parameters:
value
- the value to format- Returns:
- the string representation
-