List of usage examples for java.util List isEmpty
boolean isEmpty();
From source file:Main.java
/** * Returns the first element of a list or null if the list * is null or empty.//w w w . j a va 2 s. c om * * @param l the list in which to find the first element * @return Object the first element of the list */ public static Object getFirstElement(List l) { // Return null if list is null or empty if (l == null || l.isEmpty()) return null; return l.get(0); }
From source file:Main.java
public static String stringList2String(final String suffix, final List<String> list) { if (list == null || list.isEmpty()) { return null; }/* ww w . j a v a 2s.co m*/ StringBuilder builder = new StringBuilder(""); for (int i = 0; i < list.size(); i++) { String value = list.get(i); if (value != null && !"".equals(value)) { if (i < (list.size() - 1)) { builder.append(value).append(suffix); } else { builder.append(value); } } } return builder.toString(); }
From source file:Main.java
public static Element getElement(Element parent, String tagName) { List children = getElements(parent, tagName); return children.isEmpty() ? null : (Element) children.get(0); }
From source file:Main.java
static <E> List<E> getList(List<E> orig, Class<E> elemType) { if (orig == null || orig.isEmpty()) { return Collections.emptyList(); } else if (orig.size() == 1) { return Collections.singletonList(orig.get(0)); } else {// w ww . ja va 2 s. c o m return Collections.unmodifiableList(Arrays.asList(orig.toArray(createArray(elemType, orig.size())))); } }
From source file:Main.java
/** * Check if the list contains the member. For objects, it uses standard .equals() method. * For strings, it compares but ignores the case. * //from w w w .j av a 2 s . c om * @param list * @param member * @return */ public static boolean contains(List<? extends Object> list, Object member) { if (list.isEmpty() || member == null) return false; for (Object obj : list) { if (obj instanceof String && member instanceof String) { if (compareIgnoreCase((String) obj, (String) member)) return true; } else { if (member.equals(obj)) return true; } } return false; }
From source file:bazaar4idea.command.BzrErrorUtil.java
private static String getLastErrorLine(BzrAbstractResult result) { List<String> errorLines = result.getStdErrAsLines(); if (errorLines.isEmpty()) { return null; }/* ww w . j av a 2s . co m*/ return errorLines.get(errorLines.size() - 1); }
From source file:Main.java
public static boolean isBackground(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 ww w .j av a 2 s. c om*/ } return false; }
From source file:Main.java
public static boolean isApplicationBackground(Context context) { ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); List<ActivityManager.RunningTaskInfo> tasks = am.getRunningTasks(1); if (!tasks.isEmpty()) { ComponentName topActivity = tasks.get(0).topActivity; if (!topActivity.getPackageName().equals(context.getPackageName())) { return true; }/* w w w.j av a 2 s . c om*/ } return false; }
From source file:Main.java
public static <T> List<T> readTypedListOrNUll(Parcel parcel, Parcelable.Creator<T> creator) { List<T> result = new ArrayList<>(); parcel.readTypedList(result, creator); if (result.isEmpty()) return null; return result; }
From source file:Main.java
public static boolean isApplicationBroughtToBackground(Context context) { ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); List<RunningTaskInfo> tasks = am.getRunningTasks(1); if (tasks != null && !tasks.isEmpty()) { ComponentName topActivity = tasks.get(0).topActivity; if (!topActivity.getPackageName().equals(context.getPackageName())) { return true; }/*from w w w. ja va2s. co m*/ } return false; }