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:com.bemis.portal.customer.service.impl.CustomerProfileLocalServiceImpl.java

@Override
public Collection<String> getBemisCustomerIds() {
    Collection<CustomerProfile> parentLocations = getParentLocations();

    if ((parentLocations == null) || parentLocations.isEmpty()) {
        return Collections.emptySet();
    }/*w w w. ja  va2s.  co  m*/

    Collection<String> customerLocationIds = new ArrayList<>();

    for (CustomerProfile parentLocation : parentLocations) {
        customerLocationIds.addAll(getCustomerLocationBemisIds(parentLocation));
    }

    return customerLocationIds;
}

From source file:com.xebialabs.deployit.cli.ext.mustachify.DarEntryTransformerApplier.java

Collection<TFile> apply(Map<DarEntry, DarEntryTransformer> entriesToTransform) {
    Map<DarEntryTransformer, Iterable<TFile>> transformerWorkloads = transformValues(reduce(entriesToTransform),
            new ExpandDarEntries());

    Collection<TFile> transformedFiles = newLinkedList();
    for (Entry<DarEntryTransformer, Iterable<TFile>> transformerWorkload : transformerWorkloads.entrySet()) {
        // will force iteration of the iterable, but we're about to do that anyway
        Collection<TFile> filesToTransform = copyOf(transformerWorkload.getValue());
        try {/*  ww w.  jav a2  s . c  o  m*/
            apply(transformerWorkload.getKey(), filesToTransform);
            transformedFiles.addAll(filesToTransform);
        } catch (IOException exception) {
            LOGGER.warn("Unable to transform '{}' using '{}'", filesToTransform, transformerWorkload.getKey());
        }
    }
    return transformedFiles;
}

From source file:edu.uci.ics.jung.io.PajekNetWriter.java

/**
 * Writes <code>graph</code> to <code>w</code>.  Labels for vertices may
 * be supplied by <code>vs</code> (defaults to no labels if null), 
 * edge weights may be specified by <code>nev</code>
 * (defaults to weights of 1.0 if null), 
 * and vertex locations may be specified by <code>vld</code> (defaults
 * to no locations if null). //www.j a v  a2s. co m
 */
public void save(Graph<V, E> graph, Writer w, Transformer<V, String> vs, Transformer<E, Number> nev,
        Transformer<V, Point2D> vld) throws IOException {
    /*
     * TODO: Changes we might want to make:
     * - optionally writing out in list form
     */

    BufferedWriter writer = new BufferedWriter(w);
    if (nev == null)
        nev = new Transformer<E, Number>() {
            public Number transform(E e) {
                return 1;
            }
        };
    writer.write("*Vertices " + graph.getVertexCount());
    writer.newLine();

    List<V> id = new ArrayList<V>(graph.getVertices());//Indexer.getIndexer(graph);
    for (V currentVertex : graph.getVertices()) {
        // convert from 0-based to 1-based index
        int v_id = id.indexOf(currentVertex) + 1;
        writer.write("" + v_id);
        if (vs != null) {
            String label = vs.transform(currentVertex);
            if (label != null)
                writer.write(" \"" + label + "\"");
        }
        if (vld != null) {
            Point2D location = vld.transform(currentVertex);
            if (location != null)
                writer.write(" " + location.getX() + " " + location.getY() + " 0.0");
        }
        writer.newLine();
    }

    Collection<E> d_set = new HashSet<E>();
    Collection<E> u_set = new HashSet<E>();

    boolean directed = graph instanceof DirectedGraph;

    boolean undirected = graph instanceof UndirectedGraph;

    // if it's strictly one or the other, no need to create extra sets
    if (directed)
        d_set.addAll(graph.getEdges());
    if (undirected)
        u_set.addAll(graph.getEdges());
    if (!directed && !undirected) // mixed-mode graph
    {
        u_set.addAll(graph.getEdges());
        d_set.addAll(graph.getEdges());
        for (E e : graph.getEdges()) {
            if (graph.getEdgeType(e) == EdgeType.UNDIRECTED) {
                d_set.remove(e);
            } else {
                u_set.remove(e);
            }
        }
    }

    // write out directed edges
    if (!d_set.isEmpty()) {
        writer.write("*Arcs");
        writer.newLine();
    }
    for (E e : d_set) {
        int source_id = id.indexOf(graph.getEndpoints(e).getFirst()) + 1;
        int target_id = id.indexOf(graph.getEndpoints(e).getSecond()) + 1;
        float weight = nev.transform(e).floatValue();
        writer.write(source_id + " " + target_id + " " + weight);
        writer.newLine();
    }

    // write out undirected edges
    if (!u_set.isEmpty()) {
        writer.write("*Edges");
        writer.newLine();
    }
    for (E e : u_set) {
        Pair<V> endpoints = graph.getEndpoints(e);
        int v1_id = id.indexOf(endpoints.getFirst()) + 1;
        int v2_id = id.indexOf(endpoints.getSecond()) + 1;
        float weight = nev.transform(e).floatValue();
        writer.write(v1_id + " " + v2_id + " " + weight);
        writer.newLine();
    }
    writer.close();
}

From source file:edu.cornell.mannlib.vitro.webapp.sparql.GetClazzObjectProperties.java

public void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    if (!isAuthorizedToDisplayPage(request, response, SimplePermission.USE_MISCELLANEOUS_PAGES.ACTION)) {
        return;//w ww  .  j  ava2s.  c  o m
    }

    VitroRequest vreq = new VitroRequest(request);

    String vClassURI = vreq.getParameter("vClassURI");
    if (vClassURI == null || vClassURI.trim().equals("")) {
        return;
    }

    String respo = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
    respo += "<options>";

    ObjectPropertyDao odao = vreq.getUnfilteredWebappDaoFactory().getObjectPropertyDao();
    PropertyInstanceDao piDao = vreq.getUnfilteredWebappDaoFactory().getPropertyInstanceDao();
    VClassDao vcDao = vreq.getUnfilteredWebappDaoFactory().getVClassDao();

    // incomplete list of classes to check, but better than before
    List<String> superclassURIs = vcDao.getAllSuperClassURIs(vClassURI);
    superclassURIs.add(vClassURI);
    superclassURIs.addAll(vcDao.getEquivalentClassURIs(vClassURI));

    Map<String, PropertyInstance> propInstMap = new HashMap<String, PropertyInstance>();
    for (String classURI : superclassURIs) {
        Collection<PropertyInstance> propInsts = piDao.getAllPropInstByVClass(classURI);
        try {
            for (PropertyInstance propInst : propInsts) {
                propInstMap.put(propInst.getPropertyURI(), propInst);
            }
        } catch (NullPointerException ex) {
            continue;
        }
    }
    List<PropertyInstance> propInsts = new ArrayList<PropertyInstance>();
    propInsts.addAll(propInstMap.values());
    Collections.sort(propInsts);

    Iterator propInstIt = propInsts.iterator();
    HashSet opropURIs = new HashSet();
    while (propInstIt.hasNext()) {
        PropertyInstance pi = (PropertyInstance) propInstIt.next();
        if (!(opropURIs.contains(pi.getPropertyURI()))) {
            opropURIs.add(pi.getPropertyURI());
            ObjectProperty oprop = (ObjectProperty) odao.getObjectPropertyByURI(pi.getPropertyURI());
            if (oprop != null) {
                respo += "<option>" + "<key>" + oprop.getLocalName() + "</key>" + "<value>" + oprop.getURI()
                        + "</value>" + "</option>";
            }
        }
    }
    respo += "</options>";
    response.setContentType("text/xml");
    response.setCharacterEncoding("UTF-8");
    PrintWriter out = response.getWriter();

    out.println(respo);
    out.flush();
    out.close();
}

From source file:net.ontopia.topicmaps.query.toma.impl.basic.ResultSet.java

/**
 * Returns a new {@link ResultSet} that is the result of a merge operation of
 * the current {@link ResultSet} and the given one.
 * //from   w w w  . j av a  2  s  .co m
 * FIXME: this method has to be fixed, it does not produce correct results
 * for ResultSet that share more than one column.
 * 
 * @param rs the other {@link ResultSet} to be used for the merging.
 * @return a merged {@link ResultSet}.
 */
@SuppressWarnings("unchecked")
public ResultSet merge(ResultSet rs) {
    List<String> sharedCols = getSharedColumns(rs);
    if (sharedCols.isEmpty()) {
        return null;
    } else {
        String col = sharedCols.get(0);
        Collection vals1 = getValues(col);
        Collection vals2 = rs.getValues(col);

        vals1.addAll(vals2);
        ResultSet result = new ResultSet(1, true);
        result.setColumnName(0, col);

        for (Object o : vals1) {
            Row r = result.createRow();
            r.setLastValue(o);
            result.addRow(r);
        }

        return result;
    }
}

From source file:org.mitre.uma.service.impl.MatchAllClaimsOnAnyPolicy.java

@Override
public ClaimProcessingResult claimsAreSatisfied(ResourceSet rs, PermissionTicket ticket) {
    Collection<Claim> allUnmatched = new HashSet<>();
    for (Policy policy : rs.getPolicies()) {
        Collection<Claim> unmatched = checkIndividualClaims(policy.getClaimsRequired(),
                ticket.getClaimsSupplied());
        if (unmatched.isEmpty()) {
            // we found something that's satisfied the claims, let's go with it!
            return new ClaimProcessingResult(policy);
        } else {//from   w ww . j  a va  2  s  .  c  o  m
            // otherwise add it to the stack to send back
            allUnmatched.addAll(unmatched);
        }
    }

    // otherwise, tell the caller that we'll need some set of these fulfilled somehow
    return new ClaimProcessingResult(allUnmatched);
}

From source file:cl.b9.socialNetwork.jung.SNPajekNetWriter.java

/**
 * Writes <code>graph</code> to <code>w</code>.  Labels for vertices may
 * be supplied by <code>vs</code> (defaults to no labels if null), 
 * edge weights may be specified by <code>nev</code>
 * (defaults to weights of 1.0 if null), 
 * and vertex locations may be specified by <code>vld</code> (defaults
 * to no locations if null). /*ww w  .j  a v a2 s.com*/
 */
@SuppressWarnings("unchecked")
public void save(Graph<V, E> graph, Writer w, Transformer<V, String> vs, Transformer<E, Number> nev,
        Transformer<V, Point2D> vld, Transformer<V, String> shape) throws IOException {
    /*
     * TODO: Changes we might want to make:
     * - optionally writing out in list form
     */

    BufferedWriter writer = new BufferedWriter(w);
    if (nev == null)
        nev = new Transformer<E, Number>() {
            public Number transform(E e) {
                return 1;
            }
        };
    writer.write("*Vertices " + graph.getVertexCount());
    writer.newLine();

    List<V> id = new ArrayList<V>(graph.getVertices());//Indexer.getIndexer(graph);
    for (V currentVertex : graph.getVertices()) {
        // convert from 0-based to 1-based index
        int v_id = id.indexOf(currentVertex) + 1;
        writer.write("" + v_id);
        if (vs != null) {
            String label = vs.transform(currentVertex);
            if (label != null)
                writer.write(" \"" + label + "\"");
        }
        if (vld != null) {
            Point2D location = vld.transform(currentVertex);
            if (location != null)
                writer.write(" " + location.getX() + " " + location.getY());
        }
        if (shape != null) {
            writer.write(" " + shape.transform(currentVertex) + " x_fact 1");
        }
        writer.newLine();
    }

    Collection<E> d_set = new HashSet<E>();
    Collection<E> u_set = new HashSet<E>();

    boolean directed = graph instanceof DirectedGraph;

    boolean undirected = graph instanceof UndirectedGraph;

    // if it's strictly one or the other, no need to create extra sets
    if (directed)
        d_set.addAll(graph.getEdges());
    if (undirected)
        u_set.addAll(graph.getEdges());
    if (!directed && !undirected) // mixed-mode graph
    {
        u_set.addAll(graph.getEdges());
        d_set.addAll(graph.getEdges());
        for (E e : graph.getEdges()) {
            if (graph.getEdgeType(e) == EdgeType.UNDIRECTED) {
                d_set.remove(e);
            } else {
                u_set.remove(e);
            }
        }
    }

    // write out directed edges
    if (!d_set.isEmpty()) {
        writer.write("*Arcs");
        writer.newLine();
    }
    for (E e : d_set) {
        int source_id = id.indexOf(graph.getEndpoints(e).getFirst()) + 1;
        int target_id = id.indexOf(graph.getEndpoints(e).getSecond()) + 1;
        //            float weight = nev.get(e).floatValue();
        float weight = nev.transform(e).floatValue();
        writer.write(source_id + " " + target_id + " " + weight);
        writer.newLine();
    }

    // write out undirected edges
    if (!u_set.isEmpty()) {
        writer.write("*Edges");
        writer.newLine();
    }
    for (E e : u_set) {
        Pair<V> endpoints = graph.getEndpoints(e);
        int v1_id = id.indexOf(endpoints.getFirst()) + 1;
        int v2_id = id.indexOf(endpoints.getSecond()) + 1;
        //            float weight = nev.get(e).floatValue();
        float weight = nev.transform(e).floatValue();
        writer.write(v1_id + " " + v2_id + " " + weight);
        writer.newLine();
    }
    writer.close();
}

From source file:com.xchanging.support.batch.admin.service.SimpleJobService.java

public Collection<String> listJobs(int start, int count) {
    Collection<String> jobNames = new LinkedHashSet<String>(jobLocator.getJobNames());
    if (start + count > jobNames.size()) {
        jobNames.addAll(jobInstanceDao.getJobNames());
    }/*  w  w  w. ja v a 2s .c om*/
    if (start >= jobNames.size()) {
        start = jobNames.size();
    }
    if (start + count >= jobNames.size()) {
        count = jobNames.size() - start;
    }
    return new ArrayList<String>(jobNames).subList(start, start + count);
}

From source file:com.xchanging.support.batch.admin.service.SimpleJobService.java

public Collection<StepExecution> getStepExecutions(Long jobExecutionId) throws NoSuchJobExecutionException {

    JobExecution jobExecution = jobExecutionDao.getJobExecution(jobExecutionId);
    if (jobExecution == null) {
        throw new NoSuchJobExecutionException("No JobExecution with id=" + jobExecutionId);
    }/* w  ww  .  ja  v  a2s .  co  m*/

    stepExecutionDao.addStepExecutions(jobExecution);

    String jobName = jobExecution.getJobInstance() == null ? null : jobExecution.getJobInstance().getJobName();
    Collection<String> missingStepNames = new LinkedHashSet<String>();

    if (jobName != null) {
        missingStepNames.addAll(stepExecutionDao.findStepNamesForJobExecution(jobName, "*:partition*"));
        logger.debug("Found step executions in repository: " + missingStepNames);
    }

    Job job = null;
    try {
        job = jobLocator.getJob(jobName);
    } catch (NoSuchJobException e) {
        // expected
    }
    if (job instanceof StepLocator) {
        Collection<String> stepNames = ((StepLocator) job).getStepNames();
        missingStepNames.addAll(stepNames);
        logger.debug("Added step executions from job: " + missingStepNames);
    }

    for (StepExecution stepExecution : jobExecution.getStepExecutions()) {
        String stepName = stepExecution.getStepName();
        if (missingStepNames.contains(stepName)) {
            missingStepNames.remove(stepName);
        }
        logger.debug("Removed step executions from job execution: " + missingStepNames);
    }

    for (String stepName : missingStepNames) {
        StepExecution stepExecution = jobExecution.createStepExecution(stepName);
        stepExecution.setStatus(BatchStatus.UNKNOWN);
    }

    return jobExecution.getStepExecutions();

}

From source file:edu.uci.ics.jung.io.CustomPajekNetWriter.java

/**
 * Writes <code>graph</code> to <code>w</code>. Labels for vertices may be
 * supplied by <code>vs</code> (defaults to no labels if null), edge weights
 * may be specified by <code>nev</code> (defaults to weights of 1.0 if
 * null), and vertex locations may be specified by <code>vld</code>
 * (defaults to no locations if null).//ww  w  .  j a v a2s. c o m
 */
public void save(MyGraph<V, E> graph, Writer w, Transformer<V, String> vs, Transformer<E, Number> nev,
        Transformer<V, Point2D> vld) throws IOException {
    /*
     * TODO: Changes we might want to make:
     * - optionally writing out in list form
     */

    BufferedWriter writer = new BufferedWriter(w);
    if (nev == null) {
        nev = new Transformer<E, Number>() {
            public Number transform(E e) {
                return 1;
            }
        };
    }
    writer.write("*Colors " + graph.getLayoutParameters().getBackgroundColorRgb() + ","
            + graph.getLayoutParameters().getEdgeColorRgb());
    writer.newLine();
    writer.write(
            "*Vertices " + graph.getVertexCount() + "," + graph.getLayoutParameters().areNodeIconsAllowed());
    writer.newLine();

    List<V> id = new ArrayList<V>(graph.getVertices());//Indexer.getIndexer(graph);
    for (V currentVertex : graph.getVertices()) {
        // convert from 0-based to 1-based index
        int v_id = id.indexOf(currentVertex) + 1;
        writer.write("" + v_id);
        if (vs != null) {
            String label = vs.transform(currentVertex);
            if (label != null) {
                writer.write(" \"" + label + "\"");
            }
        }
        if (vld != null) {
            Point2D location = vld.transform(currentVertex);
            if (location != null) {
                writer.write(" " + location.getX() + " " + location.getY() + " 0.0");
            }
        }
        writer.newLine();
    }

    Collection<E> d_set = new HashSet<E>();
    Collection<E> u_set = new HashSet<E>();

    boolean directed = graph instanceof DirectedGraph;

    boolean undirected = graph instanceof UndirectedGraph;

    // if it's strictly one or the other, no need to create extra sets
    if (directed) {
        d_set.addAll(graph.getEdges());
    }
    if (undirected) {
        u_set.addAll(graph.getEdges());
    }
    if (!directed && !undirected) // mixed-mode graph
    {
        u_set.addAll(graph.getEdges());
        d_set.addAll(graph.getEdges());
        for (E e : graph.getEdges()) {
            if (graph.getEdgeType(e) == EdgeType.UNDIRECTED) {
                d_set.remove(e);
            } else {
                u_set.remove(e);
            }
        }
    }

    // write out directed edges
    if (!d_set.isEmpty()) {
        writer.write("*Arcs");
        writer.newLine();
    }
    for (E e : d_set) {
        int source_id = id.indexOf(graph.getEndpoints(e).getFirst()) + 1;
        int target_id = id.indexOf(graph.getEndpoints(e).getSecond()) + 1;
        float weight = nev.transform(e).floatValue();
        writer.write(source_id + " " + target_id + " " + weight);
        writer.newLine();
    }

    // write out undirected edges
    if (!u_set.isEmpty()) {
        writer.write("*Edges");
        writer.newLine();
    }
    for (E e : u_set) {
        Pair<V> endpoints = graph.getEndpoints(e);
        int v1_id = id.indexOf(endpoints.getFirst()) + 1;
        int v2_id = id.indexOf(endpoints.getSecond()) + 1;
        float weight = nev.transform(e).floatValue();
        writer.write(v1_id + " " + v2_id + " " + weight);
        writer.newLine();
    }
    writer.close();
}