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 boolean isTopApp(Context context) {
    ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    List<RunningTaskInfo> TaskList = am.getRunningTasks(2);
    if (TaskList == null || TaskList.isEmpty()) {
        return false;
    }//from w w w  .ja  va2s. c  o  m
    RunningTaskInfo rti = TaskList.get(0);
    String tmp = rti.topActivity.getPackageName();
    return tmp.equals(context.getPackageName());
}

From source file:Main.java

public static boolean isApplicationBroughtToBackground(Context context) {
    ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    List<RunningTaskInfo> taskInfo = am.getRunningTasks(1);
    if (!taskInfo.isEmpty()) {
        ComponentName topActivity = taskInfo.get(0).topActivity;
        if (!topActivity.getPackageName().equals(context.getPackageName())) {
            return true;
        }/*from  w  w w  .j ava 2  s.c o m*/
    }

    return false;
}

From source file:Main.java

/**
 * This API is to get the lowest value from a List. The input objects need
 * to implement Comparable.//from  w w  w .  j a v  a  2  s .  com
 * 
 * 
 * @param <T>
 *            The type of the object the input list can contain and also the
 *            return type of the method
 * @param list
 * @return
 * @author sabuj.das
 */
public static <T extends Comparable<T>> T lowestValue(List<T> list) {
    if (list == null || list.isEmpty()) {
        return null;
    }
    Collections.sort(list);
    return list.get(0);
}

From source file:Main.java

public static <T> boolean emptyList(List<T> list) {
    if (list == null) {
        return true;
    }//from   w w w  .java  2 s.co  m
    if (list.isEmpty()) {
        return true;
    }
    return false;
}

From source file:Main.java

public static <T> T last(List<T> collection) {
    if (collection == null || collection.isEmpty()) {
        return null;
    }//from ww  w . j a  v  a  2  s. co  m
    return collection.get(collection.size() - 1);

}

From source file:Main.java

public static <T> List<T> assertNotNullOrNotEmpty(List<T> reference, @Nullable Object errorMessage) {
    if (reference == null || reference.isEmpty()) {
        throw new IllegalArgumentException(String.valueOf(errorMessage));
    }/*from w  w w.j ava2 s .  co m*/
    return reference;
}

From source file:Main.java

public static <T> boolean isSubset(List<T> subList, List<T> list) {
    if (subList == null || list == null || subList.isEmpty() || list.isEmpty()) {
        return false;
    }//from  w w w  .  j a va  2  s  .c  o  m
    List<T> subList1 = new ArrayList();
    subList1.addAll(subList);

    for (T t : list) {
        if (subList1.contains(t)) {
            subList1.remove(t);
        }
    }
    if (subList1.isEmpty()) {
        return true;
    }
    return false;
}

From source file:Main.java

/**
 * //w ww  .  j  a v  a2 s. c  o  m
 * @param <T>
 * @param list
 * @return
 */
public static <T extends Comparable<T>> T getLowerMiddleValue(List<T> list) {
    if (null == list || list.isEmpty())
        return null;
    Collections.sort(list);
    return list.get((list.size() - 1) / 2);
}

From source file:Main.java

public static String listToString(List<String> list, String delimiter) {
    if (list == null || list.isEmpty()) {
        return "";
    }/*  ww w  .  j  a  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

/**
 * Generates permutations from a list of collections. Each permutation contains an element
 * from each of the collections. //from w  w w .  ja v  a 2 s.  co m
 * 
 * @param <T>         the generic type for object in the collections
 * @param collections   the list of collections
 * @return            the collection of permutations
 */
public static <T> Collection<List<T>> generatePermutations(List<Collection<T>> collections) {
    if (collections == null || collections.isEmpty()) {
        return Collections.emptyList();
    } else {
        Collection<List<T>> res = new LinkedList<List<T>>();
        permutationsImpl(collections, res, 0, new LinkedList<T>());
        return res;
    }
}