public class GeneralUtils extends Object
Modifier and Type | Field and Description |
---|---|
static String |
LINE_SEPARATOR |
Modifier and Type | Method and Description |
---|---|
static <T> T[] |
array(T... values)
Terse (especially as a static import) way to create a T[] literal.
|
static <K> ArrayList<K> |
asList(Collection<K> values)
Creates a new
ArrayList from a collection by building an
enumeration over the collection. |
static <K> HashSet<K> |
asSet(K... values) |
static boolean[] |
booleans(boolean... values)
Terse (especially as a static import) way to create a boolean[] literal.
|
static <T,U> T |
cast(U u)
Type casts from one type to another.
|
static <T> Class<? extends T> |
classForName(String className)
This method returns the correct type as specified by the caller, unlike
Class.forName(String) . |
static int |
compare(int intVal1,
int intVal2)
Compare two ints, according to the standard Comparable interface.
|
static int |
compare(long longVal1,
long longVal2)
Compare two longs, according to the standard Comparable interface.
|
static short |
compare(short shortVal1,
short shortVal2)
Compare two shorts, according to the standard Comparable interface.
|
static int |
compareInts(int intVal1,
int intVal2)
Compare two ints, according to the standard Comparable interface.
|
static int |
compareLongs(long longVal1,
long longVal2)
Compare two longs, according to the standard Comparable interface.
|
static short |
compareShorts(short shortVal1,
short shortVal2)
Compare two shorts, according to the standard Comparable interface.
|
static double[] |
doubles(double... values)
Terse (especially as a static import) way to create a double[] literal.
|
static <T extends Enum<T>> |
enumSet(T... elements)
Terse (especially as a static import) way to create an EnumSet.
|
static float[] |
floats(float... values)
Terse (especially as a static import) way to create a float[] literal.
|
static String |
getWorkingDir()
Returns the directory in which the application was started (this is the
working/current directory).
|
static int |
hashCode(boolean booleanVal)
Get standard Java hashCode for a boolean without the extra object creation.
|
static int |
hashCode(double doubleVal)
Get standard Java hashCode for a float without the extra object creation.
|
static int |
hashCode(float floatVal)
Get standard Java hashCode for a float without the extra object creation.
|
static int |
hashCode(long longVal)
Get standard Java hashCode for a long without the extra object creation.
|
static int[] |
ints(int... values)
Terse (especially as a static import) way to create an int[] literal.
|
static long[] |
longs(long... values)
Terse (especially as a static import) way to create a long[] literal.
|
static <K> ArrayList<K> |
newArrayList()
Creates a new
ArrayList by examining the expected return type. |
static <K> ArrayList<K> |
newArrayList(Collection<? extends K> c)
Creates a new
ArrayList containing the elements of the specified
collection, in order. |
static <K,V> HashMap<K,V> |
newHashMap()
Creates a new
HashMap by examining the expected return type. |
static <K,V> HashMap<K,V> |
newHashMap(Map<? extends K,? extends V> m)
Creates a new
HashMap containing the same mappings as the
specified map. |
static <K> HashSet<K> |
newHashSet()
Creates a new
HashSet by examining the expected return type. |
static <K> HashSet<K> |
newHashSet(Collection<? extends K> c)
Creates a new
HashSet containing the elements of the specified
collection. |
static <K,V> LinkedHashMap<K,V> |
newLinkedHashMap()
Creates a new
LinkedHashMap by examining the expected return type. |
static <K> LinkedHashSet<K> |
newLinkedHashSet()
Creates a new
LinkedHashSet by examining the expected return type. |
static <K> LinkedHashSet<K> |
newLinkedHashSet(Collection<? extends K> c)
Creates a new
LinkedHashSet containing the elements of the specified
collection. |
static <K,V> TreeMap<K,V> |
newTreeMap()
Creates a new
TreeMap by examining the expected return type. |
static <K> TreeSet<K> |
newTreeSet()
Creates a new
TreeSet by examining the expected return type. |
static <K> List<K> |
newUnmodifiableList(Collection<? extends K> c)
Creates a new unmodifiable
List containing the elements of the
specified collection, in order. |
static void |
stringBufferAppend(StringBuffer sb,
String format,
Object... args)
Convenience method for formatting and appending data to an existing StringBuffer.
|
static void |
stringBuilderAppend(StringBuilder sb,
String format,
Object... args)
Convenience method for formatting and appending data to an existing StringBuilder.
|
static BigDecimal |
stripTrailingZeros(BigDecimal value)
Workaround for bug #6480539:
BigDecimal.stripTrailingZeros() has no effect on zero itself ("0.0").
|
public static final String LINE_SEPARATOR
public static BigDecimal stripTrailingZeros(BigDecimal value)
public static int hashCode(long longVal)
Equivalent to (new Long(longVal)).hashCode() in jdk1.6.
longVal
- value for which to compute hashCodepublic static int hashCode(float floatVal)
Equivalent to (new Float(floatVal)).hashCode() in jdk1.6.
floatVal
- value for which to compute hashCodepublic static int hashCode(double doubleVal)
Equivalent to (new Double(doubleVal)).hashCode() in jdk1.6.
doubleVal
- value for which to compute hashCodepublic static int hashCode(boolean booleanVal)
Equivalent to (new Boolean(booleanVal)).hashCode() in jdk1.6.
booleanVal
- value for which to compute hashCodepublic static short compare(short shortVal1, short shortVal2)
shortVal1
- shortVal2
- public static short compareShorts(short shortVal1, short shortVal2)
shortVal1
- shortVal2
- public static int compare(int intVal1, int intVal2)
intVal1
- intVal2
- public static int compareInts(int intVal1, int intVal2)
intVal1
- intVal2
- public static int compare(long longVal1, long longVal2)
longVal1
- longVal2
- public static int compareLongs(long longVal1, long longVal2)
longVal1
- longVal2
- public static <T> Class<? extends T> classForName(String className) throws ClassNotFoundException
Class.forName(String)
.
It also helps localizing the "Type safety" warnings to a single place.ClassNotFoundException
public static String getWorkingDir()
public static <T,U> T cast(U u)
public static final <K> HashSet<K> newHashSet()
HashSet
by examining the expected return type.public static final <K> HashSet<K> newHashSet(Collection<? extends K> c)
HashSet
containing the elements of the specified
collection.HashSet#HashSet(Collection)}
public static final <K> LinkedHashSet<K> newLinkedHashSet()
LinkedHashSet
by examining the expected return type.public static final <K> LinkedHashSet<K> newLinkedHashSet(Collection<? extends K> c)
LinkedHashSet
containing the elements of the specified
collection.LinkedHashSet#LinkedHashSet(Collection)}
public static final <K> TreeSet<K> newTreeSet()
TreeSet
by examining the expected return type.public static final <K,V> HashMap<K,V> newHashMap()
HashMap
by examining the expected return type.public static final <K,V> HashMap<K,V> newHashMap(Map<? extends K,? extends V> m)
HashMap
containing the same mappings as the
specified map.HashMap#HashMap(Map)}
public static final <K,V> LinkedHashMap<K,V> newLinkedHashMap()
LinkedHashMap
by examining the expected return type.public static final <K,V> TreeMap<K,V> newTreeMap()
TreeMap
by examining the expected return type.public static final <K> ArrayList<K> newArrayList()
ArrayList
by examining the expected return type.public static final <K> ArrayList<K> newArrayList(Collection<? extends K> c)
ArrayList
containing the elements of the specified
collection, in order.ArrayList#ArrayList(Collection)}.
public static final <K> List<K> newUnmodifiableList(Collection<? extends K> c)
List
containing the elements of the
specified collection, in order.public static final <K> ArrayList<K> asList(Collection<K> values)
ArrayList
from a collection by building an
enumeration over the collection.public static final <K> HashSet<K> asSet(K... values)
public static int[] ints(int... values)
public static long[] longs(long... values)
public static float[] floats(float... values)
public static double[] doubles(double... values)
public static boolean[] booleans(boolean... values)
public static <T> T[] array(T... values)
public static <T extends Enum<T>> EnumSet<T> enumSet(T... elements)
public static void stringBufferAppend(StringBuffer sb, String format, Object... args)
public static void stringBuilderAppend(StringBuilder sb, String format, Object... args)
Copyright © 2016 Metron, Inc.. All rights reserved.