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:fr.lirmm.graphik.util.MathUtils.java

/**
 * Comput the cartesian product of the specified set with itself.
 * input: { A, B, C }//  ww w  . ja v a 2s. c  o  m
 * output : { (A,A), (A,B), (B,B) } 
 * @param set
 * @return
 */
public static <T> Iterable<Pair<T, T>> selfCartesianProduct(Iterable<T> set) {
    Collection<Pair<T, T>> pairs = new LinkedList<Pair<T, T>>();

    Iterator<T> it = set.iterator();
    while (it.hasNext()) {
        T a = it.next();
        for (T b : set) {
            pairs.add(new ImmutablePair<T, T>(a, b));
        }

        if (it.hasNext()) { // FIXfor singleton implementation
            it.remove();
        }
    }
    return pairs;
}

From source file:de.dhke.projects.cutil.collections.MultiMapUtil.java

public static <V> Collection<V> getTransitive(final MultiMap<V, V> multiMap, final V key,
        final Collection<V> targetSet) {
    Collection<V> keyValues = multiMap.get(key);
    if (keyValues != null) {
        for (V keyValue : keyValues) {
            if (!targetSet.contains(keyValue)) {
                targetSet.add(keyValue);
                targetSet.addAll(getTransitive(multiMap, keyValue, targetSet));
            }//  ww w .j  a  v  a 2s . co m
        }
    }
    return targetSet;
}

From source file:org.biopax.psidev.ontology_manager.impl.OntologyManagerImpl.java

/**
 * Collect all available names in the given collection of OntologyAccess terms.
 * @param terms the terms for which we want the names.
 * @return a non null collection of names.
 *//*from   w  w w  .  j  a  va2  s  . c  om*/
protected static Collection<String> getTermNames(Collection<OntologyTermI> terms) {
    if (terms == null) {
        return Collections.emptyList();
    }
    Collection<String> names = new ArrayList<String>(terms.size());
    for (OntologyTermI term : terms) {
        names.add(term.getPreferredName());
        names.addAll(term.getNameSynonyms());
    }
    return names;
}

From source file:com.splicemachine.triggers.Trigger_Create_IT.java

@Parameterized.Parameters
public static Collection<Object[]> data() {
    Collection<Object[]> params = Lists.newArrayListWithCapacity(2);
    params.add(new Object[] { "jdbc:splice://localhost:1527/splicedb;create=true;user=splice;password=admin" });
    params.add(new Object[] {
            "jdbc:splice://localhost:1527/splicedb;create=true;user=splice;password=admin;useSpark=true" });
    return params;
}

From source file:com.tacitknowledge.noexcuses.TestManager.java

/**
 * The internal instance map will return an object of a particular instance once one is found
 * in a parameter. For instance (NPI): if your object has a constructor that uses an
 * interface, you can supply in the instance map an implementation of that interface,
 * with the interface.class as key. Then when that interface is found the appropriate
 * object is created for the dummy./*w  ww .ja v  a 2  s  . co m*/
 * 
 * This method, in contrast to the {@link TestManager#testConstruction(Class, Map)}, uses
 * already existing <code>instanceMap</code> entity.
 * 
 * @param <T> the type of class element to test constructor method on
 * @param toTest the subject of construction testing, i.e. class to undergo
 *      the process of constructor testing
 * @return collection of constructed objects
 */
@SuppressWarnings("unchecked")
public static <T> Collection<T> testConstruction(Class<T> toTest) {
    DummyObjectBuilder dummyObjectBuilder = new DummyObjectBuilder(myInstances,
            ClassTypeHandlerChain.defaultTypeChain());
    Collection<T> instances = new ArrayList<T>();
    Constructor<T>[] constructors = (Constructor<T>[]) toTest.getConstructors();

    for (Constructor<T> constructor : constructors) {
        instances.add(dummyObjectBuilder.createInstance(constructor));
    }

    return instances;
}

From source file:Main.java

public static <T> Collection<T> getObjectsOfType(Collection<?> input, Class<T> type, Collection<T> output) {
    if (output == null) {
        output = createEmpty(input);/* w  w w. j a v a2  s  .  c  o  m*/
        if (output == null)
            output = new ArrayList<T>();
    }
    for (Object o : input) {
        if (type.isAssignableFrom(o.getClass()))
            output.add((T) o);
    }
    return output;
}

From source file:com.icfcc.cache.annotation.SpringCacheAnnotationParser.java

private static <T extends Annotation> Collection<T> getAnnotations(AnnotatedElement ae,
        Class<T> annotationType) {
    Collection<T> anns = new ArrayList<T>(2);

    // look at raw annotation
    T ann = ae.getAnnotation(annotationType);
    if (ann != null) {
        anns.add(ann);
    }/*  w ww  .j a v a 2 s.  c  om*/

    // scan meta-annotations
    for (Annotation metaAnn : ae.getAnnotations()) {
        ann = metaAnn.annotationType().getAnnotation(annotationType);
        if (ann != null) {
            anns.add(ann);
        }
    }

    return (anns.isEmpty() ? null : anns);
}

From source file:com.goldengekko.meetr.service.salesforce.ContactClient.java

protected static Collection<DmContact> convert(SalesforceContact[] contacts) {
    final Collection<DmContact> to = new ArrayList<DmContact>();
    for (SalesforceContact con : contacts) {
        to.add(convert(con));
    }/*w w w  .  j  a v a  2s.c om*/
    return to;
}

From source file:com.glaf.core.util.AnnotationUtils.java

public static Collection<String> findJPAEntity(String packagePrefix) {
    AnnotationDB db = getAnnotationDB(packagePrefix);
    Map<String, Set<String>> annotationIndex = db.getAnnotationIndex();
    Set<String> entities = annotationIndex.get("javax.persistence.Entity");
    Collection<String> sortSet = new TreeSet<String>();
    if (entities != null && !entities.isEmpty()) {
        for (String str : entities) {
            if (packagePrefix != null && str.contains(packagePrefix)) {
                sortSet.add(str);
            }/*from   w w  w .  j  av  a 2  s  . c  o  m*/
        }
    }
    return sortSet;
}

From source file:com.confighub.core.utils.FileUtils.java

public static Collection<String> getKeys(final String text) {
    Collection<String> keys = new HashSet<>();
    Matcher m = keyNoDefault.matcher(text);
    while (m.find())
        keys.add(m.group(1).trim());

    return keys;//from   w  w  w .  j a  v a2  s. c om
}