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:Main.java

/**
 * Adds all objects into the specified list.
 *
 * @param collection list to fill// w  w  w .java2s . c om
 * @param objects    objects
 * @param <T>        objects type
 * @return true if list changed as the result of this operation, false otherwise
 */
public static <T> boolean addAll(final Collection<T> collection, final Collection<T> objects) {
    boolean result = false;
    for (final T object : objects) {
        if (!collection.contains(object)) {
            result |= collection.add(object);
        }
    }
    return result;
}

From source file:Main.java

private static void getChildrenByName(Node node, String name, Collection<Node> nodes) {
    NodeList list = node.getChildNodes();
    for (int i = 0, len = list.getLength(); i < len; i++) {
        Node child = list.item(i);
        if (child.getNodeName().equalsIgnoreCase(name)) {
            nodes.add(child);
        }// w w w  .  j av  a2 s . co  m
    }
}

From source file:Main.java

public static <T> Collection<T> flatten(Collection<T> original) {
    // First see if there are no nested collections
    // and in this case just return this

    boolean hasNested = false;
    for (Object o : original) {
        if (o instanceof Collection) {
            hasNested = true;// w  w  w  .  java  2  s .c  o m
            break;
        }
    }

    if (!hasNested)
        return original;

    // If there are nested collections

    Collection<T> flattened = createDefaultList();
    for (T next : original) {
        if (next instanceof Collection) {
            flattened.addAll(flatten((Collection<T>) next));
        } else {
            flattened.add(next);
        }
    }
    return flattened;
}

From source file:grails.plugin.searchable.internal.compass.mapping.SearchableGrailsDomainClassCompassMappingUtils.java

/**
 * Get the mapping aliases for the given user-defined domain class and its subclasses if any
 * @param compass Compass instance//from w w w . j  a  v a 2  s.  c o m
 * @param clazz the user-defined domain class
 * @param application the GrailsApplication
 * @return the Compass aliases for the hierarchy
 */
public static String[] getPolyMappingAliases(Compass compass, Class clazz, GrailsApplication application) {
    List grailsDomainClasses = Arrays.asList(application.getArtefacts(DomainClassArtefactHandler.TYPE));
    GrailsDomainClass grailsDomainClass = GrailsDomainClassUtils.getGrailsDomainClass(clazz,
            grailsDomainClasses);
    Collection clazzes = new HashSet(GrailsDomainClassUtils.getClazzes(grailsDomainClass.getSubClasses()));
    clazzes.add(clazz);
    return CompassMappingUtils.getMappingAliases(compass, clazzes);
}

From source file:com.mtnfog.test.entity.utils.EntityUtils.java

/**
 * Creates a list of 10 random person entities.
 * @return A list of 10 random person entities.
 *///from www  . ja  va 2s  .c  o m
public static Collection<Entity> createRandomPersonEntities() {

    Collection<Entity> entities = new ArrayList<Entity>();

    for (int i = 0; i < 10; i++) {

        entities.add(createRandomPersonEntity());

    }

    return entities;

}

From source file:security.Authority.java

public static Collection<Authority> listAuthorities() {
    Collection<Authority> result;
    Authority authority;// ww w .  j  a v  a  2  s.c om

    result = new ArrayList<Authority>();

    authority = new Authority();
    authority.setAuthority(ADMIN);
    result.add(authority);

    authority = new Authority();
    authority.setAuthority(CONSUMER);
    result.add(authority);

    authority = new Authority();
    authority.setAuthority(CLERK);
    result.add(authority);

    return result;
}

From source file:com.mtnfog.test.entity.utils.EntityUtils.java

/**
 * Creates a list of random person entities.
 * @return A list of random person entities.
 *//*from  w  ww. j  a v  a2 s  .  c  om*/
public static Collection<Entity> createRandomPersonEntities(int count) {

    Collection<Entity> entities = new ArrayList<Entity>();

    for (int i = 0; i < count; i++) {

        entities.add(createRandomPersonEntity());

    }

    return entities;

}

From source file:Main.java

public static <T> boolean addAll(Collection<T> collection, Collection<? extends T> toAdd) {
    int size = toAdd.size();
    boolean result = false;
    if (size > 0) {
        if (size < 10)
            for (T element : toAdd)
                result |= collection.add(element);
        else/*from   w  ww  .j a va 2  s  .com*/
            result = collection.addAll(toAdd);
    }
    return result;
}

From source file:com.epam.reportportal.spock.NodeInfoUtilsTest.java

private static Collection<String> generateBlockTexts(int count) {
    Collection<String> texts = Lists.newArrayListWithCapacity(count);
    for (int i = 0; i < count; i++) {
        texts.add(RandomStringUtils.randomAlphabetic(40));
    }/*ww  w . ja  v a 2s.co  m*/
    return texts;
}

From source file:edu.byu.nlp.util.Iterables2.java

/**
 * Provides the same functionality as guava's Iterables.partition() but without a couple of 
 * shortcomings: handles split size 0, and the second collection can be bigger or smaller 
 * than the first./*w  w  w.jav a 2  s . c o m*/
 */
@SuppressWarnings("unchecked")
public static <I> Iterable<? extends Collection<I>> partition(Collection<I> labeledData, int splitSize) {
    Iterator<I> itr = labeledData.iterator();
    Collection<I> first = Lists.newArrayList();
    for (int cnt = 0; itr.hasNext() && cnt < splitSize; cnt++) {
        first.add(itr.next());
    }
    Collection<I> second = Lists.newArrayList();
    while (itr.hasNext()) {
        second.add(itr.next());
    }
    return Lists.newArrayList(first, second);
}