Example usage for java.util Collection addAll

List of usage examples for java.util Collection addAll

Introduction

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

Prototype

boolean addAll(Collection<? extends E> c);

Source Link

Document

Adds all of the elements in the specified collection to this collection (optional operation).

Usage

From source file:fr.jayasoft.ivy.Main.java

private static void outputCachePath(Ivy ivy, File cache, ModuleDescriptor md, String[] confs, String outFile) {
    try {//from   w w w  .ja v a2s.c  om
        String pathSeparator = System.getProperty("path.separator");
        StringBuffer buf = new StringBuffer();
        XmlReportParser parser = new XmlReportParser();
        Collection all = new LinkedHashSet();
        for (int i = 0; i < confs.length; i++) {
            Artifact[] artifacts = parser.getArtifacts(md.getModuleRevisionId().getModuleId(), confs[i], cache);
            all.addAll(Arrays.asList(artifacts));
        }
        for (Iterator iter = all.iterator(); iter.hasNext();) {
            Artifact artifact = (Artifact) iter.next();
            buf.append(ivy.getArchiveFileInCache(cache, artifact).getCanonicalPath());
            if (iter.hasNext()) {
                buf.append(pathSeparator);
            }
        }
        PrintWriter writer = new PrintWriter(new FileOutputStream(outFile));
        writer.println(buf.toString());
        writer.close();
        System.out.println("cachepath output to " + outFile);

    } catch (Exception ex) {
        throw new RuntimeException("impossible to build ivy cache path: " + ex.getMessage(), ex);
    }
}

From source file:gov.nih.nci.caarray.application.translation.geosoft.GeoSoftFileWriterUtil.java

private static void collectAllProtocols(Set<? extends ProtocolApplicable> nodes,
        Collection<ProtocolApplication> dest) {
    for (final ProtocolApplicable pa : nodes) {
        dest.addAll(pa.getProtocolApplications());
    }/*from   www . j av a 2s  . c o m*/
}

From source file:com.google.code.guice.repository.spi.TypeUtil.java

public static void getGenericSuperclassActualTypes(Collection<Type> types, Class aClass) {
    if (aClass != null && types != null) {
        Type superclass = aClass.getGenericSuperclass();
        if (superclass instanceof ParameterizedType) {
            ParameterizedType parameterizedType = (ParameterizedType) superclass;
            Type[] interfaces = parameterizedType.getActualTypeArguments();
            types.addAll(Arrays.asList(interfaces));
        } else if (superclass instanceof Class) {
            Class sClass = (Class) superclass;
            getGenericInterfacesActualTypes(types, sClass);
            getGenericSuperclassActualTypes(types, aClass.getSuperclass());
        }//from  ww  w  .ja  v  a 2 s  . co  m
    }
}

From source file:edu.sdsc.scigraph.services.jersey.writers.BbopJsGraphWriter.java

static Collection<String> getCategories(Vertex vertex) {
    Collection<String> categories = new HashSet<>();
    if (vertex.getPropertyKeys().contains(Concept.CATEGORY)) {
        Object value = vertex.getProperty(Concept.CATEGORY);
        if (value.getClass().isArray()) {
            for (int i = 0; i < Array.getLength(value); i++) {
                categories.add((String) Array.get(value, i));
            }//  ww  w  .  jav a 2s  .  c  o m
        } else if (value instanceof Iterable) {
            categories.addAll(newArrayList((Iterable<String>) value));
        } else {
            categories.add((String) value);
        }
    }
    return categories;
}

From source file:fr.jayasoft.ivy.Main.java

private static void invoke(Ivy ivy, File cache, ModuleDescriptor md, String[] confs, String mainclass,
        String[] args) {//from   ww w. j  ava  2s.  c om
    List urls = new ArrayList();

    try {
        XmlReportParser parser = new XmlReportParser();
        Collection all = new LinkedHashSet();
        for (int i = 0; i < confs.length; i++) {
            Artifact[] artifacts = parser.getArtifacts(md.getModuleRevisionId().getModuleId(), confs[i], cache);
            all.addAll(Arrays.asList(artifacts));
        }
        for (Iterator iter = all.iterator(); iter.hasNext();) {
            Artifact artifact = (Artifact) iter.next();

            urls.add(ivy.getArchiveFileInCache(cache, artifact).toURL());
        }
    } catch (Exception ex) {
        throw new RuntimeException("impossible to build ivy cache path: " + ex.getMessage(), ex);
    }

    URLClassLoader classLoader = new URLClassLoader((URL[]) urls.toArray(new URL[urls.size()]),
            Main.class.getClassLoader());

    try {
        Class c = classLoader.loadClass(mainclass);

        Method mainMethod = c.getMethod("main", new Class[] { String[].class });

        // Split up arguments 
        mainMethod.invoke(null, new Object[] { args });
    } catch (ClassNotFoundException cnfe) {
        throw new RuntimeException("Could not find class: " + mainclass, cnfe);
    } catch (SecurityException e) {
        throw new RuntimeException("Could not find main method: " + mainclass, e);
    } catch (NoSuchMethodException e) {
        throw new RuntimeException("Could not find main method: " + mainclass, e);
    } catch (IllegalAccessException e) {
        throw new RuntimeException("No permissions to invoke main method: " + mainclass, e);
    } catch (InvocationTargetException e) {
        throw new RuntimeException("Unexpected exception invoking main method: " + mainclass, e);
    }
}

From source file:io.agi.framework.persistence.PersistenceUtil.java

protected static void AddEntityData(String entityName, Collection<ModelData> modelDatas) {

    Node node = Node.NodeInstance();
    DataRefMap map = node.getDataRefMap();

    ModelEntity modelEntity = node.getPersistence().getEntity(entityName);

    Entity entity = node.getEntityFactory().create(node.getObjectMap(), modelEntity);
    entity.setConfig(entity.createConfig()); // create a blank config object

    Collection<String> attributesOut = new ArrayList<>();
    Collection<String> attributesIn = new ArrayList<>();

    DataFlags dataFlags = new DataFlags();
    entity.getOutputAttributes(attributesOut, dataFlags);
    entity.getInputAttributes(attributesIn);

    Collection<String> attributes = new ArrayList<>();
    attributes.addAll(attributesIn);
    attributes.addAll(attributesOut);//from   w w  w. j a  v  a 2s .c  om

    for (String attribute : attributes) {
        String outputKey = entity.getKey(attribute);
        //ModelData modelData = node.getModelData( outputKey, new DataRef.DenseDataRefResolver() );
        DataRef dataRef = map.getData(outputKey);
        ModelData modelData = new ModelData();
        boolean b = modelData.serialize(dataRef);
        if (b) {
            modelDatas.add(modelData);
        }
    }
}

From source file:com.siemens.sw360.datahandler.common.CommonUtils.java

/**
 * Add all from right to left collection
 *//*from w  w w  .  ja  v a 2s .c o  m*/
public static <T> void addAll(Collection<T> left, Collection<T> right) {
    if (left != null && right != null) {
        left.addAll(right);
    }
}

From source file:ch.sdi.core.impl.cfg.ConfigUtils.java

/**
 * Returns a collection of all property names in the given PropertySource.
 * <p>//from   w  ww . jav a  2  s  .co m
 * @param aPropSource
 * @return
 */
public static Collection<String> getAllPropertyNames(PropertySource<?> aPropSource) {
    Collection<String> result = new HashSet<>();

    if (aPropSource instanceof CompositePropertySource) {
        CompositePropertySource cps = (CompositePropertySource) aPropSource;
        cps.getPropertySources().forEach(ps -> result.addAll(getAllPropertyNames(ps)));
        return result;
    }

    if (aPropSource instanceof EnumerablePropertySource<?>) {
        EnumerablePropertySource<?> ps = (EnumerablePropertySource<?>) aPropSource;
        Arrays.asList(ps.getPropertyNames()).forEach(key -> result.add(key));
        return result;
    }

    // note: Most descendants of PropertySource are EnumerablePropertySource. There are some
    // few others like JndiPropertySource or StubPropertySource
    myLog.debug("Given PropertySource is instanceof " + aPropSource.getClass().getName()
            + " and cannot be iterated");

    return result;
}

From source file:com.evolveum.midpoint.util.MiscUtil.java

/**
 * Only zero vs non-zero value of comparator is important. 
 *///from  w  ww.j a  va2 s.  com
public static boolean unorderedCollectionEquals(Collection a, Collection b, Comparator comparator) {
    if (a == null && b == null) {
        return true;
    }
    if (a == null || b == null) {
        return false;
    }
    if (a.size() != b.size()) {
        return false;
    }
    Collection outstanding = new ArrayList(b.size());
    outstanding.addAll(b);
    for (Object ao : a) {
        boolean found = false;
        Iterator iterator = outstanding.iterator();
        while (iterator.hasNext()) {
            Object oo = iterator.next();
            if (comparator.compare(ao, oo) == 0) {
                iterator.remove();
                found = true;
            }
        }
        if (!found) {
            return false;
        }
    }
    if (!outstanding.isEmpty()) {
        return false;
    }
    return true;
}

From source file:edu.mayo.cts2.framework.webapp.service.ServiceUtils.java

/**
 * Find annotations./*from  www .  j a va2  s  .co m*/
 *
 * @param <A> the generic type
 * @param clazz the clazz
 * @param annotationType the annotation type
 * @return the collection
 */
public static <A extends Annotation> Collection<A> findAnnotations(Class<?> clazz, Class<A> annotationType) {
    Collection<A> returnCollection = new HashSet<A>();

    Assert.notNull(clazz, "Class must not be null");
    A annotation = clazz.getAnnotation(annotationType);
    if (annotation != null) {
        returnCollection.add(annotation);
    }

    for (Class<?> ifc : clazz.getInterfaces()) {
        Collection<A> annotations = findAnnotations(ifc, annotationType);
        if (annotations != null) {
            returnCollection.addAll(annotations);
        }
    }
    if (!Annotation.class.isAssignableFrom(clazz)) {
        for (Annotation ann : clazz.getAnnotations()) {
            Collection<A> annotations = findAnnotations(ann.annotationType(), annotationType);
            if (annotations != null) {
                returnCollection.addAll(annotations);
            }
        }
    }
    Class<?> superClass = clazz.getSuperclass();
    if (superClass == null || superClass == Object.class) {
        return returnCollection;
    }

    returnCollection.addAll(findAnnotations(superClass, annotationType));

    return returnCollection;
}