public class Utils
extends java.lang.Object
Constructor and Description |
---|
Utils() |
Modifier and Type | Method and Description |
---|---|
static int |
arrayAverage(int[] array)
Computes the average of the given integer array
|
static void |
askPermissionsAtRuntimeIfNeeded(Activity activity,
java.lang.String permission,
View permissionRequestLayout,
int permissionReminder,
int requestCode)
Runtime permissions request for API>=23
|
static boolean |
isEmpty(java.lang.String string)
Check if string is null or empty
|
static <T> java.util.List<T> |
iteratorToList(java.util.Iterator<T> iterator)
Translates and iterator to a list
|
static java.lang.String |
joinIfNotEmpty(java.lang.CharSequence delimiter,
java.lang.Object[] tokens)
Wrapper for
android.text.TextUtils#join(CharSequence, Object[]) that first checks if the token array is empty |
static <K,V> java.util.HashMap<K,V> |
listsToHashMap(java.util.List<K> keys,
java.util.List<V> values)
Translates two lists into an hashmap
|
static boolean |
manageToolbarMenuSelection(Activity activity,
int id)
Helper to manage a menu option selection
|
static java.util.Date |
parseDateFromString(java.lang.String dateString,
java.lang.String format)
Translates a string to a date using the provided format
|
static java.util.Date |
parseDateFromYearMonthDay(int year,
int month,
int day)
Creates a date object from year, month and day values
|
static int |
parseInt(java.lang.String s)
Wrapper for
Integer.parseInt(String) that returns 0 in case of exception |
static int |
parseYearFromString(java.lang.String dateString,
java.lang.String format)
Similar to
parseDateFromString(String, String) but returns only the year of the date |
static int |
randInt(int min,
int max)
Random integer between the two given values
|
public static <T> java.util.List<T> iteratorToList(java.util.Iterator<T> iterator)
T
- the type of objects in the iteratoriterator
- the iteratorpublic static <K,V> java.util.HashMap<K,V> listsToHashMap(java.util.List<K> keys, java.util.List<V> values)
K
- keys typeV
- values typekeys
- list of keysvalues
- list of valuespublic static java.util.Date parseDateFromString(java.lang.String dateString, java.lang.String format)
dateString
- the string containing the dateformat
- the format of the date in the stringpublic static int parseYearFromString(java.lang.String dateString, java.lang.String format)
parseDateFromString(String, String)
but returns only the year of the datepublic static java.util.Date parseDateFromYearMonthDay(int year, int month, int day)
year
- the year (if 0 the returned date will be null)month
- the month (can be 0 if unknown)day
- the day (can be 0 if unknown)public static java.lang.String joinIfNotEmpty(java.lang.CharSequence delimiter, java.lang.Object[] tokens)
android.text.TextUtils#join(CharSequence, Object[])
that first checks if the token array is emptypublic static boolean isEmpty(java.lang.String string)
string
- the string to checkpublic static int arrayAverage(int[] array)
array
- the arraypublic static int parseInt(java.lang.String s)
Integer.parseInt(String)
that returns 0 in case of exceptionpublic static void askPermissionsAtRuntimeIfNeeded(Activity activity, java.lang.String permission, View permissionRequestLayout, int permissionReminder, int requestCode)
activity
- the requesting activitypermission
- the permissionpermissionRequestLayout
- the main layout component displayed on screenpermissionReminder
- the string shown as reminder if the user didn't accept the permissionrequestCode
- the request codepublic static boolean manageToolbarMenuSelection(Activity activity, int id)
activity
- the activityid
- the ID of the option selected by the userpublic static int randInt(int min, int max)
min
- min value (included)max
- max value (included)