Example usage for com.google.common.collect Sets difference

List of usage examples for com.google.common.collect Sets difference

Introduction

In this page you can find the example usage for com.google.common.collect Sets difference.

Prototype

public static <E> SetView<E> difference(final Set<E> set1, final Set<?> set2) 

Source Link

Document

Returns an unmodifiable view of the difference of two sets.

Usage

From source file:com.stackframe.sarariman.ContactsGlobalAudit.java

private Collection<Contact> orphanedContacts() throws SQLException {
    Set<Contact> orphaned = Sets.difference(Sets.difference(contacts.getAll(), projectTimesheetContacts()),
            projectInvoiceContacts());//from  ww w. j a v  a2  s. c  o  m
    return orphaned;
}

From source file:org.onosproject.store.resource.impl.NonEncodableDiscreteResources.java

@Override
public DiscreteResources difference(DiscreteResources other) {
    return new NonEncodableDiscreteResources(Sets.difference(this.values, other.values()));
}

From source file:org.sonar.java.se.AlwaysTrueOrFalseExpressionCollector.java

public Set<Tree> alwaysTrue() {
    return Sets.difference(trueEvaluations.keySet(), falseEvaluations.keySet());
}

From source file:co.cask.hydrator.plugin.transform.CachingLookup.java

@Override
public Map<String, T> lookup(Set<String> keys) {
    ImmutableMap<String, T> cached = cache.getAllPresent(keys);

    Set<String> missingKeys = Sets.difference(keys, cached.keySet());
    Map<String, T> missing = delegate.lookup(missingKeys);
    cache.putAll(missing);//from www  .  j a  v  a2s.com

    return ImmutableMap.<String, T>builder().putAll(cached).putAll(missing).build();
}

From source file:org.wso2.carbon.governance.comparator.wsdl.WSDLMessagesComparator.java

protected void compareMessages(Definition base, Definition changed, DefaultComparison comparison) {

    DefaultComparison.DefaultSection section = null;

    Set<QName> baseKeys = base.getMessages().keySet();
    Set<QName> changedKeys = changed.getMessages().keySet();

    Set<QName> additionKeys = Sets.difference(changedKeys, baseKeys);
    if (section == null && additionKeys.size() > 0) {
        section = comparison.newSection();
    }//from  www. j a  va2 s. c  o  m
    processAdditions(section, additionKeys, changed);

    Set<QName> removalKeys = Sets.difference(baseKeys, changedKeys);
    if (section == null && removalKeys.size() > 0) {
        section = comparison.newSection();
    }
    processRemovals(section, removalKeys, base);

    Set<QName> commonKeys = Sets.intersection(baseKeys, changedKeys);
    if (section == null && commonKeys.size() > 0) {
        section = comparison.newSection();
    }
    processChanges(section, commonKeys, base, changed);

    if (section != null) {
        comparison.addSection(ComparatorConstants.WSDL_IMPORTS, section);
    }

}

From source file:com.opengamma.strata.engine.marketdata.function.MissingDataAwareObservableFunction.java

@Override
public Map<ObservableId, Result<Double>> build(Set<? extends ObservableId> requirements) {
    // Results for IDs with a market data feed of NO_RULE.
    // These IDs can't be used to look up market data because there was no market data rule to specify the
    // market data feed.
    Map<ObservableId, Result<Double>> failures = requirements.stream()
            .filter(id -> id.getMarketDataFeed().equals(MarketDataFeed.NO_RULE))
            .collect(toImmutableMap(id -> id, this::createFailure));

    // The requirements that have a real market data feed and can be resolved into market data
    Set<? extends ObservableId> ids = Sets.difference(requirements, failures.keySet());
    Map<ObservableId, Result<Double>> marketData = delegate.build(ids);
    return ImmutableMap.<ObservableId, Result<Double>>builder().putAll(failures).putAll(marketData).build();
}

From source file:com.facebook.buck.tools.consistency.TargetsDiffer.java

/**
 * Prints the differences between two target graphs, including newly added, removed, and changed
 * targets and hashes//from   w w  w.  j  av a2 s  .  com
 *
 * @param originalFile The original set of target / hash pairs
 * @param newFile The new set of target / hash pairs
 * @throws MaxDifferencesException If the maximum number of differences (as specified by {@link
 *     #diffPrinter}) is reached
 * @return true if the two targets are different false if they aren't
 */
public DifferState.DiffResult printDiff(ParsedTargetsFile originalFile, ParsedTargetsFile newFile)
        throws MaxDifferencesException {
    Set<String> targetsInOriginal = originalFile.targetsToHash.keySet();
    Set<String> targetsInNew = newFile.targetsToHash.keySet();
    Set<String> targetsOnlyInOriginal = Sets.difference(targetsInOriginal, targetsInNew);
    Set<String> targetsOnlyInNew = Sets.difference(targetsInNew, targetsInOriginal);
    Set<String> targetsInBoth = Sets.intersection(targetsInOriginal, targetsInNew);

    printRemoved(originalFile, targetsOnlyInOriginal);
    printAdded(newFile, targetsOnlyInNew);
    printChanged(originalFile, newFile, targetsInBoth);
    return differState.hasChanges();
}

From source file:org.sonar.java.se.checks.ConditionAlwaysTrueOrFalseCheck.java

@Override
public void checkEndOfExecution(CheckerContext context) {
    EvaluatedConditions ec = evaluatedConditions.pop();
    for (Tree condition : Sets.difference(ec.evaluatedToFalse.keySet(), ec.evaluatedToTrue.keySet())) {
        context.reportIssue(condition, this,
                "Change this condition so that it does not always evaluate to \"false\"",
                collectFlow(ec.evaluatedToFalse.get(condition), false));
    }//ww w.  j  av a2s .  c  o m
    for (Tree condition : Sets.difference(ec.evaluatedToTrue.keySet(), ec.evaluatedToFalse.keySet())) {
        context.reportIssue(condition, this,
                "Change this condition so that it does not always evaluate to \"true\"",
                collectFlow(ec.evaluatedToTrue.get(condition), true));
    }
}

From source file:org.diqube.server.config.DefaultConfigValuesAvailable.java

@Test
public void defaultValuesForAllConfigsAvailable() throws IOException {
    Properties properties = new Properties();
    properties/*from  w w  w .  j  a  v  a2s .  c om*/
            .load(this.getClass().getResourceAsStream(ConfigurationManager.DEFAULT_CONFIG_CLASSPATH_FILENAME));

    Set<String> neededConfigKeys = Stream.of(ConfigKey.class.getFields()). //
            filter(f -> f.getType().equals(String.class)). // String fields
            filter(f -> Modifier.isStatic(f.getModifiers())). // static fields
            map(f -> {
                try {
                    return (String) f.get(null); // get value of field.
                } catch (Exception e) {
                    throw new RuntimeException("Could not access value.");
                }
            }).collect(Collectors.toSet());

    Set<String> notAvailableKeys = Sets.difference(neededConfigKeys, properties.keySet());

    Assert.assertEquals(notAvailableKeys, new HashSet<String>(),
            "Expected that for each constant in " + ConfigKey.class.getSimpleName()
                    + " there is a default value in " + ConfigurationManager.DEFAULT_CONFIG_CLASSPATH_FILENAME
                    + ". For the following keys there is no default value: ");
}

From source file:org.obiba.mica.dataset.search.rest.harmonization.ContingencyUtils.java

public static List<String> getValuesHeaders(DatasetVariable variable, Mica.DatasetVariableContingencyDto dto) {
    List<String> values = variable.getCategories() != null
            ? variable.getCategories().stream().map(c -> c.getName()).collect(toList())
            : Lists.newArrayList();//from w  w  w  . j  av  a2 s .com
    List<String> dtoValues = dto.getAll().getFrequenciesList().stream().map(f -> f.getValue())
            .collect(Collectors.toList());
    values.addAll(Sets.difference(Sets.newHashSet(dtoValues), Sets.newHashSet(values)));

    return values;
}