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.apache.rya.indexing.IndexPlanValidator.VarConstantIndexListPruner.java

private boolean isRelevant(TupleExpr index) {

    ConstantCollector cc = new ConstantCollector();
    index.visit(cc);//www  . j  a  va  2s. c  o m

    Map<String, Integer> indexConstantMap = cc.getConstantMap();
    int indexSpCount = cc.getSpCount();
    int indexFilterCount = cc.getFilterCount();
    Set<String> indexConstants = indexConstantMap.keySet();

    if (indexSpCount > querySpCount || indexFilterCount > queryFilterCount
            || !Sets.intersection(indexConstants, queryConstantMap.keySet()).equals(indexConstants)) {
        return false;
    }

    for (String s : indexConstants) {
        if (indexConstantMap.get(s) > queryConstantMap.get(s)) {
            return false;
        }
    }

    return true;
}

From source file:com.complexible.common.util.ClassPath.java

/**
 * Add a URL to a jar which contains classes that should be loaded into the application
 * @param theURL the URL to a jar file to load
 *///w w  w  . j a v a2  s  .  c om
public static void add(URL... theURL) {

    Set<URL> curr = Sets.newHashSet(mLoader.getURLs());
    Set<URL> newURLS = Sets.newHashSet(theURL);

    if (!Sets.intersection(curr, newURLS).isEmpty()) {
        curr.removeAll(newURLS);

        mLoader = new MutableURLClassLoader(curr.toArray(new URL[curr.size()]), mLoader.getParent());
    }

    mLoader.addURL(theURL);

    // invalidate our cache
    mClasses = null;
}

From source file:org.roda.core.common.UserUtility.java

public static void checkRoles(final User rsu, final List<String> rolesToCheck)
        throws AuthorizationDeniedException {
    // INFO 20170220 nvieira containsAll changed to set intersection (contain at
    // least one role)
    if (!rolesToCheck.isEmpty()
            && Sets.intersection(rsu.getAllRoles(), new HashSet<>(rolesToCheck)).isEmpty()) {
        final List<String> missingRoles = new ArrayList<>(rolesToCheck);
        missingRoles.removeAll(rsu.getAllRoles());

        throw new AuthorizationDeniedException(
                "The user '" + rsu.getId() + "' does not have all needed permissions", missingRoles);
    }//from  w w w .j a  v  a  2  s.c  om
}

From source file:com.textocat.textokit.commons.annotator.AnnotationRemover.java

@Override
public void typeSystemInit(TypeSystem ts) throws AnalysisEngineProcessException {
    super.typeSystemInit(ts);
    annotationType = ts.getType("uima.tcas.Annotation");
    annotationTypeExist("uima.tcas.Annotation", annotationType);
    typesToRemove = Sets.newHashSet();/*w  w  w . j  av a 2s. c  om*/
    // process namespaces
    if (namespacesToRemove != null) {
        Set<String> namespacesToRemove = Sets.newHashSet(this.namespacesToRemove);
        Iterator<Type> typeIter = ts.getTypeIterator();
        while (typeIter.hasNext()) {
            Type t = typeIter.next();
            if (isAnnotationType(t, ts)) {
                Set<String> tNamespaces = FSTypeUtils.getNamespaces(t);
                if (!Sets.intersection(tNamespaces, namespacesToRemove).isEmpty()) {
                    typesToRemove.add(t);
                }
            }
        }
    }
    // process certain types
    if (typeNamesToRemove != null) {
        for (String tName : typeNamesToRemove) {
            Type t = ts.getType(tName);
            annotationTypeExist(tName, t);
            if (isAnnotationType(t, ts)) {
                typesToRemove.add(t);
            } else {
                getLogger().warn(String.format("%s is not annotation type", t));
            }
        }
    }
    if (typesToRemove.isEmpty()) {
        getLogger().warn("Configuration of AnnotationRemover yields empty set of types to remove.");
    } else if (getLogger().isInfoEnabled()) {
        StringBuilder msgBuilder = new StringBuilder(
                "Annotations of the following types will be removed from CAS:\n");
        Joiner.on('\n').appendTo(msgBuilder, typesToRemove);
        getLogger().info(msgBuilder.toString());
    }
    typesToRemove = ImmutableSet.copyOf(typesToRemove);
}

From source file:pl.edu.icm.cermine.metadata.extraction.enhancers.TitleAuthorSplitterEnhancer.java

@Override
protected boolean enhanceMetadata(BxDocument document, DocumentMetadata metadata) {
    for (BxZone zone : document.getFirstChild()) {
        if (BxZoneLabel.MET_AUTHOR.equals(zone.getLabel())) {
            return false;
        }/*from   w w w . j  a va 2  s.co  m*/
    }

    ReadingOrderResolver roResolver = new HierarchicalReadingOrderResolver();

    BxZone toDel = null;
    BxZone toAdd1 = null;
    BxZone toAdd2 = null;

    for (BxZone zone : filterZones(document.getFirstChild())) {
        BxZone z1 = new BxZone();
        z1.setLabel(BxZoneLabel.MET_TITLE);
        BxBoundsBuilder b1 = new BxBoundsBuilder();
        BxZone z2 = new BxZone();
        z2.setLabel(BxZoneLabel.MET_AUTHOR);
        BxBoundsBuilder b2 = new BxBoundsBuilder();
        boolean wasAuthor = false;
        BxLine prev = null;
        for (BxLine line : zone) {
            if (prev != null && Sets.intersection(prev.getFontNames(), line.getFontNames()).isEmpty()) {
                String[] words = line.toText().split(" ");
                int cWordsCount = 0;
                int wordsCount = 0;
                for (String s : words) {
                    if (s.matches(".*[a-zA-Z].*")) {
                        wordsCount++;
                    }
                    if (s.matches("[A-Z].*")) {
                        cWordsCount++;
                    }
                }
                if (line.toText().contains(",") && (double) cWordsCount / (double) wordsCount > 0.7) {
                    wasAuthor = true;
                }
            }
            if (wasAuthor) {
                z2.addLine(line);
                b2.expand(line.getBounds());
            } else {
                z1.addLine(line);
                b1.expand(line.getBounds());
            }
            prev = line;
        }
        z1.setBounds(b1.getBounds());
        z2.setBounds(b2.getBounds());
        if (z1.hasChildren() && z2.hasChildren()) {
            toDel = zone;
            toAdd1 = z1;
            toAdd2 = z2;
        }
    }

    if (toDel != null) {
        List<BxZone> list = new ArrayList<BxZone>();
        list.addAll(Lists.newArrayList(document.getFirstChild()));
        list.remove(toDel);
        list.add(toAdd1);
        list.add(toAdd2);
        document.getFirstChild().setZones(list);
        try {
            roResolver.resolve(document);
        } catch (AnalysisException ex) {
        }
    }

    return false;
}

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

@Override
public Set<InetSocketAddress> activeQuorumMembers() {
    return Sets.intersection(catalogRegistered, clusterReachable);
}

From source file:com.google.devtools.build.lib.query2.engine.AllPathsFunction.java

/**
 * Returns a (new, mutable, unordered) set containing the intersection of the
 * two specified sets./*from  www .j  a v a 2s  .c  o  m*/
 */
private static <T> Set<T> intersection(Set<T> x, Set<T> y) {
    Set<T> result = new HashSet<>();
    if (x.size() > y.size()) {
        Sets.intersection(y, x).copyInto(result);
    } else {
        Sets.intersection(x, y).copyInto(result);
    }
    return result;
}

From source file:it.infn.mw.iam.core.IamIntrospectionResultAssembler.java

@Override
public Map<String, Object> assembleFrom(OAuth2AccessTokenEntity accessToken, UserInfo userInfo,
        Set<String> authScopes) {

    Map<String, Object> result = super.assembleFrom(accessToken, userInfo, authScopes);

    String trailingSlashIssuer = oidcIssuer.endsWith("/") ? oidcIssuer : oidcIssuer + "/";

    result.put(ISSUER, trailingSlashIssuer);

    try {/*from ww w  .  j a v a 2  s. c o m*/

        List<String> audience = accessToken.getJwt().getJWTClaimsSet().getAudience();

        if (audience != null && !audience.isEmpty()) {
            result.put("aud", Joiner.on(' ').join(audience));
        }

    } catch (ParseException e) {
        LOGGER.error("Error getting audience out of access token: {}", e.getMessage(), e);
    }

    // Intersection of scopes authorized for the client and scopes linked to the
    // access token
    Set<String> scopes = Sets.intersection(authScopes, accessToken.getScope());

    if (userInfo != null) {
        if (scopes.contains("profile")) {

            IamUserInfo iamUserInfo = (IamUserInfo) userInfo;

            if (!iamUserInfo.getGroups().isEmpty()) {

                result.put(GROUPS,
                        iamUserInfo.getGroups().stream().map(IamGroup::getName).collect(Collectors.toList()));
            }

            result.put(NAME, iamUserInfo.getName());
            result.put(PREFERRED_USERNAME, iamUserInfo.getPreferredUsername());
            result.put(ORGANISATION_NAME, IamProperties.INSTANCE.getOrganisationName());
        }

        if (scopes.contains("email")) {
            result.put(EMAIL, userInfo.getEmail());
        }
    }

    return result;
}

From source file:co.cask.cdap.internal.app.DefaultPluginConfigurer.java

public void addPlugins(Map<String, Plugin> plugins) {
    Set<String> duplicatePlugins = Sets.intersection(plugins.keySet(), this.plugins.keySet());
    Preconditions.checkArgument(duplicatePlugins.isEmpty(),
            "Plugins %s have been used already. Use different ids or remove duplicates", duplicatePlugins);
    this.plugins.putAll(plugins);
}

From source file:org.opendaylight.nic.compiler.IntentCompilerImpl.java

private boolean conflicts(Policy p1, Policy p2) {
    if (!Sets.intersection(p1.src(), p2.src()).isEmpty() && !Sets.intersection(p1.dst(), p2.dst()).isEmpty()) {
        return true;
    }//from  www .j  ava2s  .  co m
    return false;
}