|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectsk.baka.ambient.commons.MiscUtils
public final class MiscUtils
Miscellaneous utility methods.
| Field Summary | |
|---|---|
static java.lang.Object |
NULL
May be used in maps and/or sets which does not support null. |
| Method Summary | ||
|---|---|---|
static void |
closeQuietly(java.io.Closeable c)
Closes the closeable object. |
|
static void |
closeQuietly(java.net.ServerSocket socket)
Closes a server socket quietly. |
|
static void |
closeQuietly(java.net.Socket socket)
Closes a socket quietly. |
|
static java.io.Serializable |
deserialize(byte[] serialized)
Deserializes an object from a byte array. |
|
static java.io.Serializable |
deserialize(java.io.InputStream stream)
Deserializes an object from an input stream. |
|
static java.io.Serializable |
deserializeFromFile(java.io.File file)
Deserializes an object from contents of given file. |
|
static java.lang.String |
emptyIfNull(java.lang.String str)
Returns given string. |
|
static java.lang.String |
fixArtistAlbumName(java.lang.String artistAlbum)
Moves the leading "the" word to the end of given name. |
|
static java.lang.String |
format(int resId,
java.lang.Object... args)
Formats given string. |
|
static java.lang.String |
formatByteLength(long length)
Formats the length and returns it. |
|
static byte[] |
fromHexa(java.lang.String hexaArray)
Converts hexadecimal string returned by toHexa(byte[]) back to
the original array. |
|
static
|
getIdentity(T object)
Wraps given object to a reference. |
|
static java.util.List<java.lang.Class<?>> |
getInterfaces(java.lang.Class<?> clazz)
Returns all interfaces that given class and all superclasses implements. |
|
static java.lang.String |
getRFC2822Date(java.util.Date date)
Formats given date as a RFC 2822 date. |
|
static java.lang.String |
getStackTrace(java.lang.Throwable throwable)
Returns given exception (including its stack trace) as a string. |
|
static int |
hashCode(java.lang.Object o)
Returns object hash code. |
|
static boolean |
isEmpty(java.lang.String str)
Checks if given string is empty ( null or zero-sized). |
|
static boolean |
isEmptyOrWhitespace(java.lang.String str)
Checks if given string is empty or consists of whitespace characters only. |
|
static
|
iterableToList(java.lang.Iterable<? extends T> i)
Iterates over given iterable and returns its items as a list. |
|
static
|
nextOrThis(T constant,
boolean next)
Returns next enum constant. |
|
static
|
nullCompare(T o1,
T o2,
boolean nullFirst)
Compares two objects. |
|
static
|
nullEquals(T o1,
T o2)
Similar to nullCompare(Comparable, Comparable, boolean), but
uses Object.equals(Object) instead. |
|
static java.lang.String |
nullIfEmptyOrWhitespace(java.lang.String str)
If given string is empty, contains spaces only or is null
then null is returned. |
|
static java.util.Date |
parseRFC2822Date(java.lang.String date)
Parses RFC 2822 date. |
|
static void |
serialize(java.io.Serializable object,
java.io.OutputStream out)
Serializes given object to the output stream. |
|
static byte[] |
serializeToBytes(java.io.Serializable object)
Serializes given object to the output stream. |
|
static void |
sysout(java.lang.Object string)
Sysout for the fucking Android. |
|
static java.lang.String |
toHexa(byte[] array)
Formats each byte in the array in its hexadecimal form and returns it. |
|
static java.lang.Runnable |
toRunnable(java.util.concurrent.Callable<?> callable)
Converts a Callable to a Runnable. |
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final java.lang.Object NULL
null.
| Method Detail |
|---|
public static <T extends java.lang.Comparable<? super T>> int nullCompare(T o1,
T o2,
boolean nullFirst)
nulls correctly. For return
value please see the Comparable.compareTo(Object) contract.
T - the object typeo1 - first objecto2 - second objectnullFirst - if true then null is less than any
non-null object. If false then
null is greater than any non-null object.
Comparable.compareTo(Object) for details.
public static <T extends java.lang.Enum<T>> T nextOrThis(T constant,
boolean next)
T - the enum typeconstant - the constant, must not be null.next - if true then next constant is returned, if
false then simply given constant is returned.
public static java.util.List<java.lang.Class<?>> getInterfaces(java.lang.Class<?> clazz)
clazz - the class to analyze
public static java.lang.String nullIfEmptyOrWhitespace(java.lang.String str)
null
then null is returned.
str - the string.
null if one of the above applies.public static java.lang.String emptyIfNull(java.lang.String str)
null then an empty
string is returned.
str - the string.
null string.public static boolean isEmptyOrWhitespace(java.lang.String str)
str - the string to check.
true if the string is empty, false
otherwise.public static boolean isEmpty(java.lang.String str)
null or zero-sized).
str - the string to check.
true if the string is empty, false
otherwise.
public static java.lang.String format(int resId,
java.lang.Object... args)
Formatter.
resId - formatting string idargs - parameters
public static <T> boolean nullEquals(T o1,
T o2)
nullCompare(Comparable, Comparable, boolean), but
uses Object.equals(Object) instead.
T - the object typeo1 - first objecto2 - second object
true if either o1 is equal to o2, or both are
nulls; false otherwise.
public static java.io.Serializable deserializeFromFile(java.io.File file)
throws java.io.IOException
file - the file to read
java.io.IOException
public static java.io.Serializable deserialize(java.io.InputStream stream)
throws java.io.IOException
stream - the stream to read
java.io.IOException
public static void serialize(java.io.Serializable object,
java.io.OutputStream out)
throws java.io.IOException
object - the object to serializeout - serialize here
java.io.IOExceptionpublic static byte[] serializeToBytes(java.io.Serializable object)
object - the object to serialize
public static java.io.Serializable deserialize(byte[] serialized)
serialized - the serialized object form
public static void closeQuietly(java.io.Closeable c)
c - close this closeable. Does nothing if the stream is
null.public static void closeQuietly(java.net.Socket socket)
socket - the socket to close.public static void closeQuietly(java.net.ServerSocket socket)
socket - the socket to close.public static <T> java.util.List<T> iterableToList(java.lang.Iterable<? extends T> i)
T - the item typei - the iterable
null.public static java.lang.String formatByteLength(long length)
length - in bytes
public static java.lang.String fixArtistAlbumName(java.lang.String artistAlbum)
artistAlbum - an artist/album name
public static <T> Ref<T> getIdentity(T object)
r1.get() == r2.get().
T - the object type.object - the object instance. nulls are handled correctly,
i.e. null is only equal to null.
public static int hashCode(java.lang.Object o)
null was given.
o - the object to compute hash code for.
public static java.util.Date parseRFC2822Date(java.lang.String date)
throws java.text.ParseException
date - the date to parse.
java.text.ParseException - if parse fails.public static java.lang.String getRFC2822Date(java.util.Date date)
date - the date to format.
public static java.lang.String toHexa(byte[] array)
array - the array to print
public static byte[] fromHexa(java.lang.String hexaArray)
toHexa(byte[]) back to
the original array.
hexaArray - the array returned by toHexa(byte[]).
public static java.lang.String getStackTrace(java.lang.Throwable throwable)
throwable - the throwable.
public static void sysout(java.lang.Object string)
string - the fucking string.public static java.lang.Runnable toRunnable(java.util.concurrent.Callable<?> callable)
Callable to a Runnable.
callable - the callable to convert, must not be null.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||