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

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

Introduction

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

Prototype

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

Source Link

Document

Returns an unmodifiable view of the intersection of two sets.

Usage

From source file:org.invenzzia.helium.gui.ui.dock.dock.AbstractPanelDock.java

@Override
public boolean supports(Dockable dockable) {
    Preconditions.checkNotNull(dockable, "Attempt to probe a null dockable.");
    Preconditions.checkState(dockable.getState() != Dockable.STATE_DISPOSED,
            "Attempt to operate on a disposed dockable.");

    return (this.constraints.isEmpty()
            || !Sets.intersection(dockable.getConstraints(), this.constraints).isEmpty())
            && (null == this.dockModel || this.dockModel == dockable.getDockModel());
}

From source file:org.dllearner.learningproblems.PosNegLPStrict.java

@Override
public void init() throws ComponentInitException {
    super.init();
    // compute neutral examples, i.e. those which are neither positive
    // nor negative (we have to take care to copy sets instead of 
    // modifying them)
    neutralExamples = Sets.intersection(getReasoner().getIndividuals(), positiveExamples);
    neutralExamples.retainAll(negativeExamples);
}

From source file:org.dllearner.experiments.Examples.java

/**
 * calculates precision based on the test set removes all training data from
 * retrieved first//from  w w  w.  java  2s  .co m
 * 
 * @param retrieved
 * @return
 */
public double precision(SortedSet<String> retrieved) {
    if (retrieved.size() == 0) {
        return 0.0d;
    }
    SortedSet<String> retrievedClean = new TreeSet<>(retrieved);
    retrievedClean.removeAll(posTrain);
    retrievedClean.removeAll(negTrain);

    int posAsPos = Sets.intersection(retrievedClean, getPosTest()).size();
    return ((double) posAsPos) / ((double) retrievedClean.size());
}

From source file:org.gradle.jvm.internal.resolve.VariantsMatcher.java

public Collection<? extends BinarySpec> filterBinaries(VariantsMetaData variantsMetaData,
        Collection<BinarySpec> binaries) {
    if (binaries.isEmpty()) {
        return binaries;
    }//from   w w w  .  j ava 2  s. c o  m
    Set<String> resolveDimensions = variantsMetaData.getNonNullVariantAxes();
    TreeMultimap<String, VariantValue> selectedVariants = TreeMultimap.create(String.CASE_INSENSITIVE_ORDER,
            SPEC_COMPARATOR);
    Set<BinarySpec> removedSpecs = Sets.newHashSet();
    for (BinarySpec binarySpec : binaries) {
        if (binarySpecType.isAssignableFrom(binarySpec.getClass())) {
            VariantsMetaData binaryVariants = DefaultVariantsMetaData.extractFrom(binarySpec,
                    schemaStore.getSchema(((BinarySpecInternal) binarySpec).getPublicType()));
            Set<String> commonsDimensions = Sets.intersection(resolveDimensions,
                    binaryVariants.getNonNullVariantAxes());
            Set<String> incompatibleDimensionTypes = VariantsMetaDataHelper
                    .determineAxesWithIncompatibleTypes(variantsMetaData, binaryVariants, commonsDimensions);
            if (incompatibleDimensionTypes.isEmpty()) {
                for (String dimension : commonsDimensions) {
                    Class<?> dimensionType = variantsMetaData.getVariantAxisType(dimension).getConcreteClass();
                    boolean isStringType = String.class == dimensionType;
                    Object requestedValue = isStringType ? variantsMetaData.getValueAsString(dimension)
                            : variantsMetaData.getValueAsType(
                                    Cast.<Class<? extends Named>>uncheckedCast(dimensionType), dimension);
                    Object binaryValue = isStringType ? binaryVariants.getValueAsString(dimension)
                            : binaryVariants.getValueAsType(
                                    Cast.<Class<? extends Named>>uncheckedCast(dimensionType), dimension);
                    VariantAxisCompatibility<Object> selector = createSelector(requestedValue);
                    if (selector.isCompatibleWithRequirement(requestedValue, binaryValue)) {
                        VariantValue value = new VariantValue(binaryValue, binarySpec);
                        SortedSet<VariantValue> variantValues = selectedVariants.get(dimension);
                        for (VariantValue variantValue : variantValues) {
                            // all the values are equal, but we store all the binaries that match that value
                            // and incrementally build a list of binaries which are excluded because of a better match
                            if (selector.betterFit(requestedValue, variantValue.value, binaryValue)) {
                                // the new value is a better fit than the old one
                                removedSpecs.add(variantValue.spec);
                            } else if (selector.betterFit(requestedValue, binaryValue, variantValue.value)) {
                                // the old value is a better fit than the new one, let's ignore the new one altogether
                                removedSpecs.add(value.spec);
                            }
                        }
                        selectedVariants.put(dimension, value);
                    } else {
                        removedSpecs.add(binarySpec);
                    }
                }
            }
        }
    }

    Set<BinarySpec> union = null;
    for (String dimension : selectedVariants.keySet()) {
        Set<BinarySpec> variantValues = ImmutableSet
                .copyOf(Iterables.transform(selectedVariants.get(dimension), VariantValue.SPEC_FUNCTION));
        union = union == null ? variantValues : Sets.union(union, variantValues);
    }
    return union == null ? Collections.<BinarySpec>emptySet() : Sets.difference(union, removedSpecs);
}

From source file:com.android.repository.testframework.MockFileOp.java

@Override
public boolean canWrite(@NonNull File file) {
    try {//from w w  w  .  j  a  v a 2  s .c o m
        return !Sets.intersection(Files.getPosixFilePermissions(toPath(new File(getAgnosticAbsPath(file)))),
                ImmutableSet.of(PosixFilePermission.OTHERS_WRITE, PosixFilePermission.GROUP_WRITE,
                        PosixFilePermission.OWNER_WRITE))
                .isEmpty();
    } catch (IOException e) {
        return false;
    }
}

From source file:org.apache.flex.compiler.internal.tree.mxml.MXMLStyleSpecifierNode.java

/**
 * Validate style.//from ww w  . j a va2 s  .c  o  m
 * 
 * @see MXMLInvalidStyleProblem
 */
private void validateStyle(MXMLTreeBuilder builder, ISourceLocation source) {
    final IDefinition definition = getDefinition();
    if (definition instanceof IStyleDefinition) {
        final IStyleDefinition styleTag = (IStyleDefinition) definition;
        final Set<String> applicableThemes = ImmutableSet.copyOf(styleTag.getThemes());
        if (!applicableThemes.isEmpty()) {
            final Set<String> themeNames = ImmutableSet.copyOf(builder.getProject().getThemeNames());
            final boolean isStyleValid = !Sets.intersection(themeNames, applicableThemes).isEmpty();
            if (!isStyleValid) {
                final String componentType;
                if (getParent() instanceof IMXMLClassReferenceNode)
                    componentType = ((IMXMLClassReferenceNode) getParent())
                            .getClassReference(builder.getProject()).getBaseName();
                else
                    componentType = "";
                final MXMLInvalidStyleProblem problem = new MXMLInvalidStyleProblem(source, this.getName(),
                        componentType, styleTag.getThemes());
                builder.addProblem(problem);
            }
        }
    }
}

From source file:com.wealdtech.collect.TreeRangedMultimap.java

@Override
public Collection<V> get(final Range<K> range) {
    // Find all items which start before this range ends
    ImmutableSet.Builder<V> startersB = ImmutableSet.builder();
    Map.Entry<K, List<V>> startEntry = startMap.floorEntry(range.upperEndpoint());
    while (startEntry != null) {
        // Because our range is [) we don't include anything on the upper endpoint itself
        if (!startEntry.getKey().equals(range.upperEndpoint())) {
            startersB.addAll(startEntry.getValue());
        }/* w  ww .  j ava 2 s  .  c o m*/
        startEntry = startMap.lowerEntry(startEntry.getKey());
    }
    final ImmutableSet<V> starters = startersB.build();

    // Final all items which end after this range starts
    ImmutableSet.Builder<V> finishersB = ImmutableSet.builder();
    Map.Entry<K, List<V>> finishEntry = endMap.ceilingEntry(range.lowerEndpoint());
    while (finishEntry != null) {
        // Because our range is [) we don't include anything on the lower endpoint itself
        if (!finishEntry.getKey().equals(range.lowerEndpoint())) {
            finishersB.addAll(finishEntry.getValue());
        }
        finishEntry = endMap.higherEntry(finishEntry.getKey());
    }
    final ImmutableSet<V> finishers = finishersB.build();

    // Our result is everything which is in both sets
    return Sets.intersection(starters, finishers);
}

From source file:org.trnltk.morphology.morphotactics.PrecachingSuffixFormSequenceApplier.java

@Override
public String apply(SuffixFormSequence suffixFormSequence, Set<PhoneticAttribute> phoneticAttributesOfSurface) {
    final Sets.SetView<PhoneticAttribute> intersection = Sets.intersection(MODIFIER_ATTRIBUTES,
            phoneticAttributesOfSurface);
    return this.suffixFormSequenceTable.get(suffixFormSequence, intersection);
}

From source file:com.opengamma.engine.depgraph.GetFunctionsStep.java

/**
 * Removes any optional flags on constraints. If the constraint is optional and the provider produced no value, then the constraint is removed. If the provider produced values for the constraint,
 * and an intersection exists, then the intersection is used. Otherwise the maximal value set is used to satisfy the original constraint.
 * /*www.j ava 2  s. c  o m*/
 * @param constraints the requested constraints, not null
 * @param properties the provider's value specification properties, not null
 * @return the builder for constraints
 */
private static ValueProperties.Builder intersectOptional(final ValueProperties constraints,
        final ValueProperties properties) {
    ValueProperties.Builder builder = constraints.copy();
    // TODO: [PLAT-3446] Return the builder immediately to recreate the observed fault
    for (String property : constraints.getProperties()) {
        final Set<String> providerValues = properties.getValues(property);
        if (providerValues != null) {
            // Remove optional flag and take intersection if there is one
            builder.notOptional(property);
            final Set<String> constrainedValues = constraints.getValues(property);
            if (!providerValues.isEmpty()) {
                if (constrainedValues.isEmpty()) {
                    builder.with(property, providerValues);
                } else {
                    final Set<String> intersection = Sets.intersection(constrainedValues, providerValues);
                    if (!intersection.isEmpty()) {
                        builder.withoutAny(property).with(property, intersection);
                    }
                }
            }
        } else {
            if (constraints.isOptional(property)) {
                // Constraint is optional, remove
                builder.withoutAny(property);
            }
        }
    }
    return builder;
}

From source file:org.mitre.uma.service.impl.DefaultUmaTokenService.java

@Override
public OAuth2AccessTokenEntity createRequestingPartyToken(OAuth2Authentication o2auth, PermissionTicket ticket,
        Policy policy) {/*from   www . j a  va 2 s  . c o  m*/
    OAuth2AccessTokenEntity token = new OAuth2AccessTokenEntity();
    AuthenticationHolderEntity authHolder = new AuthenticationHolderEntity();
    authHolder.setAuthentication(o2auth);
    authHolder = authenticationHolderRepository.save(authHolder);

    token.setAuthenticationHolder(authHolder);

    ClientDetailsEntity client = clientService.loadClientByClientId(o2auth.getOAuth2Request().getClientId());
    token.setClient(client);

    Set<String> ticketScopes = ticket.getPermission().getScopes();
    Set<String> policyScopes = policy.getScopes();

    Permission perm = new Permission();
    perm.setResourceSet(ticket.getPermission().getResourceSet());
    perm.setScopes(new HashSet<>(Sets.intersection(ticketScopes, policyScopes)));

    token.setPermissions(Sets.newHashSet(perm));

    JWTClaimsSet.Builder claims = new JWTClaimsSet.Builder();

    claims.audience(Lists.newArrayList(ticket.getPermission().getResourceSet().getId().toString()));
    claims.issuer(config.getIssuer());
    claims.jwtID(UUID.randomUUID().toString());

    if (config.getRqpTokenLifeTime() != null) {
        Date exp = new Date(System.currentTimeMillis() + config.getRqpTokenLifeTime() * 1000L);

        claims.expirationTime(exp);
        token.setExpiration(exp);
    }

    JWSAlgorithm signingAlgorithm = jwtService.getDefaultSigningAlgorithm();
    JWSHeader header = new JWSHeader(signingAlgorithm, null, null, null, null, null, null, null, null, null,
            jwtService.getDefaultSignerKeyId(), null, null);
    SignedJWT signed = new SignedJWT(header, claims.build());

    jwtService.signJwt(signed);

    token.setJwt(signed);

    tokenService.saveAccessToken(token);

    return token;
}