Example usage for java.util Collection size

List of usage examples for java.util Collection size

Introduction

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

Prototype

int size();

Source Link

Document

Returns the number of elements in this collection.

Usage

From source file:Main.java

/**
 * Converts a Collection containing java.io.File instanced into array
 * representation. This is to account for the difference between
 * File.listFiles() and FileUtils.listFiles().
 *
 * @param files a Collection containing java.io.File instances
 * @return an array of java.io.File//from ww w.j  a  v  a 2s.  c om
 */
public static File[] convertFileCollectionToFileArray(Collection<File> files) {
    return files.toArray(new File[files.size()]);
}

From source file:Main.java

@SuppressWarnings("unchecked")
public static final boolean isEmpty(Collection c) {
    return null == c || 0 == c.size() ? true : false;
}

From source file:Main.java

public static boolean isTheSame(Collection a, Collection b) {
    int sizeA = a == null ? 0 : a.size();
    int sizeB = b == null ? 0 : b.size();
    if (sizeA == sizeB && sizeA != 0) {
        int matchCount = 0;
        for (Object obj : a) {
            if (b.contains(obj)) {
                matchCount++;/*from w  w w.ja v a  2  s.  c om*/
            }
        }
        return matchCount == b.size();
    } else {
        return sizeA == 0;
    }
}

From source file:Main.java

@SuppressWarnings("rawtypes")
public static final boolean isEmpty(Collection c) {
    return null == c || 0 == c.size() ? true : false;
}

From source file:Main.java

/**
 * Returns true if both collections contain the same elements and the elements are in the same order.
 * Note that the start elements do not have to be the equal!
 * @param s1 The first collection//  ww w  .j a  v a 2s .co  m
 * @param s2 The second collection
 * @return true if s1 and s2 are same in the sense explained above. 
 */
public static boolean sameElementsSameOrder(Collection<?> s1, Collection<?> s2) {
    if (s1.size() != s2.size())
        return false;

    Iterator<?> it1 = s1.iterator();
    Object first = it1.next();
    for (Iterator<?> it2 = s2.iterator(); it2.hasNext();) {
        if (it2.next().equals(first)) {
            while (it1.hasNext()) {
                if (!it2.hasNext())
                    it2 = s2.iterator();
                if (!it1.next().equals(it2.next()))
                    return false;
            }
            return true;
        }
    }
    return false;
}

From source file:Main.java

/**
 * Concatenate the collection of lists passed as argument into a new array list.
 * @param lists/*from  w ww  .j  a v  a 2 s  .c  o m*/
 * @param <T>
 * @return
 */
public static <T> List<T> concat(Collection<? extends Collection<T>> lists) {
    int size = 0;
    for (Collection<T> list : lists) {
        size += list.size();
    }
    List<T> result = new ArrayList<T>(size);
    for (Collection<T> list : lists) {
        result.addAll(list);
    }
    return result;
}

From source file:Main.java

public static <T> String[] addSuffix(Collection<T> col, String suffix) {

    String[] result = new String[col.size()];

    int index = 0;
    for (T e : col) {
        result[index++] = e.toString() + suffix;
    }//  w ww  .  j  av a2s .  c o m

    return result;

}

From source file:Main.java

public static <T> int size(final Collection<T> collection) {
    return collection == null ? 0 : collection.size();
}

From source file:Main.java

/**
 * Check if collection contains element.
 * @return true: null == collection || 0 == collection.size()
 * @return false: null != collection && 0 != collection.size()
 *//*from  w  w w  . ja  va 2  s .c  om*/
public static boolean isBlank(Collection<? extends Object> collection) {
    if (null == collection || 0 == collection.size()) {
        return true;
    }
    return false;
}

From source file:Main.java

public static boolean isNullOrEmpty(Collection c) {
    boolean isNullOrEmpty = false;
    if (null == c || c.size() == 0) {
        isNullOrEmpty = true;/*from  w  w w .  j a va  2 s  . c  o  m*/
    }
    return isNullOrEmpty;
}