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

public static <T, K> T copyTree(T node, Function<T, K> keyMapper, Function<T, Collection<T>> childMapper,
        Function<T, T> cloneMapper, Collection<K> toCopy) {
    if (toCopy == null)
        return null;

    T copy = null;//from w w w  .  ja  va  2s  .c om

    Collection<T> children = childMapper.apply(node);
    if (children != null && children.size() > 0) {
        for (T child : children) {
            T childCopy = copyTree(child, keyMapper, childMapper, cloneMapper, toCopy);
            if (childCopy != null) {
                if (copy == null)
                    copy = cloneMapper.apply(node);
                childMapper.apply(copy).add(childCopy);
            }
        }
    }

    if (copy == null && toCopy.contains(keyMapper.apply(node)))
        copy = cloneMapper.apply(node);

    return copy;
}

From source file:io.syndesis.model.ListResult.java

static <T> ListResult<T> of(Collection<T> items) {
    return new Builder<T>().items(items).totalCount(items.size()).build();
}

From source file:Main.java

public static int sizeOf(Collection collection) {
    if (isEmpty(collection)) {
        return 0;
    }/*from  w ww  .  j a va 2s  . co m*/
    return collection.size();
}

From source file:Main.java

public static int getLength(Collection<?> collection) {
    if (collection == null) {
        return 0;
    }/*www.  ja  v a 2s  .co  m*/

    return collection.size();
}

From source file:Main.java

/**
 * The resultant set is those elements in superSet which are not in the subSet
 *///from   ww w .ja va2s .  co m
public static <T> List<T> setComplement(Collection<T> superSet, Collection<T> subList) {
    ArrayList<T> complement = new ArrayList<T>(superSet.size());
    for (T obj : superSet) {
        if (!subList.contains(obj)) {
            complement.add(obj);
        }
    }
    return complement;
}

From source file:Main.java

public static <T> int size(Collection<T> col) {
    if (col == null) {
        return 0;
    } else {/*from   w w w.j  av a2 s .co m*/
        return col.size();
    }
}

From source file:Main.java

public static boolean isNotEmpty(Collection<Object> collection) {
    if (collection == null) {
        return false;
    }/* ww w .j  av  a 2 s  .co  m*/
    if (collection.size() == 0) {
        return false;
    }
    return true;
}

From source file:Main.java

public static long[] collectionToLongArray(Collection<Long> allKeys) {
    if (allKeys == null)
        return null;
    long[] values = new long[allKeys.size()];
    int count = 0;
    for (Long allKey : allKeys) {
        values[count++] = allKey.longValue();
    }//from  w  w  w.ja va2s . c  om
    return values;
}

From source file:Main.java

/** Returns a new array even if collection is empty */
public static <T> T[] toArray(Collection<T> c, Class klass) {
    return toArray(c, (T[]) Array.newInstance(klass, c.size()));
}

From source file:Main.java

/**
 * This//from  w w  w.  j  av a  2 s  .c  o  m
 * @param collection
 * @return
 */
public static String[] toStringArray(Collection<? extends Object> collection) {
    String[] strArray = new String[collection.size()];

    int index = 0;
    for (Object obj : collection) {
        if (obj == null) {
            strArray[index] = "null";
        } else {
            strArray[index] = obj.toString();
        }
        index++;
    }

    return strArray;
}