public class BasicUtils
extends java.lang.Object
judgeNotNull(String, String...)
getVersionName(android.content.Context)
getVersionCode(android.content.Context)
iterateHashMap(java.util.HashMap)
iterateListHashMap(java.util.List)
sendIntent(android.content.Context, Class)
sendIntent(android.content.Context, Class, String, android.os.Parcelable)
getSharedPreferences(android.content.Context, String, String)
putSharedPreferences(android.content.Context, String, String, String)
构造器和说明 |
---|
BasicUtils() |
限定符和类型 | 方法和说明 |
---|---|
static <V> int |
compare(V v1,
V v2)
Compare two object
if v1 > v2 return 1
if v1 is not null, v2 is null return 1
if v1 = v2, return 0
if v1 is null, v2 is null return 0
if v1 < v2, return -1
if v1 is null, v2 is not null return -1
return v1.
|
static java.lang.String |
formatNumber(int num,
java.lang.String formatAs)
Format the int number as your want
|
static java.lang.String |
getSharedPreferences(android.content.Context context,
java.lang.String fileName,
java.lang.String parameterName)
Retrieve a String value from the preferences.
|
static java.lang.String |
getSharedPreferences(android.content.Context context,
java.lang.String fileName,
java.lang.String parameterName,
java.lang.String otherDefaultReturns)
|
static int |
getVersionCode(android.content.Context context)
get the version code which defines in AndroidManifest.xml
|
static java.lang.String |
getVersionName(android.content.Context context)
get the version name which defines in AndroidManifest.xml
|
static boolean |
isServiceRunning(android.content.Context context,
java.lang.Class<?> cls)
Check if the service is running
|
static void |
iterateHashMap(java.util.HashMap<java.lang.String,java.lang.Object> hashMap)
Print all items of HashMap
|
static void |
iterateHashMapConcurrent(java.util.HashMap<java.lang.String,java.lang.Object> hashMap)
Print all items of HashMap,avoid ConcurrentModificationExceptions
|
static void |
iterateListHashMap(java.util.List list) |
static boolean |
judgeNotNull(byte[] bytes)
Judge if a variable of byte[] is not null and the length of it is above 1
|
static boolean |
judgeNotNull(java.util.List list)
Judge if the size of a list is above 1
|
static boolean |
judgeNotNull(java.util.List list,
java.util.List... lists) |
static boolean |
judgeNotNull(java.util.Map map)
Judge if the size of a map is above 1
|
static boolean |
judgeNotNull(java.lang.Object object)
Judge if the Object is null
|
static boolean |
judgeNotNull(java.lang.Object object,
java.lang.Object... objects)
Judge if the Objects are all defined.
|
static boolean |
judgeNotNull(java.lang.String string) |
static boolean |
judgeNotNull(java.lang.String string,
java.lang.String... strings)
Judge if a variable of String or String[] is null or ""
|
static void |
putSharedPreferences(android.content.Context context,
java.lang.String fileName,
java.util.HashMap<java.lang.String,java.lang.String> hashMap)
Set a String value in the preferences editor with a HashMap
|
static void |
putSharedPreferences(android.content.Context context,
java.lang.String fileName,
java.lang.String parameterName,
java.lang.String parameterValue)
Set a String value in the preferences editor, to be written back once commit() or apply() are called.
|
static void |
sendIntent(android.content.Context context,
java.lang.Class classes)
Launch a new activity.
|
static void |
sendIntent(android.content.Context context,
java.lang.Class classes,
java.lang.String key,
java.util.ArrayList<? extends android.os.Parcelable> value)
Launch a new activity with ArrayList data.
|
static void |
sendIntent(android.content.Context context,
java.lang.Class classes,
java.lang.String key,
java.util.ArrayList<? extends android.os.Parcelable> value,
java.lang.String anotherKey,
java.lang.String anotherValue)
Launch a new activity with one ArrayList data and one pair of String data.
|
static void |
sendIntent(android.content.Context context,
java.lang.Class classes,
java.lang.String key,
android.os.Parcelable value)
Launch a new activity with one Parcelable data.
|
static void |
sendIntent(android.content.Context context,
java.lang.Class classes,
java.lang.String key,
java.lang.String value)
Launch a new activity with one pair of extended String type data.
|
static void |
sendIntent(android.content.Context context,
java.lang.Class classes,
java.lang.String key,
java.lang.String value,
java.lang.String anotherKey,
java.lang.String anotherValue)
Launch a new activity with two pairs of extended String type data.
|
public static void iterateHashMap(java.util.HashMap<java.lang.String,java.lang.Object> hashMap)
hashMap
- public static void iterateHashMapConcurrent(java.util.HashMap<java.lang.String,java.lang.Object> hashMap)
hashMap
- public static void iterateListHashMap(java.util.List list)
public static java.lang.String getVersionName(android.content.Context context)
context
- public static int getVersionCode(android.content.Context context)
context
- public static java.lang.String formatNumber(int num, java.lang.String formatAs) throws java.lang.Exception
num
- formatAs
- java.lang.Exception
public static void sendIntent(android.content.Context context, java.lang.Class classes)
context
- classes
- public static void sendIntent(android.content.Context context, java.lang.Class classes, java.lang.String key, java.lang.String value, java.lang.String anotherKey, java.lang.String anotherValue)
context
- classes
- key
- value
- anotherKey
- anotherValue
- public static void sendIntent(android.content.Context context, java.lang.Class classes, java.lang.String key, java.lang.String value)
context
- classes
- key
- value
- public static void sendIntent(android.content.Context context, java.lang.Class classes, java.lang.String key, android.os.Parcelable value)
context
- classes
- key
- value
- public static void sendIntent(android.content.Context context, java.lang.Class classes, java.lang.String key, java.util.ArrayList<? extends android.os.Parcelable> value)
context
- classes
- key
- value
- public static void sendIntent(android.content.Context context, java.lang.Class classes, java.lang.String key, java.util.ArrayList<? extends android.os.Parcelable> value, java.lang.String anotherKey, java.lang.String anotherValue)
context
- classes
- key
- value
- anotherKey
- anotherValue
- public static java.lang.String getSharedPreferences(android.content.Context context, java.lang.String fileName, java.lang.String parameterName) throws java.lang.ClassCastException
context
- fileName
- parameterName
- java.lang.ClassCastException
- Throws ClassCastException if there is a preference with this name that is not a String.public static java.lang.String getSharedPreferences(android.content.Context context, java.lang.String fileName, java.lang.String parameterName, java.lang.String otherDefaultReturns)
context
- fileName
- parameterName
- otherDefaultReturns
- public static void putSharedPreferences(android.content.Context context, java.lang.String fileName, java.lang.String parameterName, java.lang.String parameterValue)
context
- fileName
- parameterName
- parameterValue
- public static void putSharedPreferences(android.content.Context context, java.lang.String fileName, java.util.HashMap<java.lang.String,java.lang.String> hashMap)
context
- fileName
- hashMap
- public static boolean judgeNotNull(java.lang.String string)
string
- judgeNotNull(String, String...)
public static boolean judgeNotNull(java.lang.String string, java.lang.String... strings)
string
- strings
- public static boolean judgeNotNull(byte[] bytes)
bytes
- public static boolean judgeNotNull(java.util.Map map)
map
- public static boolean judgeNotNull(java.util.List list)
list
- public static boolean judgeNotNull(java.util.List list, java.util.List... lists)
list
- lists
- judgeNotNull(java.util.List)
public static boolean judgeNotNull(java.lang.Object object)
object
- public static boolean judgeNotNull(java.lang.Object object, java.lang.Object... objects)
object
- objects
- public static boolean isServiceRunning(android.content.Context context, java.lang.Class<?> cls)
context
- cls
- public static <V> int compare(V v1, V v2)
Comparable.compareTo(Object)
v1
- v2
-