Example usage for java.util Collection add

List of usage examples for java.util Collection add

Introduction

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

Prototype

boolean add(E e);

Source Link

Document

Ensures that this collection contains the specified element (optional operation).

Usage

From source file:com.cloudera.oryx.ml.serving.als.model.LoadTestALSModelFactory.java

public static ALSServingModel buildTestModel() {

    log.info("Building load test model...");

    System.gc();//ww  w. j a v a 2s. c om
    long startMemory = JVMUtils.getUsedMemory();

    RandomGenerator random = RandomManager.getRandom();
    PoissonDistribution itemPerUserDist = new PoissonDistribution(random, AVG_ITEMS_PER_USER,
            PoissonDistribution.DEFAULT_EPSILON, PoissonDistribution.DEFAULT_MAX_ITERATIONS);
    ALSServingModel model = new ALSServingModel(FEATURES, true);

    long totalEntries = 0;
    for (int user = 0; user < USERS; user++) {
        String userID = "U" + user;
        model.setUserVector(userID, randomVector(random));
        int itemsPerUser = itemPerUserDist.sample();
        totalEntries += itemsPerUser;
        Collection<String> knownIDs = new ArrayList<>(itemsPerUser);
        for (int i = 0; i < itemsPerUser; i++) {
            knownIDs.add("I" + random.nextInt(ITEMS));
        }
        model.addKnownItems(userID, knownIDs);
    }

    for (int item = 0; item < ITEMS; item++) {
        model.setItemVector("I" + item, randomVector(random));
    }

    System.gc();
    long endMemory = JVMUtils.getUsedMemory();

    log.info("Built model over {} users, {} items, {} features, {} entries, using {}MB", USERS, ITEMS, FEATURES,
            totalEntries, (endMemory - startMemory) / 1_000_000);
    return model;
}

From source file:com.google.mr4c.content.ContentTypes.java

public static Collection<String> appendSuffixes(String name, String contentType) {
    Collection<String> result = new ArrayList<String>();
    for (String suffix : getSuffixes(contentType)) {
        result.add(name + "." + suffix);
    }/*from  w ww.  ja  v a2 s. c om*/
    return result;
}

From source file:Main.java

/**
 * Adds all elements in the enumeration to the given collection.
 * //from   w  ww.j a  v a  2 s.  co  m
 * @param collection
 *            the collection to add to
 * @param enumeration
 *            the enumeration of elements to add, may not be null
 * @throws NullPointerException
 *             if the collection or enumeration is null
 */
public static void addAll(Collection collection, Enumeration enumeration) {
    while (enumeration.hasMoreElements()) {
        collection.add(enumeration.nextElement());
    }
}

From source file:com.swtxml.util.lang.CollectionUtils.java

/**
 * Returns a new collection containing all elements from collection for
 * which filter.match(element) returned true.
 *//*from   w  w w  . j a v a  2  s  .  com*/
@SuppressWarnings("unchecked")
public static <A> Collection<A> select(Collection<? extends A> collection, IFilter<A> filter) {
    Collection<A> resultList = createCollection(collection);
    for (A a : collection) {
        if (filter.match(a)) {
            resultList.add(a);
        }
    }
    return resultList;
}

From source file:Main.java

private static void flatten(Collection<?> fromTreeList, Collection<Object> toFlatList) {
    for (Object item : fromTreeList) {
        if (item instanceof Collection<?>) {
            flatten((Collection<?>) item, toFlatList);
        } else {//from   www . j  a  v a  2 s. c o m
            toFlatList.add(item);
        }
    }
}

From source file:Main.java

/**
 * Subtract objects in collection b from collection a. The string value
 * of the object is used for comparisons.
 * /* w w  w .  java2s .c  om*/
 * @param a a collection that will have members removed
 * @param b a collection whose objects will be removed from a
 * @return a new collection that contains the remaining objects in a
 */
public static Collection subtractByString(Collection a, Collection b) {
    Collection retColl = new ArrayList();
    Object obj = null;
    Iterator it = a.iterator();
    while (it.hasNext()) {
        obj = it.next();
        if (!b.contains(obj)) {
            retColl.add(obj);
        }
    }
    return retColl;
}

From source file:com.egt.ejb.toolkit.ColUtils.java

public static <T> Collection<T> filter(Collection<T> collection, Predicado<T> predicate) {
    Collection<T> arrayList = new ArrayList<T>();
    for (T element : collection) {
        if (predicate.evaluate(element)) {
            arrayList.add(element);
        }//from w  w  w.  j a  v  a  2s.  c  o  m
    }
    return arrayList;
}

From source file:Main.java

@SafeVarargs
public static <T> boolean addAll(Collection<T> collection, T... toAdd) {
    int size = toAdd.length;
    boolean result = false;
    if (size > 0) {
        for (T element : toAdd)
            result |= collection.add(element);
    }//from  w  w w  .  java2s .  c  o m
    return result;
}

From source file:org.netxilia.api.impl.format.SheetValueListFormatter.java

public static StyleDefinition buildDefinition(Style id, StyleGroup group, String name, String description,
        WorkbookId workbook, AreaReference nameReference, AreaReference valueReference) {
    Collection<StyleAttribute> atts = new ArrayList<StyleAttribute>();
    atts.add(new StyleAttribute(ATT_WORKBOOK, workbook.getKey()));
    atts.add(new StyleAttribute(ATT_NAME_REF, nameReference.toString()));
    atts.add(new StyleAttribute(ATT_VALUE_REF, valueReference.toString()));
    atts.add(new StyleAttribute(StyleAttribute.EDITOR, "select"));
    // XXX: this pattern type should correspond to what is in the spring file
    atts.add(new StyleAttribute(StyleAttribute.PATTERN_TYPE, "values"));

    return new StyleDefinition(id, group, name, description, atts);
}

From source file:org.netxilia.api.impl.format.SheetValueListFormatter.java

public static StyleDefinition buildDefinition(Style id, StyleGroup group, String name, String description,
        WorkbookId workbook, AbsoluteAlias nameReference, AbsoluteAlias valueReference) {
    Collection<StyleAttribute> atts = new ArrayList<StyleAttribute>();
    atts.add(new StyleAttribute(ATT_WORKBOOK, workbook.getKey()));
    atts.add(new StyleAttribute(ATT_NAME_REF, nameReference.toString()));
    atts.add(new StyleAttribute(ATT_VALUE_REF, valueReference.toString()));
    atts.add(new StyleAttribute(StyleAttribute.EDITOR, "select"));
    // XXX: this pattern type should correspond to what is in the spring file
    atts.add(new StyleAttribute(StyleAttribute.PATTERN_TYPE, "values"));

    return new StyleDefinition(id, group, name, description, atts);
}