|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object sk.baka.ambient.commons.MiscUtils
public final class MiscUtils
Miscellaneous utility methods.
Field Summary | |
---|---|
static Object |
NULL
May be used in maps and/or sets which does not support null . |
Method Summary | ||
---|---|---|
static void |
closeQuietly(Closeable c)
Closes the closeable object. |
|
static void |
closeQuietly(ServerSocket socket)
Closes a server socket quietly. |
|
static void |
closeQuietly(Socket socket)
Closes a socket quietly. |
|
static Serializable |
deserialize(byte[] serialized)
Deserializes an object from a byte array. |
|
static Serializable |
deserialize(InputStream stream)
Deserializes an object from an input stream. |
|
static Serializable |
deserializeFromFile(File file)
Deserializes an object from contents of given file. |
|
static String |
emptyIfNull(String str)
Returns given string. |
|
static String |
fixArtistAlbumName(String artistAlbum)
Moves the leading "the" word to the end of given name. |
|
static String |
format(int resId,
Object... args)
Formats given string. |
|
static String |
formatByteLength(long length)
Formats the length and returns it. |
|
static byte[] |
fromHexa(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 List<Class<?>> |
getInterfaces(Class<?> clazz)
Returns all interfaces that given class and all superclasses implements. |
|
static String |
getRFC2822Date(Date date)
Formats given date as a RFC 2822 date. |
|
static String |
getStackTrace(Throwable throwable)
Returns given exception (including its stack trace) as a string. |
|
static int |
hashCode(Object o)
Returns object hash code. |
|
static boolean |
isEmpty(String str)
Checks if given string is empty ( null or zero-sized). |
|
static boolean |
isEmptyOrWhitespace(String str)
Checks if given string is empty or consists of whitespace characters only. |
|
static
|
iterableToList(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 String |
nullIfEmptyOrWhitespace(String str)
If given string is empty, contains spaces only or is null
then null is returned. |
|
static Date |
parseRFC2822Date(String date)
Parses RFC 2822 date. |
|
static void |
serialize(Serializable object,
OutputStream out)
Serializes given object to the output stream. |
|
static byte[] |
serializeToBytes(Serializable object)
Serializes given object to the output stream. |
|
static void |
sysout(String string)
Sysout for the fucking Android. |
|
static String |
toHexa(byte[] array)
Formats each byte in the array in its hexadecimal form and returns it. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final Object NULL
null
.
Method Detail |
---|
public static <T extends Comparable<? super T>> int nullCompare(T o1, T o2, boolean nullFirst)
null
s 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 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 List<Class<?>> getInterfaces(Class<?> clazz)
clazz
- the class to analyze
public static String nullIfEmptyOrWhitespace(String str)
null
then null
is returned.
str
- the string.
null
if one of the above applies.public static String emptyIfNull(String str)
null
then an empty
string is returned.
str
- the string.
null
string.public static boolean isEmptyOrWhitespace(String str)
str
- the string to check.
true
if the string is empty, false
otherwise.public static boolean isEmpty(String str)
null
or zero-sized).
str
- the string to check.
true
if the string is empty, false
otherwise.public static String format(int resId, 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
null
s; false
otherwise.public static Serializable deserializeFromFile(File file) throws IOException
file
- the file to read
IOException
public static Serializable deserialize(InputStream stream) throws IOException
stream
- the stream to read
IOException
public static void serialize(Serializable object, OutputStream out) throws IOException
object
- the object to serializeout
- serialize here
IOException
public static byte[] serializeToBytes(Serializable object)
object
- the object to serialize
public static Serializable deserialize(byte[] serialized)
serialized
- the serialized object form
public static void closeQuietly(Closeable c)
c
- close this closeable. Does nothing if the stream is
null
.public static void closeQuietly(Socket socket)
socket
- the socket to close.public static void closeQuietly(ServerSocket socket)
socket
- the socket to close.public static <T> List<T> iterableToList(Iterable<? extends T> i)
T
- the item typei
- the iterable
null
.public static String formatByteLength(long length)
length
- in bytes
public static String fixArtistAlbumName(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. null
s are handled correctly,
i.e. null
is only equal to null
.
public static int hashCode(Object o)
null
was given.
o
- the object to compute hash code for.
public static Date parseRFC2822Date(String date) throws ParseException
date
- the date to parse.
ParseException
- if parse fails.public static String getRFC2822Date(Date date)
date
- the date to format.
public static String toHexa(byte[] array)
array
- the array to print
public static byte[] fromHexa(String hexaArray)
toHexa(byte[])
back to
the original array.
hexaArray
- the array returned by toHexa(byte[])
.
public static String getStackTrace(Throwable throwable)
throwable
- the throwable.
public static void sysout(String string)
string
- the fucking string.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |