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:org.sosy_lab.cpachecker.util.predicates.invariants.ExpressionTreeInvariantSupplier.java

public void updateInvariants() {
    Set<UnmodifiableReachedSet> newReached = aggregatedReached.snapShot();
    if (!newReached.equals(lastUsedReachedSets)) {
        // if we have a former aggregated supplier we do only replace the changed parts
        Set<UnmodifiableReachedSet> oldElements = Sets.difference(lastUsedReachedSets, newReached);
        Set<UnmodifiableReachedSet> newElements = Sets.difference(newReached, lastUsedReachedSets);

        oldElements.forEach(r -> singleInvariantSuppliers.remove(r));
        newElements.forEach(r -> singleInvariantSuppliers.put(r,
                new ReachedSetBasedExpressionTreeSupplier(new LazyLocationMapping(r), cfa)));

        lastUsedReachedSets = newReached;
        lastInvariantSupplier = new AggregatedExpressionTreeSupplier(
                ImmutableSet.copyOf(singleInvariantSuppliers.values()));
    }/* w  ww. j  a  va  2s  . c  o  m*/
}

From source file:com.streamsets.pipeline.stage.processor.fieldorder.FieldOrderProcessor.java

@Override
protected void process(Record record, SingleLaneBatchMaker batchMaker) throws StageException {
    Set<String> paths = Sets.difference(record.getEscapedFieldPaths(), discardFields);

    Set<String> missingFields = Sets.difference(fields, paths);
    if (!missingFields.isEmpty() && config.missingFieldAction == MissingFieldAction.TO_ERROR) {
        throw new OnRecordErrorException(record, Errors.FIELD_ORDER_001, StringUtils.join(missingFields, ", "));
    }/*from  www.j av a 2  s .c om*/

    Set<String> extraFields = Sets.difference(paths, fields);
    if (!extraFields.isEmpty() && config.extraFieldAction == ExtraFieldAction.TO_ERROR) {
        throw new OnRecordErrorException(record, Errors.FIELD_ORDER_002, StringUtils.join(extraFields, ", "));
    }

    switch (config.outputType) {
    case LIST:
        orderToList(record);
        break;
    case LIST_MAP:
        orderToListMap(record);
        break;
    default:
        throw new IllegalArgumentException("Unknown output type: " + config.outputType);
    }
    batchMaker.addRecord(record);
}

From source file:org.dishevelled.venn.model.BinaryVennModelImpl.java

/**
 * Create a new binary venn model with the specified sets.
 *
 * @param first first set, must not be null
 * @param second second set, must not be null
 *//*  w w  w .  j  a  v  a  2 s. c  om*/
public BinaryVennModelImpl(final Set<? extends E> first, final Set<? extends E> second) {
    if (first == null) {
        throw new IllegalArgumentException("first must not be null");
    }
    if (second == null) {
        throw new IllegalArgumentException("second must not be null");
    }

    // todo  defensive copy?
    this.first = new ObservableSetImpl(first);
    this.second = new ObservableSetImpl(second);
    firstOnly = Sets.difference(this.first, this.second);
    secondOnly = Sets.difference(this.second, this.first);
    intersection = Sets.intersection(this.first, this.second);
    union = Sets.union(this.first, this.second);
    selection = new SelectionView<E>(union, this.first, this.second);

    exclusives = new HashMap<ImmutableBitSet, Set<E>>(3);

    exclusives.put(toImmutableBitSet(0), firstOnly);
    exclusives.put(toImmutableBitSet(1), secondOnly);

    exclusives.put(toImmutableBitSet(0, 1), intersection);
    // copy to immutable map?
}

From source file:brooklyn.entity.rebind.BasicLocationRebindSupport.java

@Override
protected void addConfig(RebindContext rebindContext, LocationMemento memento) {
    // FIXME Treat config like we do for entities; this code will disappear when locations become entities.

    // Note that the flags have been set in the constructor
    // FIXME Relies on location.config().getLocalBag() being mutable (to modify the location's own config)

    location.config().getLocalBag().putAll(memento.getLocationConfig())
            .markAll(Sets.difference(memento.getLocationConfig().keySet(), memento.getLocationConfigUnused()))
            .setDescription(memento.getLocationConfigDescription());

    for (Map.Entry<String, Object> entry : memento.getLocationConfig().entrySet()) {
        String flagName = entry.getKey();
        try {//from  w  w  w. j  a  va 2s  .co m
            Field field = FlagUtils.findFieldForFlag(flagName, location);
            Class<?> fieldType = field.getType();
            Object value = entry.getValue();

            // Field is either of type ConfigKey, or it's a vanilla java field annotated with @SetFromFlag.
            // If the former, need to look up the field value (i.e. the ConfigKey) to find out the type.
            // If the latter, just want to look at the field itself to get the type.
            // Then coerce the value we have to that type.
            // And use magic of setFieldFromFlag's magic to either set config or field as appropriate.
            if (ConfigKey.class.isAssignableFrom(fieldType)) {
                ConfigKey<?> configKey = (ConfigKey<?>) FlagUtils.getField(location, field);
                value = TypeCoercions.coerce(entry.getValue(), configKey.getTypeToken());
            } else {
                value = TypeCoercions.coerce(entry.getValue(), fieldType);
            }
            if (value != null) {
                location.config().addToLocalBag(MutableMap.of(flagName, value));
                FlagUtils.setFieldFromFlag(location, flagName, value);
            }
        } catch (NoSuchElementException e) {
            // FIXME How to do findFieldForFlag without throwing exception if it's not there?
        }
    }
}

From source file:com.tesora.dve.groupmanager.SimpleMembershipView.java

@Override
public Set<InetSocketAddress> disabledMembers() {
    return Sets.difference(allMembers(), activeQuorumMembers());
}

From source file:org.apache.provisionr.core.activities.CheckProcessesEnded.java

@Override
public void execute(DelegateExecution execution) {
    @SuppressWarnings("unchecked")
    List<String> processIds = (List<String>) execution.getVariable(variableWithProcessIds);

    List<String> ended = Lists.newArrayList(Iterables.filter(processIds, new Predicate<String>() {
        @Override/* w  w  w.jav  a2 s  . c o  m*/
        public boolean apply(String processInstanceId) {
            ProcessInstance instance = runtimeService.createProcessInstanceQuery()
                    .processInstanceId(processInstanceId).singleResult();

            return instance == null || instance.isEnded();
        }
    }));

    boolean done = (processIds.size() == ended.size());
    execution.setVariable(resultVariable, done);

    if (done) {
        LOG.info("All background processes ENDED: {}", processIds);
    } else {
        if (LOG.isInfoEnabled()) {
            LOG.info("Still waiting for: {}",
                    Sets.difference(ImmutableSet.copyOf(processIds), ImmutableSet.copyOf(ended)));
        }
    }
}

From source file:io.druid.segment.QueryableIndexStorageAdapter.java

@Override
public Iterable<String> getAvailableMetrics() {
    return Sets.difference(Sets.newHashSet(index.getColumnNames()),
            Sets.newHashSet(index.getAvailableDimensions()));
}

From source file:com.github.lukaszkusek.xml.comparator.comparators.children.cost.minimum.CostMatrixFilter.java

private Collection<INode> filterKeys(Set<INode> alreadyAssignedKeyNodes, List<INode> keyNodes) {
    return Sets.difference(Sets.newHashSet(keyNodes), alreadyAssignedKeyNodes);
}

From source file:io.prestosql.plugin.resourcegroups.StaticSelector.java

public StaticSelector(Optional<Pattern> userRegex, Optional<Pattern> sourceRegex,
        Optional<List<String>> clientTags, Optional<SelectorResourceEstimate> selectorResourceEstimate,
        Optional<String> queryType, ResourceGroupIdTemplate group) {
    this.userRegex = requireNonNull(userRegex, "userRegex is null");
    this.sourceRegex = requireNonNull(sourceRegex, "sourceRegex is null");
    requireNonNull(clientTags, "clientTags is null");
    this.clientTags = ImmutableSet.copyOf(clientTags.orElse(ImmutableList.of()));
    this.selectorResourceEstimate = requireNonNull(selectorResourceEstimate,
            "selectorResourceEstimate is null");
    this.queryType = requireNonNull(queryType, "queryType is null");
    this.group = requireNonNull(group, "group is null");

    HashSet<String> variableNames = new HashSet<>(ImmutableList.of(USER_VARIABLE, SOURCE_VARIABLE));
    userRegex.ifPresent(u -> addNamedGroups(u, variableNames));
    sourceRegex.ifPresent(s -> addNamedGroups(s, variableNames));
    this.variableNames = ImmutableSet.copyOf(variableNames);

    Set<String> unresolvedVariables = Sets.difference(group.getVariableNames(), variableNames);
    checkArgument(unresolvedVariables.isEmpty(),
            "unresolved variables %s in resource group ID '%s', available: %s\"", unresolvedVariables, group,
            variableNames);/*  ww w . j av a  2 s.  com*/
}

From source file:com.googlecode.blaisemath.graphics.swing.JGraphicSelectionHandler.java

/** 
 * Initialize for specified component//from  w  w w.  ja  v a  2  s  . c  o  m
 * @param compt the component for handling 
 */
public JGraphicSelectionHandler(JGraphicComponent compt) {
    this.component = compt;

    // highlight updates
    selection.addPropertyChangeListener(new PropertyChangeListener() {
        @Override
        public void propertyChange(PropertyChangeEvent evt) {
            Set<Graphic> old = (Set<Graphic>) evt.getOldValue();
            Set<Graphic> nue = (Set<Graphic>) evt.getNewValue();
            for (Graphic g : Sets.difference(old, nue)) {
                g.getStyleHints().remove(StyleHints.SELECTED_HINT);
            }
            for (Graphic g : Sets.difference(nue, old)) {
                g.getStyleHints().put(StyleHints.SELECTED_HINT, true);
            }
        }
    });
}