public final class Utils
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
static class |
Utils.AnalyticsExecutorService
A
ThreadPoolExecutor implementation by Analytics
instances. |
static class |
Utils.AnalyticsThreadFactory |
static class |
Utils.NullableConcurrentHashMap<K,V>
A
ConcurrentHashMap that rejects null keys and values instead of failing. |
Modifier and Type | Field and Description |
---|---|
static boolean |
DEFAULT_COLLECT_DEVICE_ID |
static int |
DEFAULT_FLUSH_INTERVAL |
static int |
DEFAULT_FLUSH_QUEUE_SIZE |
static java.lang.String |
THREAD_PREFIX |
Modifier and Type | Method and Description |
---|---|
static java.io.BufferedReader |
buffer(java.io.InputStream is)
Buffers the given
InputStream . |
static void |
closeQuietly(java.io.Closeable closeable)
Close the given
Closeable . |
static float |
coerceToFloat(java.lang.Object value,
float defaultValue)
Returns the float representation at
value if it exists and is a float or can be
coerced
to a float. |
static void |
createDirectory(java.io.File location)
Ensures that a directory is created in the given location, throws an IOException otherwise.
|
static <T> java.util.Map<java.lang.String,T> |
createMap() |
static java.lang.String |
getDeviceId(android.content.Context context)
Creates a unique device id.
|
static java.lang.String |
getResourceString(android.content.Context context,
java.lang.String key)
Get the string resource for the given key.
|
static android.content.SharedPreferences |
getSegmentSharedPreferences(android.content.Context context)
Returns a shared preferences for storing any library preferences.
|
static <T> T |
getSystemService(android.content.Context context,
java.lang.String serviceConstant)
Returns the system service for the given string.
|
static boolean |
hasFeature(android.content.Context context,
java.lang.String feature)
Returns true if the application has the given feature.
|
static boolean |
hasPermission(android.content.Context context,
java.lang.String permission)
Returns true if the application has the given permission.
|
static boolean |
isConnected(android.content.Context context)
Returns
true if the phone is connected to a network, or if we don't have the enough
permissions. |
static boolean |
isNullOrEmpty(java.lang.CharSequence text)
Returns true if the string is null, or empty (once trimmed).
|
static boolean |
isNullOrEmpty(java.util.Collection collection)
Returns true if the collection or has a size 0.
|
static boolean |
isNullOrEmpty(java.util.Map map)
Returns true if the map is null or empty, false otherwise.
|
static boolean |
isOnClassPath(java.lang.String className)
Return
true if a class with the given name is found. |
static <T> java.util.Set<T> |
newSet(T... values)
Creates a mutable HashSet instance containing the given elements in unspecified order
|
static java.lang.String |
readFully(java.io.BufferedReader reader)
Reads the give
BufferedReader into a String. |
static java.lang.String |
readFully(java.io.InputStream is)
Reads the give
InputStream into a String. |
static java.lang.String |
toISO8601Date(java.util.Date date)
Returns the date as a string formatted with
ISO_8601_DATE_FORMAT . |
static java.util.Date |
toISO8601Date(java.lang.String date)
Returns the string as a date parsed with
ISO_8601_DATE_FORMAT . |
static org.json.JSONObject |
toJsonObject(java.util.Map<java.lang.String,?> map)
Return a copy of the contents of the given map as a
JSONObject . |
static <T> java.util.Map<java.lang.String,T> |
transform(java.util.Map<java.lang.String,T> in,
java.util.Map<java.lang.String,java.lang.String> mapper)
Transforms the given map by replacing the keys mapped by
mapper . |
public static final java.lang.String THREAD_PREFIX
public static final int DEFAULT_FLUSH_INTERVAL
public static final int DEFAULT_FLUSH_QUEUE_SIZE
public static final boolean DEFAULT_COLLECT_DEVICE_ID
public static <T> java.util.Set<T> newSet(T... values)
public static java.lang.String toISO8601Date(java.util.Date date)
ISO_8601_DATE_FORMAT
.public static java.util.Date toISO8601Date(java.lang.String date) throws java.text.ParseException
ISO_8601_DATE_FORMAT
.java.text.ParseException
public static float coerceToFloat(java.lang.Object value, float defaultValue)
value
if it exists and is a float or can be
coerced
to a float. Returns defaultValue
otherwise.public static boolean hasPermission(android.content.Context context, java.lang.String permission)
public static boolean hasFeature(android.content.Context context, java.lang.String feature)
public static <T> T getSystemService(android.content.Context context, java.lang.String serviceConstant)
public static boolean isNullOrEmpty(java.lang.CharSequence text)
public static boolean isNullOrEmpty(java.util.Collection collection)
public static boolean isNullOrEmpty(java.util.Map map)
public static java.lang.String getDeviceId(android.content.Context context)
public static android.content.SharedPreferences getSegmentSharedPreferences(android.content.Context context)
public static java.lang.String getResourceString(android.content.Context context, java.lang.String key)
public static boolean isConnected(android.content.Context context)
true
if the phone is connected to a network, or if we don't have the enough
permissions. Returns false
otherwise.public static boolean isOnClassPath(java.lang.String className)
true
if a class with the given name is found.public static void closeQuietly(java.io.Closeable closeable)
Closeable
. If an exception is thrown during Closeable.close()
,
this will quietly ignore it. Does nothing if closeable
is null
.public static java.io.BufferedReader buffer(java.io.InputStream is)
InputStream
.public static java.lang.String readFully(java.io.InputStream is) throws java.io.IOException
InputStream
into a String.java.io.IOException
public static java.lang.String readFully(java.io.BufferedReader reader) throws java.io.IOException
BufferedReader
into a String.java.io.IOException
public static <T> java.util.Map<java.lang.String,T> transform(java.util.Map<java.lang.String,T> in, java.util.Map<java.lang.String,java.lang.String> mapper)
mapper
. Any keys not in the
mapper preserve their original keys. If a key in the mapper maps to null or a blank string,
that value is dropped.
e.g. transform({a: 1, b: 2, c: 3}, {a: a, c: ""}) -> {$a: 1, b: 2}
- transforms a to $a
- keeps b
- removes cpublic static org.json.JSONObject toJsonObject(java.util.Map<java.lang.String,?> map)
JSONObject
. Instead of failing on
null
values like the JSONObject
map constructor, it cleans them up and
correctly converts them to JSONObject.NULL
.public static <T> java.util.Map<java.lang.String,T> createMap()
public static void createDirectory(java.io.File location) throws java.io.IOException
java.io.IOException