Example usage for org.apache.commons.collections CollectionUtils union

List of usage examples for org.apache.commons.collections CollectionUtils union

Introduction

In this page you can find the example usage for org.apache.commons.collections CollectionUtils union.

Prototype

public static Collection union(final Collection a, final Collection b) 

Source Link

Document

Returns a Collection containing the union of the given Collection s.

Usage

From source file:org.eurekastreams.server.service.actions.strategies.activity.OrSortedListColliderTest.java

/**
 * Helper method, tests against apache commons union.
 * /*from   w w  w.jav a 2 s.c om*/
 * @param a
 *            a sorted list.
 * @param b
 *            a sorted list.
 * @param maxResults
 *            the max results.
 */
@SuppressWarnings("unchecked")
private static void collideTest(final Long[] a, final Long[] b, final int maxResults) {
    List<Long> listA = Arrays.asList(a);
    List<Long> listB = Arrays.asList(b);

    Collection<Long> expected = CollectionUtils.union(listA, listB);

    List<Long> actual = collider.collide(listA, listB, maxResults);

    Assert.assertEquals(expected.size(), actual.size());

    Assert.assertTrue(actual.size() <= maxResults);

    for (int i = 0; i < actual.size(); i++) {
        Long actualItem = actual.get(i);

        // Confirm sort order is correct
        if (i > 0) {
            Assert.assertTrue(actualItem <= actual.get(i - 1));
        }

        Assert.assertTrue(expected.contains(actualItem));
    }
}

From source file:org.jannocessor.collection.impl.PowerArrayList.java

@SuppressWarnings("unchecked")
@Override/*from  www  .j ava 2 s  .  com*/
public PowerList<E> getUnion(Collection<E> list) {
    return powerList(CollectionUtils.union(this, list));
}

From source file:org.jannocessor.collection.impl.PowerLinkedHashSet.java

@SuppressWarnings("unchecked")
public PowerSet<E> getUnion(Collection<E> Set) {
    return powerSet(CollectionUtils.union(this, Set));
}

From source file:org.jenkinsci.plugins.neoload.integration.NeoBuildAction.java

/**
 * Here we search the global config for settings that have the same uniqueID. If the same uniqueID is found then we use those
 * settings instead of our own because they are more up to date. This is because all server info is stored and duplicated here.
 * We don't ONLY store the uniqueID because we don't want the project to break if someone deletes the global config.
 *
 * @param <T>        the type parameter
 * @param serverInfo the server info// w  ww.ja va  2  s  .  com
 * @return t t
 */
@SuppressWarnings("unchecked")
<T extends ServerInfo> T updateUsingUniqueID(final T serverInfo) {
    if (serverInfo == null || StringUtils.trimToNull(serverInfo.getUniqueID()) == null) {
        return serverInfo;
    }

    if (Jenkins.getInstance() == null) {
        return serverInfo;
    }
    final NeoGlobalConfig.DescriptorImpl globalConfigDescriptor = PluginUtils.getNeoGlobalConfig();

    if (globalConfigDescriptor == null) {
        // no change necessary.
        return serverInfo;
    }

    // search for the same uniqueID
    final Collection<ServerInfo> allServerInfo = CollectionUtils.union(globalConfigDescriptor.getNtsInfo(),
            globalConfigDescriptor.getCollabInfo());
    for (final ServerInfo si : allServerInfo) {
        if (si.getUniqueID().equals(serverInfo.getUniqueID())) {
            // we found the same uniqueID so we return the copy from the global config.
            return (T) si;
        }
    }

    return serverInfo;
}

From source file:org.jenkinsci.plugins.neoload.integration.supporting.PluginUtils.java

public Object convert(@SuppressWarnings("rawtypes") final Class type, final Object value) {
    // get the main config.
    final NeoGlobalConfig.DescriptorImpl globalConfigDescriptor = getNeoGlobalConfig();

    if (globalConfigDescriptor == null) {
        LOGGER.log(Level.FINEST,/* www . j a  v a2  s  .co  m*/
                "No NeoLoad server settings found. Please add servers before configuring jobs. (getLicenseServerOptions)");
        return null;
    }

    // find the serverInfo based on the unique ID.
    @SuppressWarnings("unchecked")
    final Collection<ServerInfo> allServerInfo = CollectionUtils.union(globalConfigDescriptor.getNtsInfo(),
            globalConfigDescriptor.getCollabInfo());
    for (final ServerInfo si : allServerInfo) {
        if (si.getUniqueID().equals(value)) {
            return si;
        }
    }
    return null;
}

From source file:org.medici.bia.controller.manuscriptviewer.AjaxController.java

/**
 * @param entryId/*  w w  w.j av a2s .c om*/
 * @param volNum
 * @param volLetExt
 * @param imageType
 * @param imageProgTypeNum
 * @param imageOrder
 * @param imageName
 * @param total
 * @param totalRubricario
 * @param totalCarta
 * @param totalAppendix
 * @param totalOther
 * @param totalGuardia
 * @param modeEdit
 * @param request
 * @return
 */
@RequestMapping(value = { "/src/mview/GetLinkedDocument.json",
        "/de/mview/GetLinkedDocument.json" }, method = RequestMethod.GET)
public ModelAndView findLinkedDocument(@RequestParam(value = "entryId", required = false) Integer entryId,
        @RequestParam(value = "volNum", required = false) Integer volNum,
        @RequestParam(value = "volLetExt", required = false) String volLetExt,
        @RequestParam(value = "imageType", required = false) String imageType,
        @RequestParam(value = "imageProgTypeNum", required = false) Integer imageProgTypeNum,
        @RequestParam(value = "imageOrder", required = false) Integer imageOrder,
        @RequestParam(value = "imageName", required = false) String imageName,
        @RequestParam(value = "total", required = false) Long total,
        @RequestParam(value = "totalRubricario", required = false) Long totalRubricario,
        @RequestParam(value = "totalCarta", required = false) Long totalCarta,
        @RequestParam(value = "totalAppendix", required = false) Long totalAppendix,
        @RequestParam(value = "totalOther", required = false) Long totalOther,
        @RequestParam(value = "totalGuardia", required = false) Long totalGuardia,
        @RequestParam(value = "modeEdit", required = false) Boolean modeEdit, HttpServletRequest request) {
    Map<String, Object> model = new HashMap<String, Object>(0);

    try {
        Integer documentId = null;
        List<Document> linkedDocumentOnStartFolio = null;
        List<Document> linkedDocumentOnTranscribeFolio = null;
        boolean isExtract = false;
        Image image = new Image();

        int intersectionSize = 0;
        int unionSize = 0;

        //         if (entryId != null) {
        //            documentId = entryId;
        //         } else {
        if (org.medici.bia.common.util.StringUtils.safeTrim(imageType) != null
                && !"C".equals(imageType.trim())) {
            model.put("error", "wrongType");
        } else {
            // We extract image
            image = getManuscriptViewerService().findVolumeImage(null, volNum, volLetExt,
                    (imageType != null) ? ImageType.valueOf(imageType) : null, imageProgTypeNum, imageOrder);

            if (image != null) {
                model.put("imageName", image.getImageName());
                model.put("imageId", image.getImageId());
                model.put("imageType", image.getImageType());
                model.put("imageOrder", image.getImageOrder());

                if (!ImageType.C.equals(image.getImageType())) {
                    model.put("error", "wrongType");
                } else {
                    // We check if this image has linked document on start folio...
                    linkedDocumentOnStartFolio = getManuscriptViewerService()
                            .findLinkedDocumentOnStartFolioWithOrWithoutRectoVerso(volNum, volLetExt,
                                    image.getInsertNum(), image.getInsertLet(), image.getImageProgTypeNum(),
                                    image.getMissedNumbering(),
                                    image.getImageRectoVerso() != null ? image.getImageRectoVerso().toString()
                                            : null);

                    // ..and on transcribe folio
                    linkedDocumentOnTranscribeFolio = getManuscriptViewerService()
                            .findLinkedDocumentOnTranscriptionWithOrWithoutRectoVerso(volNum, volLetExt,
                                    image.getInsertNum(), image.getInsertLet(), image.getImageProgTypeNum(),
                                    image.getMissedNumbering(),
                                    image.getImageRectoVerso() != null ? image.getImageRectoVerso().toString()
                                            : null);

                    if (!linkedDocumentOnStartFolio.isEmpty() && !linkedDocumentOnTranscribeFolio.isEmpty()) {
                        intersectionSize = CollectionUtils
                                .intersection(linkedDocumentOnStartFolio, linkedDocumentOnTranscribeFolio)
                                .size();
                        unionSize = CollectionUtils
                                .union(linkedDocumentOnStartFolio, linkedDocumentOnTranscribeFolio).size();
                    } else {
                        unionSize = Math.max(linkedDocumentOnStartFolio.size(),
                                linkedDocumentOnTranscribeFolio.size());
                    }

                    if (unionSize == 1) {
                        documentId = linkedDocumentOnStartFolio.isEmpty()
                                ? linkedDocumentOnTranscribeFolio.iterator().next().getEntryId()
                                : linkedDocumentOnStartFolio.iterator().next().getEntryId();
                    } else if (unionSize > 1) {
                        isExtract = true;
                    }
                }
            }
        }
        //         }         
        if (documentId != null) {
            isExtract = getManuscriptViewerService().isDocumentExtract(documentId);
        }

        // old one
        //model.put("linkedDocument", (linkedDocumentOnStartFolio != null && linkedDocumentOnStartFolio.size() > 0) ? true : false);
        // new ones
        model.put("linkedDocumentOnStartFolio",
                (linkedDocumentOnStartFolio != null && linkedDocumentOnStartFolio.size() > 0) ? true : false);
        model.put("linkedDocumentOnTranscribeFolio",
                (linkedDocumentOnTranscribeFolio != null && linkedDocumentOnTranscribeFolio.size() > 0) ? true
                        : false);
        model.put("countAlreadyEntered", unionSize);
        model.put("countStartAndTranscribeHere", intersectionSize);
        model.put("entryId", documentId);
        if (unionSize == 1) {
            model.put("showLinkedDocument", HtmlUtils.showDocument(documentId));
        } else if (unionSize > 1) {
            model.put("showLinkedDocument",
                    HtmlUtils.showSameFolioDocuments(volNum, volLetExt, image.getInsertNum(),
                            image.getInsertLet(), image.getImageProgTypeNum(), image.getMissedNumbering(),
                            image.getImageRectoVerso().toString()));
        }
        model.put("isExtract", isExtract);
    } catch (ApplicationThrowable applicationThrowable) {
        model.put("entryId", null);
        //model.put("linkedDocument", false);
        model.put("linkedDocumentOnStartFolio", false);
        model.put("linkedDocumentOnTranscribeFolio", false);
        model.put("showLinkedDocument", "");
        model.put("imageName", "");
        model.put("imageId", "");
        model.put("imageOrder", "");
        model.put("isExtract", false);
    }

    return new ModelAndView("responseOK", model);
}

From source file:org.medici.bia.service.docbase.DocBaseServiceImpl.java

/**
 * {@inheritDoc}//from w  w w  .  j  a  v a 2  s .c  o m
 */
@Override
@SuppressWarnings("unchecked")
public List<Document> findDocumentsByFolio(Integer volNum, String volLetExt, String insertNum, String insertLet,
        Integer folioNum, String folioMod, String folioRectoVerso, boolean alsoTranscribeFolio)
        throws ApplicationThrowable {
    try {
        List<Document> startFolioDocuments = getDocumentDAO().findDocumentsOnFolioWithOrWithoutRectoVerso(
                volNum, volLetExt, insertNum, insertLet, folioNum, folioMod, folioRectoVerso);
        if (alsoTranscribeFolio) {
            List<Document> transcribeFolioDocuments = getDocumentDAO()
                    .findDocumentsOnTranscribeFolioWithOrWithoutRectoVerso(volNum, volLetExt, insertNum,
                            insertLet, folioNum, folioMod, folioRectoVerso);
            Collection<Document> union = CollectionUtils.union(startFolioDocuments, transcribeFolioDocuments);
            if (union instanceof List)
                return (List<Document>) union;
            return new ArrayList<Document>(union);
        }
        return startFolioDocuments;
    } catch (Throwable th) {
        throw new ApplicationThrowable(th);
    }
}

From source file:org.openmrs.module.adminui.TestUtils.java

public static boolean sameProviders(Map<EncounterRole, Set<Provider>> a, Map<EncounterRole, Set<Provider>> b) {
    Collection<EncounterRole> roles = CollectionUtils.union(a.keySet(), b.keySet());
    for (EncounterRole role : roles) {
        Set<Provider> aSet = a.get(role);
        Set<Provider> bSet = b.get(role);
        if (aSet == null) {
            aSet = Collections.emptySet();
        }//from   ww  w . java  2s  .  co  m
        if (bSet == null) {
            bSet = Collections.emptySet();
        }
        if (!CollectionUtils.isEqualCollection(aSet, bSet)) {
            return false;
        }
    }
    return true;
}

From source file:org.opensingular.flow.core.FlowMap.java

/**
 * <p>Retorna todas as tarefas definidas neste mapa.</p>
 *
 * @return todas as tarefas definidas.//from  w w w .j  a  va 2s .c  om
 */
@Nonnull
public Collection<STask<?>> getAllTasks() {
    return CollectionUtils.union(getTasks(), getEndTasks());
}

From source file:org.orbeon.oxf.processor.pipeline.choose.ConcreteChooseProcessor.java

/**
 * @param branchConditions  List of Strings: XPath expression for each branch
 *                          (except the optimal last <otherwise>)
 * @param branchNamespaces  List of NamespaceContext objects: namespaces declared in
 *                          the context of the given XPath expression
 * @param branchProcessors  List of Processor objects: one for each branch
 * @param inputs            Set of Strings: all the ids possibly referenced by
 *                          a processor in any branch
 * @param outputsById       Set of Strings: outputs of the choose referenced
 *                          by and other processor
 * @param outputsByParamRef Set of Strings: outputs of the choose referencing
 *                          pipeline outputs
 */// ww w .  ja  v  a  2 s.  co  m
public ConcreteChooseProcessor(String id, LocationData locationData, List branchConditions,
        List<NamespaceMapping> branchNamespaces, List<Processor> branchProcessors, Set inputs, Set outputsById,
        Set outputsByParamRef) {
    setId(id);
    this.locationData = locationData;
    this.branchConditions = branchConditions;
    this.branchNamespaces = branchNamespaces;
    this.branchProcessors = branchProcessors;
    this.outputsById = outputsById;
    this.outputsByParamRef = outputsByParamRef;

    // Add inputs
    addInputInfo(new ProcessorInputOutputInfo(AbstractChooseProcessor.CHOOSE_DATA_INPUT));
    for (Iterator i = inputs.iterator(); i.hasNext();) {
        String name = (String) i.next();
        addInputInfo(new ProcessorInputOutputInfo(name));
    }

    // Add outputs
    for (Iterator i = CollectionUtils.union(outputsById, outputsByParamRef).iterator(); i.hasNext();) {
        String name = (String) i.next();
        addOutputInfo(new ProcessorInputOutputInfo(name));
    }

    for (Iterator i = branchProcessors.iterator(); i.hasNext();) {
        Processor processor = (Processor) i.next();

        // Create ProcessorInput for each branch
        Map<String, ProcessorInput> currentBranchInputs = new HashMap<String, ProcessorInput>();
        branchInputs.add(currentBranchInputs);
        for (Iterator j = inputs.iterator(); j.hasNext();) {
            String inputName = (String) j.next();
            currentBranchInputs.put(inputName, processor.createInput(inputName));
        }

        // Create ProcessorOutput for each branch
        Map<Object, ProcessorOutput> currentBranchOutputs = new HashMap<Object, ProcessorOutput>();
        branchOutputs.add(currentBranchOutputs);
        for (Iterator j = CollectionUtils.union(outputsById, outputsByParamRef).iterator(); j.hasNext();) {
            String outputName = (String) j.next();
            currentBranchOutputs.put(outputName, processor.createOutput(outputName));
        }
    }
}