Example usage for java.util List retainAll

List of usage examples for java.util List retainAll

Introduction

In this page you can find the example usage for java.util List retainAll.

Prototype

boolean retainAll(Collection<?> c);

Source Link

Document

Retains only the elements in this list that are contained in the specified collection (optional operation).

Usage

From source file:cepdest.pattern.holder.EnhancedPatternsHolder.java

public List<String> getPatternIdForItinerary(Itinerary it) {

    List<String> finalPatternIds = null;
    double chainLength = 1;

    ConfigProvider config = ConfigProviderFactory.getConfig();

    switch (config.getPredictorConfig().getCurrentIterationMode()) {
    case BACKWARDS:
        AreaOfInterest a = it.getAllNamedAreas().get(it.getNumOfAllNamedAreas() - 1);
        GroupOfEnhancedPatternNode node = getNodesWithArea(a);

        finalPatternIds = new ArrayList(node.getOutboundPatternIds());

        int lastIndex = it.getNumOfAllNamedAreas() - 1;

        for (int i = lastIndex; i >= 1; i--) {
            AreaOfInterest a1 = it.getAllNamedAreas().get(i);
            AreaOfInterest a2 = it.getAllNamedAreas().get(i - 1);

            GroupOfEnhancedPatternNode node2 = getNodesWithArea(a2);

            List<String> cPatternIds = node2.getPatternIdsForSon(a1.getID());

            if (cPatternIds != null) {
                List<String> aux = new ArrayList(finalPatternIds);
                finalPatternIds.retainAll(cPatternIds);
                if (finalPatternIds.isEmpty()) {
                    finalPatternIds = aux;
                    break;
                } else {
                    for (String patternId : finalPatternIds) {
                        List<Integer> pos1 = node.getPositionsForPatternId(patternId);
                        List<Integer> pos2 = node2.getPositionsForPatternId(patternId);
                        if (!compatiblePositions(pos1, pos2)) {
                            finalPatternIds = aux;
                            break;
                        }/*from   w  w  w. j  av a  2  s  .co  m*/
                    }
                }
            } else {
                break;
            }

            chainLength++;
            node = node2;

        }
        break;
    case FULL_FORWARD:
        int i = 0;
        while (i < it.getNumOfAllNamedAreas() - 1) {
            AreaOfInterest a1 = it.getAllNamedAreas().get(i);
            AreaOfInterest a2 = it.getAllNamedAreas().get(i + 1);

            node = getNodesWithArea(a1);
            List<String> cPatternIds = node.getPatternIdsForSon(a2.getID());
            if (finalPatternIds != null) {
                if (cPatternIds != null) {
                    finalPatternIds.retainAll(cPatternIds);
                    chainLength++;
                } else {
                    finalPatternIds = null;
                }
            } else if (cPatternIds != null && !cPatternIds.isEmpty()) {
                finalPatternIds = new ArrayList<String>(cPatternIds);
                chainLength = 2;
            }
            i++;
        }
        break;
    case FORWARD:
        for (i = 0; i < it.getNumOfOldNamedAreas() - 1; i++) {
            AreaOfInterest a1 = it.getOldNamedAreas().get(i);
            AreaOfInterest a2 = it.getOldNamedAreas().get(i + 1);

            node = getNodesWithArea(a1);
            List<String> cPatternIds = node.getPatternIdsForSon(a2.getID());

            if (finalPatternIds != null) {
                if (cPatternIds != null) {
                    finalPatternIds.retainAll(cPatternIds);
                    chainLength++;
                } else {
                    AreaOfInterest iArea = it.getOldNamedAreas().get(0);
                    AreaOfInterest fArea = it.getOldNamedAreas().get(it.getNumOfOldNamedAreas() - 1);

                    EnhancedPatternNode iNode = getNodeWithArea(iArea);
                    EnhancedPatternNode fNode = getNodeWithArea(fArea);

                    finalPatternIds = new ArrayList(iNode.getPatternIds());
                    finalPatternIds.retainAll(fNode.getPatternIds());
                    chainLength = 1;
                    break;
                }
            } else if (cPatternIds != null && !cPatternIds.isEmpty()) {
                finalPatternIds = new ArrayList<String>(cPatternIds);
                chainLength = 2;
            }
        }

        break;
    }

    if (finalPatternIds != null) {
        finalPatternIds.add(String.valueOf(chainLength / it.getNumOfAllNamedAreas()));
    }
    return finalPatternIds;
}

From source file:org.ebayopensource.turmeric.eclipse.utils.test.collections.TestListUtil.java

/**
 * Test method for {@link org.ebayopensource.turmeric.maveneclipseapi.internal.collections.ListUtil#transformed(org.ebayopensource.turmeric.maveneclipseapi.internal.collections.Transformer, java.util.List)}.
 *///from w ww .  j a  v  a 2  s .  co  m
@Test
public void testTransformedTransformerOfTListOfQ() {
    List<String> collection = new ArrayList<String>();
    collection.add("Arc' Terryx");
    collection.add("Mountain Hardwear");
    collection.add("Black Diamond");
    final Transformer<String> transformer = new Transformer<String>() {
        private static final long serialVersionUID = 1631027078150099602L;

        @Override
        public String transform(final Object input) {
            return ObjectUtils.toString(input).toLowerCase();
        }
    };
    List<String> list = ListUtil.transformed(transformer, collection);
    for (int i = 0; i < collection.size(); i++) {
        String expected = collection.get(i);
        String actual = list.get(i);
        Assert.assertNotSame(expected, actual);
        Assert.assertTrue(expected.equalsIgnoreCase(actual));
    }
    String item = "3dfx";
    list.add(item);
    Assert.assertTrue(list.contains(item));
    list.remove(item);
    Assert.assertFalse(list.contains(item));
    list.add(0, item);
    Assert.assertTrue(list.indexOf(item) == 0);
    Assert.assertTrue(list.lastIndexOf(item) == 0);
    list.remove(0);
    list.set(0, item);
    Assert.assertTrue(list.indexOf(item) == 0);

    Collection<String> data = new ArrayList<String>(2);
    data.add("Voodoo");
    data.add("Radeon");
    list.addAll(data);
    Assert.assertTrue(list.containsAll(data));
    list.removeAll(data);
    Assert.assertFalse(list.containsAll(data));
    list.addAll(0, data);
    list.retainAll(data);
}

From source file:org.onosproject.t3.impl.TroubleshootManager.java

/**
 * Checks that two hosts are bridged (L2Unicast).
 *
 * @param source      the source host//from   w  w w.j  a va 2 s.  c  o  m
 * @param destination the destination host
 * @return true if bridged.
 * @throws ConfigException if config can't be properly retrieved
 */
private boolean areBridged(Host source, Host destination) throws ConfigException {

    //If the locations is not the same we don't even check vlan or subnets
    if (Collections.disjoint(source.locations(), destination.locations())) {
        return false;
    }

    if (!source.vlan().equals(VlanId.NONE) && !destination.vlan().equals(VlanId.NONE)
            && !source.vlan().equals(destination.vlan())) {
        return false;
    }

    InterfaceConfig interfaceCfgH1 = networkConfigService.getConfig(source.location(), InterfaceConfig.class);
    InterfaceConfig interfaceCfgH2 = networkConfigService.getConfig(destination.location(),
            InterfaceConfig.class);
    if (interfaceCfgH1 != null && interfaceCfgH2 != null) {

        //following can be optimized but for clarity is left as is
        Interface intfH1 = interfaceCfgH1.getInterfaces().stream().findFirst().get();
        Interface intfH2 = interfaceCfgH2.getInterfaces().stream().findFirst().get();

        if (source.vlan().equals(VlanId.NONE) && !destination.vlan().equals(VlanId.NONE)) {
            return intfH1.vlanUntagged().equals(destination.vlan())
                    || intfH1.vlanNative().equals(destination.vlan());
        }

        if (!source.vlan().equals(VlanId.NONE) && destination.vlan().equals(VlanId.NONE)) {
            return intfH2.vlanUntagged().equals(source.vlan()) || intfH2.vlanNative().equals(source.vlan());
        }

        if (!intfH1.vlanNative().equals(intfH2.vlanNative())) {
            return false;
        }

        if (!intfH1.vlanUntagged().equals(intfH2.vlanUntagged())) {
            return false;
        }

        List<InterfaceIpAddress> intersection = new ArrayList<>(intfH1.ipAddressesList());
        intersection.retainAll(intfH2.ipAddressesList());
        if (intersection.size() == 0) {
            return false;
        }
    }
    return true;
}

From source file:hydrograph.ui.propertywindow.widgets.utility.SchemaSyncUtility.java

/**
 * Add and remove data from map fields those are not present in outer schema, use to sync outer schema with transform and aggregate internal fields.
 *
 * @param outSchema the out schema/*from  w w w .  j av  a 2  s . co  m*/
 * @param transformMapping the transform mapping
 * @return the list
 */
public List<NameValueProperty> filterCommonMapFields(List<NameValueProperty> outSchema,
        TransformMapping transformMapping) {
    List<NameValueProperty> mapNameValueProperties = transformMapping.getMapAndPassthroughField();
    for (NameValueProperty nameValueProperty : outSchema) {
        boolean isPresent = false;
        if (!mapNameValueProperties.contains(nameValueProperty)) {
            for (MappingSheetRow mappingSheetRow : transformMapping.getMappingSheetRows()) {
                FilterProperties tempFilterProperties = new FilterProperties();
                tempFilterProperties.setPropertyname(nameValueProperty.getPropertyValue());
                if (mappingSheetRow.getOutputList().contains(tempFilterProperties)) {
                    isPresent = true;
                    break;
                }
            }
            if (!isPresent)
                mapNameValueProperties.add(nameValueProperty);
        }

    }
    mapNameValueProperties.retainAll(outSchema);
    return mapNameValueProperties;
}

From source file:org.entrystore.repository.impl.ContextManagerImpl.java

/**
 * Intersection//www  . ja  v  a  2 s . c  om
 * @param entries entries
 * @param mdEntries entries from metadata query
 * @return the intersected entries.
 */
private List<Entry> intersectEntries(List<Entry> entries, List<Entry> mdEntries) {
    if (mdEntries != null && entries != null) {
        mdEntries.retainAll(entries);
        return mdEntries;
    }
    if (mdEntries != null) {
        return mdEntries;
    }
    if (entries != null) {
        return entries;
    }
    return null;
}

From source file:org.phenotips.export.internal.DataToCellConverter.java

public DataSection isSolvedHeader(Set<String> enabledFields) throws Exception {
    String sectionName = "isSolved";
    List<String> fields = new ArrayList<>(Arrays.asList("solved", "solved__pubmed_id", "solved__notes"));
    fields.retainAll(enabledFields);
    Set<String> fieldSet = new HashSet<>(fields);
    this.enabledHeaderIdsBySection.put(sectionName, fieldSet);

    DataSection headerSection = new DataSection();
    if (fields.isEmpty()) {
        return null;
    }//from w ww  .  j a v  a 2s . co  m

    int hX = 0;
    for (String fieldId : fields) {
        DataCell headerCell = new DataCell(
                this.translationManager.translate("phenotips.export.excel.label.solvedStatus." + fieldId), hX,
                1, StyleOption.HEADER);
        headerSection.addCell(headerCell);
        hX++;
    }
    DataCell headerCell = new DataCell(
            this.translationManager.translate("phenotips.export.excel.label.solvedStatus"), 0, 0,
            StyleOption.LARGE_HEADER);
    headerCell.addStyle(StyleOption.HEADER);
    headerSection.addCell(headerCell);

    return headerSection;
}

From source file:org.phenotips.export.internal.DataToCellConverter.java

public DataSection documentInfoHeader(Set<String> enabledFields) throws Exception {
    String sectionName = "documentInfo";

    // Must be linked to keep order; in other sections as well

    List<String> fields = new ArrayList<>(Arrays.asList("referrer", "creationDate", "author", "date"));
    fields.retainAll(enabledFields);
    Set<String> fieldSet = new HashSet<>(fields);
    this.enabledHeaderIdsBySection.put(sectionName, fieldSet);

    DataSection headerSection = new DataSection();
    if (fields.isEmpty()) {
        return null;
    }//  www  .j a v  a2s.co m

    int hX = 0;
    for (String fieldId : fields) {
        DataCell headerCell = new DataCell(
                this.translationManager.translate("phenotips.exportPreferences.field." + fieldId), hX, 1,
                StyleOption.HEADER);
        headerSection.addCell(headerCell);
        hX++;
    }
    DataCell headerCell = new DataCell(
            this.translationManager.translate("phenotips.export.excel.label.documentInfo"), 0, 0,
            StyleOption.LARGE_HEADER);
    headerCell.addStyle(StyleOption.HEADER);
    headerSection.addCell(headerCell);

    return headerSection;
}

From source file:au.org.ala.delta.intkey.directives.TaxonListArgument.java

@Override
public List<Item> parseInput(Queue<String> inputTokens, IntkeyContext context, String directiveName,
        StringBuilder stringRepresentationBuilder) throws IntkeyDirectiveParseException {
    List<String> selectedKeywordsOrTaxonNumbers = new ArrayList<String>();

    boolean overrideExcludedTaxa = false;

    String token = inputTokens.poll();
    if (token != null && token.equalsIgnoreCase(OVERRIDE_EXCLUDED_TAXA)) {
        overrideExcludedTaxa = true;/*from   w  ww  .  java 2  s.  c o m*/
        token = inputTokens.poll();
    }

    List<Item> taxa = null;

    SelectionMode selectionMode = context.displayKeywords() ? SelectionMode.KEYWORD : SelectionMode.LIST;

    if (token != null) {
        if (token.equalsIgnoreCase(DEFAULT_DIALOG_WILDCARD)) {
            // do nothing - default selection mode is already set above.
        } else if (token.equalsIgnoreCase(KEYWORD_DIALOG_WILDCARD)) {
            selectionMode = SelectionMode.KEYWORD;
        } else if (token.equalsIgnoreCase(LIST_DIALOG_WILDCARD)) {
            selectionMode = SelectionMode.LIST;
        } else if (token.equalsIgnoreCase(LIST_DIALOG_AUTO_SELECT_SOLE_ITEM_WILDCARD)) {
            selectionMode = SelectionMode.LIST_AUTOSELECT_SINGLE_VALUE;
        } else {
            taxa = new ArrayList<Item>();

            while (token != null) {
                try {
                    taxa.addAll(ParsingUtils.parseTaxonToken(token, context));
                    selectedKeywordsOrTaxonNumbers.add(token);
                    token = inputTokens.poll();

                } catch (IllegalArgumentException ex) {
                    throw new IntkeyDirectiveParseException("UnrecognizedTaxonKeyword.error", token);
                }
            }

            if (!(overrideExcludedTaxa || _selectFromAll)) {
                taxa.retainAll(context.getIncludedTaxa());
            }
        }
    }

    if (taxa == null) {
        List<String> selectedKeywords = new ArrayList<String>();
        DirectivePopulator populator = context.getDirectivePopulator();
        if (selectionMode == SelectionMode.KEYWORD) {
            taxa = populator.promptForTaxaByKeyword(directiveName, !(overrideExcludedTaxa || _selectFromAll),
                    _noneSelectionPermitted, false, null, selectedKeywords);
        } else {
            boolean autoSelectSingleValue = (selectionMode == SelectionMode.LIST_AUTOSELECT_SINGLE_VALUE);
            taxa = populator.promptForTaxaByList(directiveName, !(overrideExcludedTaxa || _selectFromAll),
                    autoSelectSingleValue, false, false, null, selectedKeywords);
        }

        if (taxa == null) {
            // cancelled
            return null;
        }

        // Put selected keywords or taxon numbers into a collection to use
        // to build the string representation.
        if (!selectedKeywords.isEmpty()) {
            for (String selectedKeyword : selectedKeywords) {
                if (selectedKeyword.contains(" ")) {
                    // Enclose any keywords that contain spaces in quotes
                    // for the string representation
                    selectedKeywordsOrTaxonNumbers.add("\"" + selectedKeyword + "\"");
                } else {
                    selectedKeywordsOrTaxonNumbers.add(selectedKeyword);
                }
            }
        } else {
            List<Integer> selectedTaxonNumbers = new ArrayList<Integer>();
            for (int i = 0; i < taxa.size(); i++) {
                Item taxon = taxa.get(i);
                selectedTaxonNumbers.add(taxon.getItemNumber());
            }
            selectedKeywordsOrTaxonNumbers.add(Utils.formatIntegersAsListOfRanges(selectedTaxonNumbers));
        }
    }

    // build the string representation of the directive call
    stringRepresentationBuilder.append(" ");

    if (overrideExcludedTaxa) {
        stringRepresentationBuilder.append(OVERRIDE_EXCLUDED_TAXA);
        stringRepresentationBuilder.append(" ");
    }

    stringRepresentationBuilder.append(StringUtils.join(selectedKeywordsOrTaxonNumbers, " "));

    if (taxa.size() == 0 && !_noneSelectionPermitted) {
        throw new IntkeyDirectiveParseException("NoTaxaInSet.error");
    }

    Collections.sort(taxa);

    return taxa;
}

From source file:au.org.ala.delta.intkey.directives.CharacterListArgument.java

@Override
public List<au.org.ala.delta.model.Character> parseInput(Queue<String> inputTokens, IntkeyContext context,
        String directiveName, StringBuilder stringRepresentationBuilder) throws IntkeyDirectiveParseException {

    List<String> selectedKeywordsOrCharacterNumbers = new ArrayList<String>();

    boolean overrideExcludedCharacters = false;

    String token = inputTokens.poll();
    if (token != null && token.equalsIgnoreCase(OVERRIDE_EXCLUDED_CHARACTERS)) {
        overrideExcludedCharacters = true;
        token = inputTokens.poll();//  w  w w.ja  v a 2  s  .  c om
    }

    List<au.org.ala.delta.model.Character> characters = null;

    SelectionMode selectionMode = context.displayKeywords() ? SelectionMode.KEYWORD : SelectionMode.LIST;
    DirectivePopulator populator = context.getDirectivePopulator();

    if (token != null) {
        if (token.equalsIgnoreCase(DEFAULT_DIALOG_WILDCARD)) {
            // do nothing - default selection mode is already set above.
        } else if (token.equalsIgnoreCase(KEYWORD_DIALOG_WILDCARD)) {
            selectionMode = SelectionMode.KEYWORD;
        } else if (token.equalsIgnoreCase(LIST_DIALOG_WILDCARD)) {
            selectionMode = SelectionMode.LIST;
        } else {
            characters = new ArrayList<au.org.ala.delta.model.Character>();
            while (token != null) {
                try {
                    characters.addAll(ParsingUtils.parseCharacterToken(token, context));
                    selectedKeywordsOrCharacterNumbers.add(token);
                    token = inputTokens.poll();
                } catch (IllegalArgumentException ex) {
                    throw new IntkeyDirectiveParseException("UnrecognizedCharacterKeyword.error", token);
                }
            }

            if (!(overrideExcludedCharacters || _selectFromAll)) {
                characters.retainAll(context.getIncludedCharacters());
            }
        }
    }

    if (characters == null) {
        if (context.isProcessingDirectivesFile()) {
            //ignore incomplete directives when processing an input file
            return null;
        }

        List<String> selectedKeywords = new ArrayList<String>();
        if (selectionMode == SelectionMode.KEYWORD) {
            characters = populator.promptForCharactersByKeyword(directiveName,
                    !(overrideExcludedCharacters || _selectFromAll), _noneSelectionPermitted, selectedKeywords);
        } else {
            characters = populator.promptForCharactersByList(directiveName,
                    !(overrideExcludedCharacters || _selectFromAll), selectedKeywords);
        }

        if (characters == null) {
            // cancelled
            return null;
        }

        // Put selected keywords or taxon numbers into a collection to use
        // to build the string representation.
        if (!selectedKeywords.isEmpty()) {
            for (String selectedKeyword : selectedKeywords) {
                if (selectedKeyword.contains(" ")) {
                    // Enclose any keywords that contain spaces in quotes
                    // for the string representation
                    selectedKeywordsOrCharacterNumbers.add("\"" + selectedKeyword + "\"");
                } else {
                    selectedKeywordsOrCharacterNumbers.add(selectedKeyword);
                }
            }
        } else {
            List<Integer> selectedCharacterNumbers = new ArrayList<Integer>();
            for (int i = 0; i < characters.size(); i++) {
                Character ch = characters.get(i);
                selectedCharacterNumbers.add(ch.getCharacterId());
            }
            selectedKeywordsOrCharacterNumbers
                    .add(Utils.formatIntegersAsListOfRanges(selectedCharacterNumbers));
        }
    }

    // build the string representation of the directive call
    stringRepresentationBuilder.append(" ");

    if (overrideExcludedCharacters) {
        stringRepresentationBuilder.append(OVERRIDE_EXCLUDED_CHARACTERS);
        stringRepresentationBuilder.append(" ");
    }

    stringRepresentationBuilder.append(StringUtils.join(selectedKeywordsOrCharacterNumbers, " "));

    if (characters.size() == 0 && !_noneSelectionPermitted) {
        throw new IntkeyDirectiveParseException("NoCharactersInSet.error");
    }

    Collections.sort(characters);

    return characters;
}

From source file:org.phenotips.export.internal.DataToCellConverter.java

public DataSection medicalHistoryHeader(Set<String> enabledFields) throws Exception {
    String sectionName = "medicalHistory";
    List<String> fields = new ArrayList<>(Arrays.asList("allergies", "global_age_of_onset", "medical_history"));
    fields.retainAll(enabledFields);
    Set<String> fieldSet = new HashSet<>(fields);
    this.enabledHeaderIdsBySection.put(sectionName, fieldSet);

    DataSection headerSection = new DataSection();
    if (fields.isEmpty()) {
        return null;
    }//w  w w .  j av  a  2s . c o m

    int hX = 0;
    for (String fieldId : fields) {
        DataCell headerCell = new DataCell(
                this.translationManager.translate("phenotips.export.excel.label.medicalHistory." + fieldId), hX,
                1, StyleOption.HEADER);
        headerSection.addCell(headerCell);
        hX++;
    }
    DataCell headerCell = new DataCell(
            this.translationManager.translate("phenotips.export.excel.label.medicalHistory"), 0, 0,
            StyleOption.LARGE_HEADER);
    headerCell.addStyle(StyleOption.HEADER);
    headerSection.addCell(headerCell);

    return headerSection;
}