Example usage for org.apache.commons.collections15 ListUtils subtract

List of usage examples for org.apache.commons.collections15 ListUtils subtract

Introduction

In this page you can find the example usage for org.apache.commons.collections15 ListUtils subtract.

Prototype

public static <E> List<E> subtract(final List<? extends E> list1, final List<? extends E> list2) 

Source Link

Document

Subtracts all elements in the second list from the first list, placing the results in a new list.

Usage

From source file:gov.nih.nci.cabig.caaers.web.study.StudyCommand.java

public void synchronizeTreatmentAssignmentSelectedInterventions() {
    for (TreatmentAssignment treatmentAssignment : study.getActiveTreatmentAssignments()) {
        //all selected IDs
        List<Integer> studyAgentIds = new ArrayList<Integer>(
                treatmentAssignment.getSelectedStudyAgentInterventionIds());
        List<Integer> studyDeviceIds = new ArrayList<Integer>(
                treatmentAssignment.getSelectedStudyDeviceInterventionIds());
        List<Integer> otherInterventionIds = new ArrayList<Integer>(
                treatmentAssignment.getSelectedOtherInteterventionIds());

        //exiting association ids
        treatmentAssignment.regenerateAllInterventionIdList();
        List<Integer> existingStudyAgentIds = treatmentAssignment.getSelectedStudyAgentInterventionIds();
        List<Integer> existingStudyDeviceIds = treatmentAssignment.getSelectedStudyDeviceInterventionIds();
        List<Integer> existingOtherInterventionIds = treatmentAssignment.getSelectedOtherInteterventionIds();

        //object ids to remove
        List<Integer> unwantedStudyAgentIds = ListUtils.subtract(existingStudyAgentIds, studyAgentIds);
        List<Integer> unwantedStudyDeviceIds = ListUtils.subtract(existingStudyDeviceIds, studyDeviceIds);
        List<Integer> unwantedOtherInterventionIds = ListUtils.subtract(existingOtherInterventionIds,
                otherInterventionIds);//w w w  .j  a  v a  2  s  .c  o  m

        //object ids to add
        List<Integer> newStudyAgentIds = ListUtils.subtract(studyAgentIds, existingStudyAgentIds);
        List<Integer> newStudyDeviceIds = ListUtils.subtract(studyDeviceIds, existingStudyDeviceIds);
        List<Integer> newOtherInterventionIds = ListUtils.subtract(otherInterventionIds,
                existingOtherInterventionIds);

        //remove the unwanted ones 
        for (Integer id : unwantedStudyAgentIds) {
            StudyAgent studyAgent = study.findStudyAgentById(id);
            treatmentAssignment.removeInterventionFromTreatmentAssignment(studyAgent);
        }
        for (Integer id : unwantedStudyDeviceIds) {
            StudyDevice studyDevice = study.findStudyDeviceById(id);
            treatmentAssignment.removeInterventionFromTreatmentAssignment(studyDevice);
        }
        for (Integer id : unwantedOtherInterventionIds) {
            OtherIntervention otherIntervention = study.findOtherInterventionById(id);
            treatmentAssignment.removeInterventionFromTreatmentAssignment(otherIntervention);
        }

        //add the new ones
        for (Integer id : newStudyAgentIds) {
            StudyAgent studyAgent = study.findStudyAgentById(id);
            if (studyAgent != null)
                treatmentAssignment.addInterventionToTreatmentAssignment(studyAgent);
        }
        for (Integer id : newStudyDeviceIds) {
            StudyDevice studyDevice = study.findStudyDeviceById(id);
            if (studyDevice != null)
                treatmentAssignment.addInterventionToTreatmentAssignment(studyDevice);
        }
        for (Integer id : newOtherInterventionIds) {
            OtherIntervention otherIntervention = study.findOtherInterventionById(id);
            if (otherIntervention != null)
                treatmentAssignment.addInterventionToTreatmentAssignment(otherIntervention);
        }
    }
}

From source file:opendial.DialogueSystem.java

/**
 * Changes the settings of the system/*w  w w. j  a  v  a  2  s.c o m*/
 * 
 * @param settings the new settings
 */
public void changeSettings(Settings settings) {

    for (Class<Module> toDetach : ListUtils.subtract(this.settings.modules, settings.modules)) {
        detachModule(toDetach);
    }
    this.settings.fillSettings(settings.getFullMapping());

    for (Class<Module> toAttach : settings.modules) {
        if (getModule(toAttach) == null) {
            log.info("Attaching module: " + toAttach.getCanonicalName());
            attachModule(toAttach);
        }
    }
}

From source file:org.aksw.simba.bengal.triple2nl.TripleConverter.java

/**
 * Return a textual representation for the given triples. Currently we
 * assume that all triples have the same subject!
 * /*w w  w  .java 2s  . co  m*/
 * @param triples
 *            the triples to convert
 * @return the textual representation
 */
public String convert(List<Triple> triples) {
    // combine with conjunction
    CoordinatedPhraseElement typesConjunction = nlgFactory.createCoordinatedPhrase();

    // separate type triples from others
    List<Triple> typeTriples = triples.stream().filter(t -> t.predicateMatches(RDF.type.asNode()))
            .collect(Collectors.toList());
    List<Triple> otherTriples = ListUtils.subtract(triples, typeTriples);

    // convert the type triples
    List<SPhraseSpec> typePhrases = convertToPhrases(typeTriples);

    // if there is more than one type, we combine them into a single clause
    if (typePhrases.size() > 1) {
        // combine all objects in a coordinated phrase
        CoordinatedPhraseElement combinedObject = nlgFactory.createCoordinatedPhrase();

        // the last 2 phrases are combined via 'as well as'
        if (useAsWellAsCoordination) {
            SPhraseSpec phrase1 = typePhrases.remove(typePhrases.size() - 1);
            SPhraseSpec phrase2 = typePhrases.get(typePhrases.size() - 1);
            // combine all objects in a coordinated phrase
            CoordinatedPhraseElement combinedLastTwoObjects = nlgFactory
                    .createCoordinatedPhrase(phrase1.getObject(), phrase2.getObject());
            combinedLastTwoObjects.setConjunction("as well as");
            combinedLastTwoObjects.setFeature(Feature.RAISE_SPECIFIER, false);
            combinedLastTwoObjects.setFeature(InternalFeature.SPECIFIER, "a");
            phrase2.setObject(combinedLastTwoObjects);
        }

        Iterator<SPhraseSpec> iterator = typePhrases.iterator();
        // pick first phrase as representative
        SPhraseSpec representative = iterator.next();
        combinedObject.addCoordinate(representative.getObject());

        while (iterator.hasNext()) {
            SPhraseSpec phrase = iterator.next();
            NLGElement object = phrase.getObject();
            combinedObject.addCoordinate(object);
        }

        combinedObject.setFeature(Feature.RAISE_SPECIFIER, true);
        // set the coordinated phrase as the object
        representative.setObject(combinedObject);
        // return a single phrase
        typePhrases = Lists.newArrayList(representative);
    }
    for (SPhraseSpec phrase : typePhrases) {
        typesConjunction.addCoordinate(phrase);
    }

    // convert the other triples
    CoordinatedPhraseElement othersConjunction = nlgFactory.createCoordinatedPhrase();
    List<SPhraseSpec> otherPhrases = convertToPhrases(otherTriples);
    // we have to keep one triple with subject if we have no type triples
    if (typeTriples.isEmpty()) {
        othersConjunction.addCoordinate(otherPhrases.remove(0));
    }
    // make subject pronominal, i.e. -> he/she/it
    otherPhrases.stream().forEach(p -> asPronoun(p.getSubject()));
    for (SPhraseSpec phrase : otherPhrases) {
        othersConjunction.addCoordinate(phrase);
    }

    List<DocumentElement> sentences = new ArrayList();
    if (!typeTriples.isEmpty()) {
        sentences.add(nlgFactory.createSentence(typesConjunction));
    }

    if (!otherTriples.isEmpty()) {
        sentences.add(nlgFactory.createSentence(othersConjunction));
    }

    DocumentElement paragraph = nlgFactory.createParagraph(sentences);
    String realisation = realiser.realise(paragraph).getRealisation().trim();

    return realisation;
}