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:hu.ppke.itk.nlpg.purepos.common.Util.java

public static <E> boolean isNotEmpty(Collection<E> c) {
    return c != null && c.size() > 0;
}

From source file:imageClassify.Describe.java

private static List<String> convert(Collection<?> values) {
    List<String> list = Lists.newArrayListWithCapacity(values.size());
    for (Object value : values) {
        list.add(value.toString());//from www  .j  a  v  a 2s. c  o  m
    }
    return list;
}

From source file:Main.java

public static <T> T last(Collection<T> c) {
    if (isEmpty(c))
        return null;

    if (c instanceof List)
        return (T) ((List<T>) c).get(c.size() - 1);

    List<T> a = new ArrayList<T>(c);
    return a.get(a.size() - 1);
}

From source file:Main.java

/**
 * Copy the given Collection into a Class array.
 * The Collection must contain Class elements only.
 *
 * @param collection the Collection to copy
 * @return the Class array ({@code null} if the passed-in
 * Collection was {@code null})//from w  ww  . j  a va 2  s .co  m
 */
public static Class<?>[] toClassArray(Collection<Class<?>> collection) {
    if (collection == null) {
        return null;
    }
    return collection.toArray(new Class<?>[collection.size()]);
}

From source file:Main.java

/**
 * Removes duplicate objects from the Collection.
 * @param p_collection a Collection//from w  w  w .j  ava 2s.co m
 * @returns true if one or more duplicate objects were removed.
 */
public static boolean removeDuplicates(Collection p_collection) {
    if (p_collection == null) {
        return false;
    }
    HashSet set = new HashSet(p_collection.size());
    Iterator it = p_collection.iterator();
    while (it.hasNext()) {
        set.add(it.next());
    }
    if (set.size() != p_collection.size()) {
        p_collection.clear();
        p_collection.addAll(set);
        return true;
    }
    return false;
}

From source file:Main.java

public static <T> void nullFill(final Collection<T> coll, @Nonnegative final int size) {
    checkNotNull(coll);/*from   w w  w  .  ja  va2 s .  com*/
    checkArgument(size >= 0, "size is negative");
    while (coll.size() < size) {
        coll.add(null);
    }

}

From source file:Main.java

public static int[] toIntArray(Collection<Integer> list) {
    if (list == null || list.isEmpty()) {
        return EMPTY_INT_ARRAY;
    }/*ww w  .  j  a v  a2  s.  c om*/
    int[] result = new int[list.size()];
    int i = 0;
    for (Integer integer : list) {
        result[i++] = integer;
    }
    return result;
}

From source file:Main.java

/**
 * //from w w w. j ava  2s . com
 * @param collection
 * @return int[]
 */
public static boolean[] toBooleanArray(final Collection<Boolean> collection) {
    final boolean[] array = new boolean[collection == null ? 0 : collection.size()];

    if (collection != null) {
        int i = 0;

        for (Iterator<Boolean> iterator = collection.iterator(); iterator.hasNext();) {
            array[i++] = iterator.next().booleanValue();
        }
    }

    return array;
}

From source file:Main.java

/**
 * Converts a collection of Integer values to an int[] array.
 * @param values//ww w .jav a  2s .  c  om
 * @return null if the given collection is null, otherwise an array of the same size as the collection
 * @throws NullPointerException when an element of the collection is null
 */
public static int[] toIntArray(Collection<Integer> values) {
    if (values == null) {
        return null;
    }
    int i = 0;
    int[] result = new int[values.size()];
    for (Integer value : values) {
        result[i++] = value;
    }
    return result;
}

From source file:com.goncalomb.bukkit.bkglib.namemaps.EntityTypeMap.java

public static List<String> getNames(Collection<EntityType> types) {
    ArrayList<String> names = new ArrayList<String>(types.size());
    for (EntityType type : types) {
        names.add(getName(type));// w  w w .j ava  2 s  . c  o  m
    }
    return names;
}