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:lib.StubHttpProvider.java

public Set<Expectation> unfulfilledExpectations() {
    return Sets.difference(Sets.newHashSet(expectations.values()), fulfilledExpectations);
}

From source file:org.apache.lens.server.api.query.save.param.ParameterResolver.java

/**
 *
 * @return resolved query/*from w  ww  .  j  ava 2  s. c  om*/
 * @throws ParameterValueException, IllegalArgumentException
 *
 * The function resolves the provided values for the bind params.
 * A MissingParameterException is thrown if a value is not provided for one of the params
 *
 */
private String resolve() throws ParameterValueException, MissingParameterException {
    final Sets.SetView<String> unProvidedParameters = Sets.difference(parameterMap.keySet(),
            queryParameters.keySet());
    if (unProvidedParameters.size() > 0) {
        throw new MissingParameterException(unProvidedParameters);
    }
    final StringBuilder query = new StringBuilder(savedQuery.getQuery());
    for (Map.Entry<String, List<String>> parameter : queryParameters.entrySet()) {
        final String parameterName = parameter.getKey();
        final List<String> values = parameter.getValue();
        final Parameter parameterDetail = parameterMap.get(parameterName);
        final String encodedValue;
        try {
            encodedValue = ParameterCollectionTypeEncoder
                    .valueOf(parameterDetail.getCollectionType().toString())
                    .encode(parameterDetail.getDataType(), values);
        } catch (ValueEncodeException | ParameterCollectionException e) {
            throw new ParameterValueException(parameterName, values, e);
        }
        resolveParameter(query, parameterName, encodedValue);
    }
    return query.toString();
}

From source file:org.apache.aurora.scheduler.http.api.security.ShiroIniConverter.java

@Override
public Ini convert(String raw) {
    Ini ini;/*from  www.ja  v  a 2s.  c o m*/
    try {
        ini = Ini.fromResourcePath(raw);
    } catch (ConfigurationException e) {
        throw new ParameterException(getErrorString(raw, e.getMessage()), e);
    }

    Set<String> presentSections = ImmutableSortedSet.copyOf(ini.getSectionNames());
    if (presentSections.isEmpty()) {
        throw new MissingSectionsException();
    }

    Set<String> extraSections = Sets.difference(presentSections, ALLOWED_SECTION_NAMES);
    if (!extraSections.isEmpty()) {
        throw new ExtraSectionsException(extraSections);
    }

    return ini;
}

From source file:com.b2international.snowowl.snomed.core.refset.compare.RefSetRelationComparator.java

/**
 * Compare the predicate reference set to the candidate reference set.
 * //from w  ww.j av a  2s .c  o  m
 * @param members1
 *            the members of the predicate {@link SnomedRefSet reference set}
 * @param members2
 *            the members of the candidate {@link SnomedRefSet reference set}
 * @param monitor
 *            the progress monitor
 * @return the comparison results
 * 
 * @throws OperationCanceledException
 *             if the progress monitor has been cancelled
 */
public List<ReferencedComponentDelta> compare(Collection<SnomedConceptDocument> members1,
        Collection<SnomedConceptDocument> members2, IProgressMonitor monitor) {
    Set<SnomedConceptDocument> parentReferencedComponents = (Set<SnomedConceptDocument>) (members1 instanceof Set<?>
            ? members1
            : Sets.newHashSet(members1));
    Set<SnomedConceptDocument> childReferencedComponents = (Set<SnomedConceptDocument>) (members2 instanceof Set<?>
            ? members2
            : Sets.newHashSet(members2));
    Set<SnomedConceptDocument> childReferencedComponentsFiltered = Sets.difference(childReferencedComponents,
            parentReferencedComponents);

    // detect added and related
    Iterator<Collection<ReferencedComponentDelta>> addedOrSubsumedDeltaIterator = ConcurrentCollectionUtils
            .transform(childReferencedComponentsFiltered.iterator(),
                    new AddedOrRelatedReferencedComponentDeltaFunction(parentReferencedComponents));

    // manually build delta lists to be able to report progress (this may take minutes with large ref sets)
    SubMonitor subMonitor = SubMonitor.convert(monitor, 100);
    SubMonitor childMonitor = subMonitor.newChild(100);
    childMonitor.setTaskName("Comparing reference sets...");
    childMonitor.setWorkRemaining(childReferencedComponentsFiltered.size());

    List<ReferencedComponentDelta> childDeltaList = Lists.newArrayList();
    while (addedOrSubsumedDeltaIterator.hasNext()) {
        childDeltaList.addAll(addedOrSubsumedDeltaIterator.next());
        childMonitor.worked(1);
        if (childMonitor.isCanceled()) {
            throw new OperationCanceledException();
        }
    }

    return childDeltaList;
}

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

boolean register(DiscreteResourceId parent, Set<ContinuousResource> resources) {
    // short-circuit: receiving empty resource is regarded as success
    if (resources.isEmpty()) {
        return true;
    }//w w  w .  j  a  v  a2 s .  c  o  m

    Set<ContinuousResource> oldValues = childMap.putIfAbsent(parent, resources);
    if (oldValues == null) {
        return true;
    }

    Set<ContinuousResource> addedValues = Sets.difference(resources, oldValues);
    // no new value, then no-op
    if (addedValues.isEmpty()) {
        // don't write to map because all values are already stored
        return true;
    }

    Set<ContinuousResourceId> addedIds = addedValues.stream().map(ContinuousResource::id)
            .collect(Collectors.toSet());
    // if the value is not found but the same ID is found
    // (this happens only when being continuous resource)
    if (oldValues.stream().anyMatch(x -> addedIds.contains(x.id()))) {
        // no-op, but indicating failure (reject the request)
        return false;
    }
    Set<ContinuousResource> newValues = new LinkedHashSet<>(oldValues);
    newValues.addAll(addedValues);
    return childMap.replace(parent, oldValues, newValues);
}

From source file:de.decoit.siemgui.domain.events.NmapEventContent.java

/**
 * Return a set of ports that are closed but should be open.
 * These are the ports that caused a WARNING status from Nmap.
 *
 * @return Set of closed ports/*from  www. j  a  v a2  s.com*/
 */
@JsonProperty("invalid-closed-ports")
public Set<Integer> getInvalidClosedPorts() {
    Set<Integer> rv = Sets.difference(allowedPorts, scannedPorts);

    return rv;
}

From source file:eu.lp0.cursus.scoring.scores.impl.GenericRacePositionsData.java

@Override
protected LinkedListMultimap<Integer, Pilot> calculateRacePositionsWithOrder(Race race) {
    // Create a lap order list containing all pilots
    List<Pilot> lapOrder = new ArrayList<Pilot>(scores.getPilots().size());
    lapOrder.addAll(scores.getLapOrder(race));
    Set<Pilot> pilotsWithLaps = ImmutableSet.copyOf(lapOrder);
    SortedSet<Pilot> pilotsWithoutLaps = new TreeSet<Pilot>(new PilotRaceNumberComparator());
    pilotsWithoutLaps.addAll(Sets.difference(scores.getPilots(), pilotsWithLaps));
    lapOrder.addAll(pilotsWithoutLaps);/* w  w  w.j  a v  a  2s .c  o  m*/

    // Add penalties to race points
    Map<Pilot, Integer> racePoints = scores.getRacePoints(race);
    Map<Pilot, Integer> racePenalties = scores.getRacePenalties(race);
    Map<Pilot, Integer> racePointsWithPenalties = new HashMap<Pilot, Integer>(scores.getPilots().size() * 2);
    for (Pilot pilot : scores.getPilots()) {
        racePointsWithPenalties.put(pilot, racePoints.get(pilot) + racePenalties.get(pilot));
    }

    // Invert race points with ordered lists of pilots
    TreeMultimap<Integer, Pilot> invRacePoints = TreeMultimap.create(Ordering.natural(),
            Ordering.explicit(lapOrder));
    Multimaps.invertFrom(Multimaps.forMap(racePointsWithPenalties), invRacePoints);

    // Calculate race positions
    LinkedListMultimap<Integer, Pilot> racePositions = LinkedListMultimap.create();
    LinkedList<SortedSet<Pilot>> pilotPointsOrdering = new LinkedList<SortedSet<Pilot>>();
    int position = 1;

    if (simulatedToEnd) {
        Set<Pilot> simulatedRacePoints = scores.getSimulatedRacePoints(race);
        for (Integer points : invRacePoints.keySet()) {
            SortedSet<Pilot> pilots = Sets.filter(invRacePoints.get(points),
                    Predicates.not(Predicates.in(simulatedRacePoints)));
            if (!pilots.isEmpty()) {
                pilotPointsOrdering.add(pilots);
            }
        }
        for (Integer points : invRacePoints.keySet()) {
            SortedSet<Pilot> pilots = Sets.filter(invRacePoints.get(points),
                    Predicates.in(simulatedRacePoints));
            if (!pilots.isEmpty()) {
                pilotPointsOrdering.add(pilots);
            }
        }
    } else {
        for (Integer points : invRacePoints.keySet()) {
            pilotPointsOrdering.add(invRacePoints.get(points));
        }
    }

    for (SortedSet<Pilot> pilots : pilotPointsOrdering) {
        switch (equalPositioning) {
        case ALWAYS:
            // Always put pilots with the same points in the same position
            racePositions.putAll(position, pilots);
            position += pilots.size();
            break;

        case WITHOUT_LAPS:
            // Add everyone with laps (by removing pilots without laps from the set) in separate positions
            for (Pilot pilot : Sets.difference(pilots, pilotsWithoutLaps)) {
                racePositions.put(position, pilot);
                position++;
            }

            // Add everyone without laps (by removing pilots with laps from the set) in the same position
            Set<Pilot> pilots2 = Sets.difference(pilots, pilotsWithLaps);
            racePositions.putAll(position, pilots2);
            position += pilots2.size();
            break;

        case NEVER:
            // Always put pilots with the same points in separate positions
            for (Pilot pilot : pilots) {
                racePositions.put(position, pilot);
                position++;
            }
            break;
        }
    }

    return racePositions;
}

From source file:org.dllearner.utilities.owl.ConceptTransformation.java

/**
 * Expand the class expression by adding \exists r.\top for all properties r
 * that are involved in some \forall r.C on the same modal depth. 
 * @param ce the class expression to expand
 * @return/*from  w  ww .  ja v  a  2s  .  com*/
 */
public static OWLClassExpression appendSomeValuesFrom(OWLClassExpression ce) {
    // if forall semantics is someonly
    if (ce instanceof OWLObjectIntersectionOf) {
        Set<OWLClassExpression> newOperands = new HashSet<>();
        Set<OWLObjectPropertyExpression> universallyQuantifiedProperties = new HashSet<>();
        Set<OWLObjectPropertyExpression> existentiallyQuantifiedProperties = new HashSet<>();
        for (OWLClassExpression operand : ((OWLObjectIntersectionOf) ce).getOperands()) {
            newOperands.add(appendSomeValuesFrom(operand));
            if (operand instanceof OWLObjectAllValuesFrom) {
                universallyQuantifiedProperties.add(((OWLObjectAllValuesFrom) operand).getProperty());
            } else if (operand instanceof OWLObjectSomeValuesFrom) {
                existentiallyQuantifiedProperties.add(((OWLObjectSomeValuesFrom) operand).getProperty());
            }
        }
        for (OWLObjectPropertyExpression ope : Sets.difference(universallyQuantifiedProperties,
                existentiallyQuantifiedProperties)) {
            newOperands.add(df.getOWLObjectSomeValuesFrom(ope, df.getOWLThing()));
        }
        return df.getOWLObjectIntersectionOf(newOperands);
    }
    //      else if(ce instanceof OWLObjectUnionOf) {
    //         Set<OWLClassExpression> newOperands = new HashSet<OWLClassExpression>();
    //         
    //         for (OWLClassExpression operand : ((OWLObjectUnionOf) ce).getOperands()) {
    //            OWLClassExpression newOperand = appendSomeValuesFrom(operand);
    //            if(newOperand instanceof OWLObjectAllValuesFrom) {
    //               newOperand = df.getOWLObjectIntersectionOf(ce,
    //                     df.getOWLObjectSomeValuesFrom(((OWLObjectAllValuesFrom) newOperand).getProperty(), df.getOWLThing()));
    //            } 
    //            newOperands.add(newOperand);
    //         }
    //         
    //         return df.getOWLObjectUnionOf(newOperands);
    //      }
    return ce.getNNF();
}

From source file:ca.ualberta.physics.cssdp.model.Mnemonic.java

private void validate(String value) {
    List<Character> characterList = Chars.asList(value.toCharArray());
    Set<Character> characterSet = new HashSet<Character>(characterList);

    Set<Character> shouldBeEmpty = Sets.difference(characterSet, allowedChars);
    if (shouldBeEmpty.size() > 0) {
        throw new IllegalArgumentException("Mnemonic contains invalid characters: " + shouldBeEmpty
                + " \n Only these are allowed: " + allowedChars);
    }/*from  ww  w .ja v  a2s  .co  m*/

    if (value.length() > 20) {
        throw new IllegalArgumentException("Mnemonic length is too long, max is 20 characters");
    }
}

From source file:com.metamx.druid.client.BatchServerInventoryView.java

@Override
protected DruidServer updateInnerInventory(DruidServer container, String inventoryKey,
        Set<DataSegment> inventory) {
    Set<DataSegment> existing = zNodes.get(inventoryKey);
    if (existing == null) {
        throw new ISE("Trying to update an inventoryKey[%s] that didn't exist?!", inventoryKey);
    }/*from  w  w  w  .  j  a  va  2  s .  com*/

    for (DataSegment segment : Sets.difference(inventory, existing)) {
        addSingleInventory(container, segment);
    }
    for (DataSegment segment : Sets.difference(existing, inventory)) {
        removeSingleInventory(container, segment.getIdentifier());
    }
    zNodes.put(inventoryKey, inventory);

    return container;
}