|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.metsci.glimpse.util.GeneralUtils
public class GeneralUtils
This class holds miscellaneous static methods that are simple but broadly useful. In particular, workarounds for Java defects can go here.
Field Summary | |
---|---|
static java.lang.String |
LINE_SEPARATOR
|
Method Summary | ||
---|---|---|
static
|
array(T... values)
Terse (especially as a static import) way to create a T[] literal. |
|
static
|
asList(java.util.Collection<K> values)
Creates a new ArrayList from a collection by building an
enumeration over the collection. |
|
static
|
asSet(K... values)
|
|
static boolean[] |
booleans(boolean... values)
Terse (especially as a static import) way to create a boolean[] literal. |
|
static
|
cast(U u)
Type casts from one type to another. |
|
static
|
classForName(java.lang.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
|
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 java.lang.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
|
newArrayList()
Creates a new ArrayList by examining the expected return type. |
|
static
|
newArrayList(java.util.Collection<? extends K> c)
Creates a new ArrayList containing the elements of the specified
collection, in order. |
|
static
|
newHashMap()
Creates a new HashMap by examining the expected return type. |
|
static
|
newHashMap(java.util.Map<? extends K,? extends V> m)
Creates a new HashMap containing the same mappings as the
specified map. |
|
static
|
newHashSet()
Creates a new HashSet by examining the expected return type. |
|
static
|
newHashSet(java.util.Collection<? extends K> c)
Creates a new HashSet containing the elements of the specified
collection. |
|
static
|
newLinkedHashMap()
Creates a new LinkedHashMap by examining the expected return type. |
|
static
|
newTreeMap()
Creates a new TreeMap by examining the expected return type. |
|
static
|
newTreeSet()
Creates a new TreeSet by examining the expected return type. |
|
static
|
newUnmodifiableList(java.util.Collection<? extends K> c)
Creates a new unmodifiable List containing the elements of the
specified collection, in order. |
|
static void |
stringBufferAppend(java.lang.StringBuffer sb,
java.lang.String format,
java.lang.Object... args)
Convenience method for formatting and appending data to an existing StringBuffer. |
|
static void |
stringBuilderAppend(java.lang.StringBuilder sb,
java.lang.String format,
java.lang.Object... args)
Convenience method for formatting and appending data to an existing StringBuilder. |
|
static java.math.BigDecimal |
stripTrailingZeros(java.math.BigDecimal value)
Workaround for bug #6480539: BigDecimal.stripTrailingZeros() has no effect on zero itself ("0.0"). |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final java.lang.String LINE_SEPARATOR
Method Detail |
---|
public static java.math.BigDecimal stripTrailingZeros(java.math.BigDecimal value)
public static int hashCode(long longVal)
Equivalent to (new Long(longVal)).hashCode() in jdk1.6.
longVal
- value for which to compute hashCode
public static int hashCode(float floatVal)
Equivalent to (new Float(floatVal)).hashCode() in jdk1.6.
floatVal
- value for which to compute hashCode
public static int hashCode(double doubleVal)
Equivalent to (new Double(doubleVal)).hashCode() in jdk1.6.
doubleVal
- value for which to compute hashCode
public static int hashCode(boolean booleanVal)
Equivalent to (new Boolean(booleanVal)).hashCode() in jdk1.6.
booleanVal
- value for which to compute hashCode
public 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> java.lang.Class<? extends T> classForName(java.lang.String className) throws java.lang.ClassNotFoundException
Class.forName(String)
.
It also helps localizing the "Type safety" warnings to a single place.
java.lang.ClassNotFoundException
public static java.lang.String getWorkingDir()
public static <T,U> T cast(U u)
public static final <K> java.util.HashSet<K> newHashSet()
HashSet
by examining the expected return type.
public static final <K> java.util.HashSet<K> newHashSet(java.util.Collection<? extends K> c)
HashSet
containing the elements of the specified
collection.
HashSet#HashSet(Collection)}
public static final <K> java.util.TreeSet<K> newTreeSet()
TreeSet
by examining the expected return type.
public static final <K,V> java.util.HashMap<K,V> newHashMap()
HashMap
by examining the expected return type.
public static final <K,V> java.util.HashMap<K,V> newHashMap(java.util.Map<? extends K,? extends V> m)
HashMap
containing the same mappings as the
specified map.
HashMap#HashMap(Map)}
public static final <K,V> java.util.LinkedHashMap<K,V> newLinkedHashMap()
LinkedHashMap
by examining the expected return type.
public static final <K,V> java.util.TreeMap<K,V> newTreeMap()
TreeMap
by examining the expected return type.
public static final <K> java.util.ArrayList<K> newArrayList()
ArrayList
by examining the expected return type.
public static final <K> java.util.ArrayList<K> newArrayList(java.util.Collection<? extends K> c)
ArrayList
containing the elements of the specified
collection, in order.
ArrayList#ArrayList(Collection)}.
public static final <K> java.util.List<K> newUnmodifiableList(java.util.Collection<? extends K> c)
List
containing the elements of the
specified collection, in order.
public static final <K> java.util.ArrayList<K> asList(java.util.Collection<K> values)
ArrayList
from a collection by building an
enumeration over the collection.
public static final <K> java.util.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 java.lang.Enum<T>> java.util.EnumSet<T> enumSet(T... elements)
public static void stringBufferAppend(java.lang.StringBuffer sb, java.lang.String format, java.lang.Object... args)
public static void stringBuilderAppend(java.lang.StringBuilder sb, java.lang.String format, java.lang.Object... args)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |