Example usage for java.util Collections disjoint

List of usage examples for java.util Collections disjoint

Introduction

In this page you can find the example usage for java.util Collections disjoint.

Prototype

public static boolean disjoint(Collection<?> c1, Collection<?> c2) 

Source Link

Document

Returns true if the two specified collections have no elements in common.

Usage

From source file:eu.supersede.fe.application.ApplicationUtil.java

/**
 * Return the gadgets compatible with the given profiles.
 * @param profiles//from  w w w .j  av a  2s  . c o m
 */
public Set<ApplicationGadget> getApplicationsGadgetsByProfilesNames(Collection<String> profiles) {
    Set<ApplicationGadget> gadgs = new HashSet<>();
    List<Object> gadgets = template.opsForHash().values(GADGET_KEY);

    for (Object o : gadgets) {
        ApplicationGadget g = getFromString(ApplicationGadget.class, (String) o);

        if (!Collections.disjoint(g.getProfilesRequired(), profiles)) {
            gadgs.add(g);
        }
    }

    return gadgs;
}

From source file:uniol.apt.adt.ts.ParikhVector.java

/**
 * Check if two Parikh vectors are mutually disjoint. Mutually disjoint means that there is no label for which
 * both Parikh vectors have a non-zero count.
 * @param pv2 the Parikh vector to compare with.
 * @return true if the Parikh vectors are mutually disjoint.
 *//*from w w  w.j  a v  a 2 s  .  c o  m*/
public boolean mutuallyDisjoint(ParikhVector pv2) {
    return Collections.disjoint(this.occurrenceBag, pv2.occurrenceBag);
}

From source file:org.languagetool.rules.uk.TokenInflectionAgreementRule.java

@Override
public final RuleMatch[] match(AnalyzedSentence text) {
    List<RuleMatch> ruleMatches = new ArrayList<>();
    AnalyzedTokenReadings[] tokens = text.getTokensWithoutWhitespace();

    List<AnalyzedToken> adjTokenReadings = new ArrayList<>();
    AnalyzedTokenReadings adjAnalyzedTokenReadings = null;

    for (int i = 1; i < tokens.length; i++) {
        AnalyzedTokenReadings tokenReadings = tokens[i];

        String posTag0 = tokenReadings.getAnalyzedToken(0).getPOSTag();

        if (posTag0 == null) {
            //          || posTag0.equals(JLanguageTool.SENTENCE_START_TAGNAME) ){
            adjTokenReadings.clear();//from w  w w.  ja  va  2 s  . co m
            continue;
        }

        // grab initial adjective inflections

        if (adjTokenReadings.isEmpty()) {

            // no need to start checking on last token or if no noun
            if (i == tokens.length - 1)
                continue;

            //TODO: nv still can be wrong if :np/:ns is present to it's not much gain for lots of work
            if (PosTagHelper.hasPosTagPart(tokens[i], ":nv")
                    //TODO: turn back on when we can handle pron
                    || PosTagHelper.hasPosTagPart(tokens[i], "&pron")
                    || PosTagHelper.hasPosTagPart(tokens[i], "<"))
                continue;

            if (!PosTagHelper.hasPosTagPart(tokens[i + 1], "noun:")
                    || PosTagHelper.hasPosTagPart(tokens[i + 1], ":nv")
                    || PosTagHelper.hasPosTagPart(tokens[i + 1], "&pron")
                    || PosTagHelper.hasPosTagPart(tokens[i + 1], "<"))
                continue;

            //TODO: TEMP?

            if (LemmaHelper.hasLemma(tokens[i],
                    Arrays.asList("", "", "?",
                            "?", ""),
                    ":p:")
                    || LemmaHelper.hasLemma(tokens[i],
                            Arrays.asList("", "", "",
                                    "", "", ""),
                            ":n:")
                    || LemmaHelper.hasLemma(tokens[i], Arrays.asList(""), ":f:")) {
                adjTokenReadings.clear();
                break;
            }

            for (AnalyzedToken token : tokenReadings) {
                String adjPosTag = token.getPOSTag();

                if (adjPosTag == null) { // can happen for words with \u0301 or \u00AD
                    continue;
                }

                if (adjPosTag.startsWith("adj")) {

                    adjTokenReadings.add(token);
                    adjAnalyzedTokenReadings = tokenReadings;
                } else {
                    adjTokenReadings.clear();
                    break;
                }
            }

            continue;
        }

        List<AnalyzedToken> slaveTokenReadings = new ArrayList<>();

        for (AnalyzedToken token : tokenReadings) {
            String nounPosTag = token.getPOSTag();

            if (nounPosTag == null) { // can happen for words with \u0301 or \u00AD
                continue;
            }

            if (nounPosTag.startsWith("noun") && !nounPosTag.contains(NO_VIDMINOK_SUBSTR)) {

                slaveTokenReadings.add(token);
            } else if (nounPosTag.equals(JLanguageTool.SENTENCE_END_TAGNAME)
                    || nounPosTag.equals(JLanguageTool.PARAGRAPH_END_TAGNAME)) {
                continue;
            } else {
                slaveTokenReadings.clear();
                break;
            }
        }

        // no slave token - restart

        if (slaveTokenReadings.isEmpty()) {
            adjTokenReadings.clear();
            continue;
        }

        if (DEBUG) {
            System.err.println(
                    MessageFormat.format("=== Checking:\n\t{0}\n\t{1}", adjTokenReadings, slaveTokenReadings));
        }

        // perform the check

        List<InflectionHelper.Inflection> masterInflections = InflectionHelper
                .getAdjInflections(adjTokenReadings);

        List<InflectionHelper.Inflection> slaveInflections = InflectionHelper
                .getNounInflections(slaveTokenReadings);

        if (Collections.disjoint(masterInflections, slaveInflections)) {

            if (TokenInflectionExceptionHelper.isException(tokens, i, masterInflections, slaveInflections,
                    adjTokenReadings, slaveTokenReadings)) {
                adjTokenReadings.clear();
                continue;
            }

            if (DEBUG) {
                System.err.println(MessageFormat.format("=== Found:\n\t{0}\n\t",
                        adjAnalyzedTokenReadings.getToken() + ": " + masterInflections + " // "
                                + adjAnalyzedTokenReadings,
                        slaveTokenReadings.get(0).getToken() + ": " + slaveInflections + " // "
                                + slaveTokenReadings));
            }

            String msg = String.format(
                    " :     : \"%s\": [%s]  \"%s\": [%s]",
                    adjTokenReadings.get(0).getToken(), formatInflections(masterInflections, true),
                    slaveTokenReadings.get(0).getToken(), formatInflections(slaveInflections, false));

            if (PosTagHelper.hasPosTagPart(adjTokenReadings, ":m:v_rod")
                    && tokens[i].getToken().matches(".*[]")
                    && PosTagHelper.hasPosTag(slaveTokenReadings, "noun.*:m:v_dav.*")) {
                msg += ".      ..  ? -/- ? -/-? ( ?   ?? )?";
            }

            RuleMatch potentialRuleMatch = new RuleMatch(this, adjAnalyzedTokenReadings.getStartPos(),
                    tokenReadings.getEndPos(), msg, getShort());

            Synthesizer ukrainianSynthesizer = ukrainian.getSynthesizer();
            List<String> suggestions = new ArrayList<>();

            try {

                for (Inflection adjInflection : masterInflections) {
                    String genderTag = ":" + adjInflection.gender + ":";
                    String vidmTag = adjInflection._case;

                    if (!adjInflection._case.equals("v_kly") && (adjInflection.gender.equals("p")
                            || PosTagHelper.hasPosTagPart(slaveTokenReadings, genderTag))) {
                        for (AnalyzedToken nounToken : slaveTokenReadings) {

                            if (adjInflection.animMatters()) {
                                if (!nounToken.getPOSTag().contains(":" + adjInflection.animTag))
                                    continue;
                            }

                            String newNounPosTag = nounToken.getPOSTag().replaceFirst(":.:v_...",
                                    genderTag + vidmTag);

                            String[] synthesized = ukrainianSynthesizer.synthesize(nounToken, newNounPosTag,
                                    false);

                            for (String s : synthesized) {
                                String suggestion = adjAnalyzedTokenReadings.getToken() + " " + s;
                                if (!suggestions.contains(suggestion)) {
                                    suggestions.add(suggestion);
                                }
                            }
                        }
                    }
                }

                for (Inflection nounInflection : slaveInflections) {
                    String genderTag = ":" + nounInflection.gender + ":";
                    String vidmTag = nounInflection._case;

                    if (nounInflection.animMatters()) {
                        vidmTag += ":r" + nounInflection.animTag;
                    }

                    for (AnalyzedToken adjToken : adjTokenReadings) {
                        String newAdjTag = adjToken.getPOSTag().replaceFirst(":.:v_...(:r(in)?anim)?",
                                genderTag + vidmTag);

                        String[] synthesized = ukrainianSynthesizer.synthesize(adjToken, newAdjTag, false);

                        for (String s : synthesized) {
                            String suggestion = s + " " + tokenReadings.getToken();
                            if (!suggestions.contains(suggestion)) {
                                suggestions.add(suggestion);
                            }
                        }
                    }

                }

            } catch (IOException e) {
                throw new RuntimeException(e);
            }

            //        System.err.println("### " + suggestions);

            if (suggestions.size() > 0) {
                potentialRuleMatch.setSuggestedReplacements(suggestions);
            }

            ruleMatches.add(potentialRuleMatch);
        }

        adjTokenReadings.clear();
    }

    return toRuleMatchArray(ruleMatches);
}

From source file:org.wso2.carbon.appfactory.ext.Util.java

public static void checkNonModifiableRoles(String[] roles) throws UserStoreException {
    if (roles != null) {
        Set<String> securedRoles = AuthorizationMetaDataHolder.getInstance().getSecuredRoles();
        Set<String> givenRoles = new HashSet<String>(Arrays.asList(roles));

        // check if application is trying to modify secured roles
        if (!Collections.disjoint(securedRoles, givenRoles)) {
            String errorMsg = Util.getCurrentArtifactName()
                    + " is trying to modify AppFactory specific system roles."
                    + " Applications are not allowed to modify AppFactory specific system roles.";
            log.warn(errorMsg);//from  w  w  w .  j a v  a 2s .  co  m
            throw new UserStoreException(errorMsg);
        }

        // check if application is trying to modify appfactory application specific roles.
        for (String role : roles) {
            if (AppFactoryUtil.isAppRole(role)) {
                String errorMsg = Util.getCurrentArtifactName() + " is trying to modify AppFactory application "
                        + "specific system role:" + role + " Applications are not allowed to modify AppFactory "
                        + "application specific system roles.";
                log.warn(errorMsg);
                throw new UserStoreException(errorMsg);
            }
        }

    }
}

From source file:org.apache.sling.samples.urlfilter.impl.UrlFilter.java

private Resource findUrlFilterDefinitionResource(String resourceType, ResourceResolver resolver) {
    if (resourceType == null) {
        return null;
    }//from   ww w  .java  2s  . c o  m
    Resource typeResource = resolver.getResource(resourceType);
    if (typeResource == null) {
        return null;
    }

    ValueMap properties = typeResource.adaptTo(ValueMap.class);
    if (properties == null) {
        return null;
    }

    // Collections.disjoint returns true if the collections
    // have nothing in common, so when it is false, use the current resource
    if (!Collections.disjoint(properties.keySet(), PROPERTY_NAMES)) {
        return typeResource;
    } else {
        // otherwise, look at the resource type resource's super type
        return findUrlFilterDefinitionResource(typeResource.getResourceSuperType(), resolver);
    }

}

From source file:org.apache.ctakes.ytex.kernel.evaluator.SemanticTypeKernel.java

/**
 * /*from  w ww .  java  2s  . com*/
 * @param o1
 *            cui
 * @param o2
 *            cui
 * @return concepts have overlapping main semantic types, return 1, else
 *         return 0
 */
private double mainSuiCheck(Object o1, Object o2) {
    Set<Integer> tuis1 = cuiMainSuiMap.get((String) o1);
    Set<Integer> tuis2 = cuiMainSuiMap.get((String) o2);
    // only compare the two if they have a common semantic type
    if (tuis1 != null && tuis2 != null && !Collections.disjoint(tuis1, tuis2)) {
        return 1;
    } else {
        return 0;
    }
}

From source file:com.adobe.acs.commons.util.impl.UrlFilter.java

private Component findUrlFilterDefinitionComponent(Component component) {
    if (component == null) {
        return null;
    }//from   w  ww  .j a  va  2s .  c  o m

    ValueMap properties = component.getProperties();
    // Collections.disjoint returns true if the collections
    // have nothing in common, so when it is false, use the current resource
    if (!Collections.disjoint(properties.keySet(), PROPERTY_NAMES)) {
        return component;
    } else {
        // otherwise, look at the resource type resource's super type
        return findUrlFilterDefinitionComponent(component.getSuperComponent());
    }
}

From source file:com.numenta.taurus.service.TaurusNotificationService.java

/**
 * Format anomaly title// ww w .jav a2 s .  c o  m
 *
 * @param company   The company name
 * @param types     The anomaly types triggering the anomaly
 * @param timestamp The time the anomaly was fired
 * @return The formatted text suitable for OS notification
 */
String formatAnomalyTitle(String company, EnumSet<MetricType> types, long timestamp) {
    Context ctx = getService();
    String anomalyTypes = "";

    if (!Collections.disjoint(types, MetricType.STOCK_TYPES)) {
        if (types.contains(MetricType.TwitterVolume)) {
            anomalyTypes = ctx.getString(R.string.header_stock_twitter);
        } else {
            anomalyTypes = ctx.getString(R.string.header_stock);
        }
    } else if (types.contains(MetricType.TwitterVolume)) {
        anomalyTypes = ctx.getString(R.string.header_twitter);
    }
    return String.format(ctx.getString(R.string.taurus_notification_description_template), company,
            DateUtils.formatDateTime(ctx, timestamp, DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_TIME),
            anomalyTypes);
}

From source file:org.apache.kylin.cube.model.v1_4_0.CubeDesc.java

public Map<Array<TblColRef>, List<DeriveInfo>> getHostToDerivedInfo(List<TblColRef> rowCols,
        Collection<TblColRef> wantedCols) {
    Map<Array<TblColRef>, List<DeriveInfo>> result = new HashMap<Array<TblColRef>, List<DeriveInfo>>();
    for (Entry<Array<TblColRef>, List<DeriveInfo>> entry : hostToDerivedMap.entrySet()) {
        Array<TblColRef> hostCols = entry.getKey();
        boolean hostOnRow = rowCols.containsAll(Arrays.asList(hostCols.data));
        if (!hostOnRow)
            continue;

        List<DeriveInfo> wantedInfo = new ArrayList<DeriveInfo>();
        for (DeriveInfo info : entry.getValue()) {
            if (wantedCols == null || Collections.disjoint(wantedCols, Arrays.asList(info.columns)) == false) // has
                // any
                // wanted
                // columns?
                wantedInfo.add(info);//from   ww  w  . j  a v a 2s. c  o m
        }

        if (wantedInfo.size() > 0)
            result.put(hostCols, wantedInfo);
    }
    return result;
}

From source file:org.apache.ctakes.ytex.uima.annotators.MetaMapToCTakesAnnotator.java

/**
 * add a concept to the map of concepts for the current named entity.
 * /*from  ww w .j  a  v a  2s .  com*/
 * @param jcas
 * @param concepts
 * @param annoCandidate
 * @param cuiFeature
 * @param tuiFeature
 * @param bMedication
 * @return is this concept a medication concept? only check if
 *         checkMedications is true
 */
private boolean addConcept(JCas jcas, Map<String, OntologyConcept> concepts, Annotation annoCandidate,
        Feature cuiFeature, Feature tuiFeature, boolean bMedication) {
    String cui = annoCandidate.getStringValue(cuiFeature);
    if (concepts.containsKey(cui))
        return bMedication;
    OntologyConcept oc = new OntologyConcept(jcas);
    oc.setCode(cui);
    oc.setCodingScheme("METAMAP");
    StringArray tuiArr = (StringArray) annoCandidate.getFeatureValue(tuiFeature);
    List<String> tuis = null;
    if (tuiArr != null)
        tuis = Arrays.asList(tuiArr.toStringArray());
    concepts.put(cui, oc);
    return checkMedications && tuis != null ? !Collections.disjoint(setMedicationAbrs, tuis) : false;
}