Example usage for java.util Collection isEmpty

List of usage examples for java.util Collection isEmpty

Introduction

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

Prototype

boolean isEmpty();

Source Link

Document

Returns true if this collection contains no elements.

Usage

From source file:adalid.commons.util.ColUtils.java

public static <T> Collection<T> oneFilter(Collection<T> collection, Predicate... predicates) {
    if (collection == null || collection.isEmpty() || predicates == null) {
        return collection;
    } else {/*w w  w.  j  a  va2 s .c  o m*/
        //          Collection<T> list = new ArrayList<T>();
        //          list.addAll(collection);
        Collection<T> list = new ArrayList<>(collection);
        Predicate predicate = PredicateUtils.onePredicate(predicates);
        CollectionUtils.filter(list, predicate);
        return list;
    }
}

From source file:adalid.commons.util.ColUtils.java

public static <T> Collection<T> noneFilter(Collection<T> collection, Predicate... predicates) {
    if (collection == null || collection.isEmpty() || predicates == null) {
        return collection;
    } else {//from w  ww .j a v  a  2  s  . co m
        //          Collection<T> list = new ArrayList<T>();
        //          list.addAll(collection);
        Collection<T> list = new ArrayList<>(collection);
        Predicate predicate = PredicateUtils.nonePredicate(predicates);
        CollectionUtils.filter(list, predicate);
        return list;
    }
}

From source file:info.archinnov.achilles.internal.validation.Validator.java

public static void validateNotEmpty(Collection<?> arg, String message, Object... args) {
    if (arg == null || arg.isEmpty()) {
        throw new AchillesException(format(message, args));
    }//  w  ww .  j a  v a  2  s. c o m
}

From source file:dev.meng.wikipedia.profiler.util.StringUtils.java

public static String collectionToString(Collection collection, String delimeter) {
    String result = "";
    if (!collection.isEmpty()) {
        Iterator iterator = collection.iterator();
        result = result + iterator.next();
        while (iterator.hasNext()) {
            result = result + delimeter + iterator.next();
        }//from  w  w  w .j a va2s.  com
    }
    return result;
}

From source file:adalid.commons.util.ColUtils.java

public static <T> Collection<T> sort(Collection<T> collection, Comparator<T> comparator) {
    if (collection instanceof List && !collection.isEmpty() && comparator != null) {
        List<T> list = (List<T>) collection;
        Collections.sort(list, comparator);
    }/*from  ww w . jav  a2s . c  om*/
    return collection;
}

From source file:Main.java

public static boolean isNotEmpty(Collection collection) {
    return (collection != null && !(collection.isEmpty()));
}

From source file:Main.java

public static String singleDump(final Collection<?> l) {
    final StringBuilder sb = new StringBuilder();
    if (l == null) {
        sb.append("[]");
    } else if (l.isEmpty()) {
        sb.append("[]");
    } else {/*from   ww  w  .  jav  a2 s  .co m*/
        final Iterator<?> iterator = l.iterator();
        int cnt = 0;
        sb.append("[");
        while (iterator.hasNext()) {
            if (cnt++ > 0) {
                sb.append(", ");
            }
            sb.append(iterator.next().toString());
        }
        sb.append("]");
    }
    return (sb.toString());
}

From source file:adalid.commons.util.ColUtils.java

@SuppressWarnings("unchecked") // unchecked cast
public static <T> Collection<T> sort(Collection<T> collection, Comparator<T>... comparators) {
    if (collection instanceof List && !collection.isEmpty() && comparators != null) {
        List<T> list = (List<T>) collection;
        Comparator<T> comparator = (Comparator<T>) ComparatorUtils.chainedComparator(comparators); // unchecked cast
        Collections.sort(list, comparator);
    }/*from   ww  w  .ja  va2 s .  c o  m*/
    return collection;
}

From source file:com.amalto.core.history.action.StringActions.java

public static Action mostCommon(Collection<FieldUpdateAction> actions) {
    if (actions == null || actions.isEmpty()) {
        return NoOpAction.instance();
    }/*  www  . j  av a 2s. c o m*/
    return MostCommonAction.mostCommon(actions);
}

From source file:Main.java

/**
 * Collections are equals if they contain the same elements 
 * independent of ordering.//from   ww  w .  j a  v a  2  s . c o  m
 * To this to be true, they must have the same number of elements.
 * Empty collections are equal.
 * 
 * @param <T>
 * @param c1
 * @param c2
 * @return
 */
public static <T> boolean equalContents(Collection<? extends T> c1, Collection<? extends T> c2) {

    if (c1 == c2) {
        return true;
    } else if (c1.isEmpty() && c2.isEmpty()) {
        return true;
    }
    if (c1.size() != c2.size()) {
        return false;
    }

    if (!(c2 instanceof Set) && (c1 instanceof Set || c1.size() > c2.size())) {
        //swap
        Collection<? extends T> tmp = c1;
        c1 = c2;
        c2 = tmp;
    }

    for (T t : c1) {
        if (!c2.contains(t)) {
            return false;
        }
    }
    return true;

}