List of usage examples for java.util List isEmpty
boolean isEmpty();
From source file:Main.java
/** * Return the last item of the {@code List}. Null is returned if the list is null or empty. * * @param <T> Type of the items in the list * @param list Input list/* www . j ava 2 s. com*/ * @return Last item of the list or null if the list is empty */ public static <T> T getLast(List<T> list) { if (list == null || list.isEmpty()) { return null; } return list.get(list.size() - 1); }
From source file:Main.java
static String getKSessionName(List<String> kSessions) { if (kSessions == null || kSessions.isEmpty()) { return null; } else {//from ww w. ja v a 2s . c o m return kSessions.iterator().next(); } }
From source file:Main.java
public static <T> List<T> mergeAll(List<T>... lists) { List<T> mergedList = new ArrayList<T>(); for (int i = 0, len = lists.length; i < len; i++) { List<T> list = lists[i]; if (list != null && !list.isEmpty()) { for (int j = 0, lenj = list.size(); j < lenj; j++) { T obj = list.get(j);/* w ww . j a v a 2s .c o m*/ if (obj != null) { mergedList.add(obj); } } } } return mergedList; }
From source file:Main.java
public static final <T> List<List<T>> devide(List<T> origin, int size) { if (origin == null || origin.isEmpty() || size <= 0) { return Collections.emptyList(); }// w ww. j a v a2 s . co m final int block = origin.size() / size + (origin.size() % size > 0 ? 1 : 0); List<List<T>> devidedList = new ArrayList<List<T>>(block); for (int i = 0; i < block; i++) { final int start = i * size; final int end = Math.min(start + size, origin.size()); devidedList.add(new ArrayList<T>(origin.subList(start, end))); } return devidedList; }
From source file:Main.java
public static <T> T last(List<T> list) { if (list == null || list.isEmpty()) { return null; }/*from w w w. j av a2s.c o m*/ return list.get(list.size() - 1); }
From source file:Main.java
public static <T> T getFirst(Map<String, List<T>> multiValutMap, String key) { List<T> values = multiValutMap.get(key); if (values != null && !values.isEmpty()) return values.get(0); return null;//from ww w . j a v a2 s.co m }
From source file:Main.java
public static String toString(List<String> permission) { if (permission == null || permission.isEmpty()) { return ""; }//from w ww . j ava2s . co m return toString(permission.toArray(new String[permission.size()])); }
From source file:Main.java
public static boolean isBackgroundRunning(Context context) { ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); List<RunningTaskInfo> tasks = am.getRunningTasks(1); if (!tasks.isEmpty()) { ComponentName topActivity = tasks.get(0).topActivity; if (!topActivity.getPackageName().equals(context.getPackageName())) { return true; }// w ww .j av a2 s. c o m } return false; }
From source file:Main.java
public static boolean isApplicationBroughtToBackground(final Context context) { ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); List<RunningTaskInfo> tasks = am.getRunningTasks(1); if (!tasks.isEmpty()) { ComponentName topActivity = tasks.get(0).topActivity; if (!topActivity.getPackageName().equals(context.getPackageName())) { return true; }/*from w w w . ja v a 2s . c o m*/ } return false; }
From source file:Main.java
public static boolean isEmpty(List<?> list) { if (list == null) return true; return list.isEmpty(); }