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 isEmpty(List<?> list) {
    return list == null || list.isEmpty();
}

From source file:Main.java

public static <T> T mostCommon(List<T> list, double percent) {
    if (list.isEmpty())
        return null;

    Map<T, Integer> map = new HashMap<>();

    for (T t : list) {
        Integer count = map.get(t);
        map.put(t, count == null ? 1 : count + 1);
    }/*from  ww  w  .  j  a  v  a 2 s .  c  o m*/

    double freq = map.size() / (double) list.size();
    if (1.0 == freq || (1.0 - freq) < percent)
        return null;

    Entry<T, Integer> max = null;
    for (Entry<T, Integer> e : map.entrySet()) {
        if (max == null || e.getValue() > max.getValue()) {
            max = e;
        }
    }

    return max.getKey();
}

From source file:Main.java

public static boolean isEmpty(List<? extends Object> list) {
    return list == null || list.isEmpty();
}

From source file:Main.java

public static <T> List<T> subList(List<T> list, int first, int end) {
    if (null == list || list.isEmpty())
        return null;
    int size = list.size();
    int fromIndex = first;
    int toIndex = end;
    if (fromIndex < 0) {
        toIndex = 0;/*w w  w .j  a  v  a  2s  .c om*/
    }
    if (toIndex > size) {
        toIndex = size;
    }
    if (fromIndex > toIndex)
        return null;
    return list.subList(fromIndex, toIndex);
}

From source file:Main.java

public static Element getChildNode(Element parent, String name) {
    List<Element> childNodes = getChildNodes(parent, name);
    if (childNodes.isEmpty()) {
        return null;
    }/*from  w  ww. ja v a 2  s  .c o m*/
    return childNodes.get(0);
}

From source file:Main.java

/**
 * Returns the first found frame of {@code #findFramesWithIcons()}. <p> Especially for usage in a
 * <code>JOptionPane#show...Dialog()</code> instead of null. Then in the dialog frame an icon will be displayed that
 * is different to the Java "coffee cup" icon.
 *
 * @return frame or null/* w w w .j a  v  a  2s  .  c o m*/
 */
public static Frame findFrameWithIcon() {
    List<Frame> frames = findFramesWithIcons();

    return (frames.isEmpty()) ? null : frames.get(0);
}

From source file:com.xpfriend.fixture.cast.temp.TempDynaSet.java

private static TempDynaClass getTempDynaClass(List<DynaBean> table) {
    if (table.isEmpty()) {
        throw new IllegalArgumentException();
    }/*from  w  w w.java 2 s  .  c  o  m*/
    return (TempDynaClass) table.get(0).getDynaClass();
}

From source file:Main.java

public static Element getChildElement(Element parent, String tagName) {
    List children = getChildElements(parent, tagName);
    return children.isEmpty() ? null : (Element) children.get(0);
}

From source file:Main.java

public static <T> T getSingle(List<T> collection) {
    boolean hasAnyElements = collection != null && !collection.isEmpty();
    if (!hasAnyElements) {
        throw new RuntimeException("Collection is null or empty");
    }//from  ww  w  .  j  a v a  2 s .  c  o  m

    boolean hasMultipleResults = collection.size() > 1;
    if (hasMultipleResults) {
        throw new RuntimeException("Collection contains multiple elements");
    }

    return collection.get(0);
}

From source file:Main.java

public static List<String> stringToList(String weeksStr) {
    List<String> weekList = new ArrayList<>();
    if (weeksStr == null || weekList.isEmpty()) {
        return weekList;
    }/* w  ww  .  j  a va 2 s.  c  o  m*/
    String[] weeksArray = weeksStr.split(",");
    if (weeksArray.length != 0) {
        weekList = Arrays.asList(weeksArray);
    } else {
        weekList.add(weeksStr);
    }
    return weekList;
}