Example usage for java.util List isEmpty

List of usage examples for java.util List isEmpty

Introduction

In this page you can find the example usage for java.util List isEmpty.

Prototype

boolean isEmpty();

Source Link

Document

Returns true if this list contains no elements.

Usage

From source file:Main.java

public static String join(List<String> list, String delimiter) {
    if (list == null || list.isEmpty()) {
        return "";
    }//from   w  w  w.ja  v  a 2 s.  c o  m
    final StringBuilder builder = new StringBuilder();
    boolean first = true;
    for (String s : list) {
        if (first) {
            first = false;
        } else {
            builder.append(delimiter);
        }
        builder.append(s);
    }
    return builder.toString();
}

From source file:Main.java

public static Element getChildElement(Element parent, String tagName) {
    List<Element> children = getChildElements(parent, tagName);
    if (children.isEmpty()) {
        return null;
    } else {//from  ww w  . j a  v  a  2  s. c om
        return children.get(0);
    }
}

From source file:com.github.jakubkolar.autobuilder.groovy.Table.java

public static Table of(List<TableRow> rows) {
    if (rows.isEmpty()) {
        throw new IllegalArgumentException("No rows defined: every table must have"
                + " at least 1 row (the header). Also please check that your table"
                + " has at least 2 columns separated by the '|' operator (technical" + " restriction)");
    }/*from  w  w w  .  j av a 2 s . c om*/

    Table table = new Table(rows.get(0));

    for (int i = 1; i < rows.size(); i++) {
        table.add(rows.get(i));
    }

    return table;
}

From source file:Main.java

/**
 * Checks if the application is in the background (i.e behind another application's Activity).
 * //from   ww  w . jav  a  2  s  .  c o m
 * @param context
 * @return true if another application is above this one.
 */
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;
        }
    }

    return false;
}

From source file:Main.java

public static <T> Object getContent(List<T> collection, Object object) {
    Object retValue = null;//w ww  .j a v  a  2 s .c om
    if (collection != null && !collection.isEmpty() && collection.contains(object)) {
        retValue = collection.get(collection.indexOf(object));
    }
    return retValue;
}

From source file:Main.java

public static String getTopActivityName(Context context) {
    try {/*from  ww  w.ja va  2  s . c  o m*/
        ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
        List<ActivityManager.RunningTaskInfo> tasks = am.getRunningTasks(1);
        if (!tasks.isEmpty()) {
            ComponentName topActivity = tasks.get(0).topActivity;
            return topActivity.getClassName();
        }
    } catch (Exception ex) {
        ex.printStackTrace();
    }
    return "";
}

From source file:Main.java

public static <T> boolean listsEquals(List<T> list1, List<T> list2) {
    if (list1 == null) {
        return list2 == null || list2.isEmpty();
    }/*  www  . jav a 2  s .c om*/
    if (list1.size() != list2.size()) {
        return false;
    }
    return list1.containsAll(list2);
}

From source file:Main.java

public static boolean isApplicationInStackHead(Context context) {
    ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    List<RunningTaskInfo> taskList = am.getRunningTasks(1);
    if (taskList != null && !taskList.isEmpty()) {
        ComponentName topActivity = taskList.get(0).topActivity;
        if (topActivity != null && !topActivity.getPackageName().equals(context.getPackageName())) {
            return false;
        }/*from   w  w  w. j a v  a  2 s  .  com*/
    }
    return true;
}

From source file:Main.java

public static boolean isApplicationInBackground(Context context) {
    ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    List<RunningTaskInfo> taskList = am.getRunningTasks(1);
    if (taskList != null && !taskList.isEmpty()) {
        ComponentName topActivity = taskList.get(0).topActivity;
        if (topActivity != null && !topActivity.getPackageName().equals(context.getPackageName())) {
            return true;
        }/*from  ww  w  .  j  a v a 2 s.c  om*/
    }
    return false;
}

From source file:net.firejack.platform.core.utils.ArrayUtils.java

public static <T> T[] append(T[] array, List<T> list, Class<T> clazz) {
    if (list == null || list.isEmpty()) {
        return array;
    }//w w w .  j  av a  2  s . c om
    T[] additionalItems = getArray(list, clazz);
    return array == null ? additionalItems : (T[]) addAll(array, additionalItems);
}