FileDocCategorySizeDatePackage
ListUtils.javaAPI DocAndroid 5.1 API3007Thu Mar 12 22:22:10 GMT 2015android.hardware.camera2.utils

ListUtils

public class ListUtils extends Object
Various assortment of list utilities.

Using a {@code null} list is supported and will almost always return the default value (e.g. {@code false}, or {@code null}).

Fields Summary
Constructors Summary
private ListUtils()

        throw new AssertionError();
    
Methods Summary
public static booleanlistContains(java.util.List list, T needle)
Return {@code} true if the {@code list} contains the {@code needle}.

        if (list == null) {
            return false;
        } else {
            return list.contains(needle);
        }
    
public static booleanlistElementsEqualTo(java.util.List list, T single)
Return {@code true} if the {@code list} is only a single element equal to {@code single}.

        if (list == null) {
            return false;
        }

        return (list.size() == 1 && list.contains(single));
    
public static TlistSelectFirstFrom(java.util.List list, T[] choices)
Return the first item from {@code choices} that is contained in the {@code list}.

Choices with an index closer to 0 get higher priority. If none of the {@code choices} are in the {@code list}, then {@code null} is returned.

param
list a list of objects which may or may not contain one or more of the choices
param
choices an array of objects which should be used to select an item from
return
the first item from {@code choices} contained in {@code list}, otherwise {@code null}

        if (list == null) {
            return null;
        }

        for (T choice : choices) {
            if (list.contains(choice)) {
                return choice;
            }
        }

        return null;
    
public static java.lang.StringlistToString(java.util.List list)
Return a human-readable representation of a list (non-recursively).

        if (list == null) {
            return null;
        }

        StringBuilder sb = new StringBuilder();
        sb.append('[");

        int size = list.size();
        int i = 0;
        for (T elem : list) {
            sb.append(elem);

            if (i != size - 1) {
                sb.append(',");
            }
            i++;
        }
        sb.append(']");

        return sb.toString();