Example usage for java.util Set contains

List of usage examples for java.util Set contains

Introduction

In this page you can find the example usage for java.util Set contains.

Prototype

boolean contains(Object o);

Source Link

Document

Returns true if this set contains the specified element.

Usage

From source file:com.kantenkugel.discordbot.jdocparser.JDoc.java

/**
 * Searches the whole JavaDocs based on input string and options
 *
 * @param input The text to search for./*from w w w  .  j  ava 2s  .c o m*/
 * @param options Options refining the search. Valid options are:
 *                <ul>
 *                <li>cs - makes matching case-sensitive</li>
 *                <li>f - only methods are searched. Can't be used together with other type-specific filters.</li>
 *                <li>c - only classes are searched. Can't be used together with other type-specific filters.</li>
 *                <li>var - only values are searched. Can't be used together with other type-specific filters.</li>
 *                </ul>
 * @return Pairs of the form: Text-representation - Documentation
 * @throws PatternSyntaxException if regex was used and the regex is not valid
 */
public static Set<Pair<String, ? extends Documentation>> search(String input, String... options)
        throws PatternSyntaxException {
    Set<String> opts = Arrays.stream(options).map(String::toLowerCase).collect(Collectors.toSet());
    final boolean isCaseSensitive = opts.contains("cs");
    String key = input.toLowerCase();
    if (opts.contains("f")) {
        return docs.values().stream()
                .flatMap(cls -> cls.methodDocs.entrySet().stream().filter(mds -> mds.getKey().contains(key))
                        .map(Map.Entry::getValue).flatMap(Collection::stream))
                .filter(md -> !isCaseSensitive || md.functionName.contains(input))
                .map(md -> Pair.of(md.parent.className + " " + md.functionSig, md)).collect(Collectors.toSet());
    } else if (opts.contains("c")) {
        return docs.values().stream()
                .filter(cls -> isCaseSensitive ? cls.className.contains(input)
                        : cls.className.toLowerCase().contains(key))
                .map(cls -> Pair.of("Class " + cls.className, cls)).collect(Collectors.toSet());
    } else if (opts.contains("var")) {
        return docs.values().stream()
                .flatMap(cls -> cls.classValues.entrySet().stream().filter(val -> val.getKey().contains(key))
                        .map(Map.Entry::getValue))
                .filter(val -> !isCaseSensitive || val.name.contains(input))
                .map(val -> Pair.of(val.parent.className + " " + val.sig, val)).collect(Collectors.toSet());
    } else {
        //search all categories
        Set<Pair<String, ? extends Documentation>> results = new HashSet<>();
        for (JDocParser.ClassDocumentation classDoc : docs.values()) {
            if (isCaseSensitive ? classDoc.className.contains(input)
                    : classDoc.className.toLowerCase().contains(key))
                results.add(Pair.of("Class " + classDoc.className, classDoc));
            for (Set<JDocParser.MethodDocumentation> mdcs : classDoc.methodDocs.values()) {
                for (JDocParser.MethodDocumentation mdc : mdcs) {
                    if (isCaseSensitive ? mdc.functionName.contains(input)
                            : mdc.functionName.toLowerCase().contains(key))
                        results.add(Pair.of(mdc.parent.className + " " + mdc.functionSig, mdc));
                }
            }
            for (JDocParser.ValueDocumentation valueDoc : classDoc.classValues.values()) {
                if (isCaseSensitive ? valueDoc.name.contains(input) : valueDoc.name.toLowerCase().contains(key))
                    results.add(Pair.of(valueDoc.parent.className + " " + valueDoc.sig, valueDoc));
            }
        }
        return results;
    }
}

From source file:net.officefloor.plugin.web.http.security.store.PasswordFileCredentialStoreTest.java

/**
 * Asserts the set of roles.//from w  w  w .  jav a2  s .com
 * 
 * @param actualRoles
 *            Actual roles.
 * @param expectedRoles
 *            Expected roles.
 */
private static void assertRoles(Set<String> actualRoles, String... expectedRoles) {
    assertEquals("Incorrect number of roles", expectedRoles.length, actualRoles.size());
    for (String role : expectedRoles) {
        assertTrue("Expected to have role: '" + role + "'", actualRoles.contains(role));
    }
}

From source file:com.palantir.ptoss.cinch.core.BindingContext.java

static <T> boolean isOn(Object onObject, Set<T> changedSet) {
    if (changedSet.contains(ModelUpdates.ALL)) {
        return true;
    }//  www  .j  a v a  2 s  . com
    return changedSet.contains(onObject);
}

From source file:com.vmware.photon.controller.api.frontend.utils.SecurityGroupUtils.java

/**
 * Merge the 'self' security groups to existing security groups.
 *
 * @param existingSecurityGroups Existing security groups including both inherited and self ones.
 * @param selfSecurityGroups     'self' security groups to be merged.
 * @return The merging result and security groups not being merged.
 *//* w w w.  j  a  va 2 s . co  m*/
public static Pair<List<SecurityGroup>, List<String>> mergeSelfSecurityGroups(
        List<SecurityGroup> existingSecurityGroups, List<String> selfSecurityGroups) {

    checkNotNull(existingSecurityGroups, "Provided value for existingSecurityGroups is unacceptably null");
    checkNotNull(selfSecurityGroups, "Provided value for selfSecurityGroups is unacceptably null");

    List<SecurityGroup> mergedSecurityGroups = new ArrayList<>();
    List<String> securityGroupsNotMerged = new ArrayList<>();
    Set<String> inheritedSecurityGroupNames = new HashSet<>();

    existingSecurityGroups.stream().filter(g -> g.isInherited()).forEach(g -> {
        mergedSecurityGroups.add(g);
        inheritedSecurityGroupNames.add(g.getName());
    });

    selfSecurityGroups.forEach(g -> {
        if (!inheritedSecurityGroupNames.contains(g)) {
            mergedSecurityGroups.add(new SecurityGroup(g, false));
        } else {
            securityGroupsNotMerged.add(g);
        }
    });

    return Pair.of(mergedSecurityGroups, securityGroupsNotMerged);
}

From source file:dk.dma.ais.track.rest.resource.TrackResource.java

/** Create a Predicate<TargetInfo> out of user supplied mmsi and area information */
static Predicate<TargetInfo> createTargetFilterPredicate(Set<Integer> mmsis, Set<Area> baseAreas,
        Set<Area> areas) {
    Predicate<TargetInfo> mmsiPredicate = null;
    if (mmsis != null && mmsis.size() > 0) {
        mmsiPredicate = targetInfo -> mmsis.contains(targetInfo.getMmsi());
    }/*from   w  w w .  j av  a  2 s.c o  m*/

    Predicate<TargetInfo> baseAreaPredicate = null;
    if (baseAreas != null && baseAreas.size() > 0) {
        baseAreaPredicate = targetInfo -> baseAreas.stream()
                .anyMatch(area -> targetInfo.getPosition() != null && area.contains(targetInfo.getPosition()));
    }

    Predicate<TargetInfo> areaPredicate = null;
    if (areas != null && areas.size() > 0) {
        areaPredicate = targetInfo -> areas.stream()
                .anyMatch(area -> targetInfo.getPosition() != null && area.contains(targetInfo.getPosition()));
    }

    Predicate<TargetInfo> resultingAreaPredicate = null;
    if (baseAreaPredicate != null && areaPredicate == null) {
        resultingAreaPredicate = baseAreaPredicate;
    } else if (baseAreaPredicate != null && areaPredicate != null) {
        resultingAreaPredicate = baseAreaPredicate.and(areaPredicate);
    } else {
        resultingAreaPredicate = areaPredicate;
    }

    if (mmsiPredicate == null && resultingAreaPredicate == null)
        return t -> true;
    else if (mmsiPredicate != null && resultingAreaPredicate == null)
        return mmsiPredicate;
    else if (mmsiPredicate == null && resultingAreaPredicate != null)
        return resultingAreaPredicate;
    else
        return mmsiPredicate.or(resultingAreaPredicate);
}

From source file:gemlite.core.api.logic.LogicServices.java

private final static void checkModuleAndServiceName(String moduleName, String beanName) {
    if (StringUtils.isEmpty(moduleName))
        moduleName = simpleModuleName;/*  w ww.  j a  v a 2  s.  co  m*/
    if (services.isEmpty())
        LogicServices.initServiceMap();
    Set<String> beanNames = services.get(moduleName);
    if (beanNames == null)
        throw new GemliteException("No module:" + moduleName + ". Modules:" + services.keySet());
    if (!beanNames.contains(beanName))
        throw new GemliteException("No service:" + beanName + ". Services:" + beanNames);
}

From source file:de.tudarmstadt.ukp.dkpro.tc.core.util.ReportUtils.java

/**
 * Looks into the {@link FlexTable} and outputs general performance numbers if available
 * //w  ww .j a va  2s. c  o  m
 * @param table
 */
public static String getPerformanceOverview(FlexTable<String> table) {
    // output some general performance figures
    // TODO this is a bit of a hack. Is there a better way?
    Set<String> columnIds = new HashSet<String>(Arrays.asList(table.getColumnIds()));
    StringBuffer buffer = new StringBuffer("\n");
    if (columnIds.contains(PCT_CORRECT) && columnIds.contains(PCT_INCORRECT)) {
        int i = 0;
        buffer.append("ID\t% CORRECT\t% INCORRECT\n");
        for (String id : table.getRowIds()) {
            String correct = table.getValueAsString(id, PCT_CORRECT);
            String incorrect = table.getValueAsString(id, PCT_INCORRECT);
            buffer.append(i + "\t" + correct + "\t" + incorrect + "\n");
            i++;
        }
        buffer.append("\n");
    } else if (columnIds.contains(CORRELATION)) {
        int i = 0;
        buffer.append("ID\tCORRELATION\n");
        for (String id : table.getRowIds()) {
            String correlation = table.getValueAsString(id, CORRELATION);
            buffer.append(i + "\t" + correlation + "\n");
            i++;
        }
        buffer.append("\n");
    }
    return buffer.toString();
}

From source file:cec.easyshop.cockpits.cmscockpit.sitewizard.CMSSiteUtils.java

/**
 * @return first template from given list that is restricted to ContentPage
 *//*from   ww w . java2  s  .com*/
protected static PageTemplateModel getContentPageTemplate(final Collection<PageTemplateModel> pageTemplates) {
    final TypeModel contentPageType = Registry.getApplicationContext().getBean("typeService", TypeService.class)
            .getTypeForCode(CONTENT_PAGE);
    for (final PageTemplateModel pageTemplateModel : pageTemplates) {
        final Set<CMSPageTypeModel> restrictedPageTypes = pageTemplateModel.getRestrictedPageTypes();
        if (CollectionUtils.isNotEmpty(restrictedPageTypes) && restrictedPageTypes.contains(contentPageType)) {
            return pageTemplateModel;
        }
    }
    return null;
}

From source file:org.constretto.spring.EnvironmentAnnotationConfigurer.java

public static Environment findEnvironmentMetaAnnotation(Set<Annotation> visited, Annotation[] annotations) {
    for (Annotation annotation : annotations) {
        if (annotation instanceof Environment) {
            return (Environment) annotation;
        } else {//from   w w w  . j a va  2 s. c om
            if (!visited.contains(annotation)) {
                visited.add(annotation);
                Environment environment = findEnvironmentMetaAnnotation(visited,
                        annotation.annotationType().getAnnotations());
                if (environment != null) {
                    return environment;
                }
            }
        }
    }
    return null;
}

From source file:de.uni_potsdam.hpi.asg.logictool.helper.BDDHelper.java

public static BDD mergeBDDs(BDD bdd, NetlistVariable replaceVar, BDD replaceBdd, Netlist netlist) {

    Set<NetlistVariable> bddvars = BDDHelper.getVars(bdd, netlist);
    if (!bddvars.contains(replaceVar)) {
        logger.error("ReplaceVar not in Vars");
        return null;
    }// ww  w  .j  a v a 2s . c  o  m

    if (bddvars.size() == 1) {
        //         logger.debug("Shortcut");
        //         logger.debug("BDD: " + getFunctionString(bdd, netlist));
        //         logger.debug("ReplBDD: " + getFunctionString(replaceBdd, netlist));
        //         logger.debug("ReplVar: " + replaceVar.getName());
        if (isPos(bdd, replaceVar)) {
            return replaceBdd;
        } else {
            return replaceBdd.not();
        }
        //         return replaceBdd;//.and(netlist.getFac().one());
    }

    SortedSet<NetlistVariable> newinputs = new TreeSet<>();
    newinputs.addAll(bddvars);
    newinputs.addAll(BDDHelper.getVars(replaceBdd, netlist));
    newinputs.remove(replaceVar);
    //      System.out.println("New Inp: " + newinputs.toString());

    BDD retVal = netlist.getFac().zero();
    BitSet b = new BitSet(newinputs.size());
    for (int i = 0; i < Math.pow(2, newinputs.size()); i++) {
        //         System.out.println(i + ": " + BitSetHelper.formatBitset(b, newinputs.size()));
        int index = 0;
        BDD bdd_new = bdd;
        BDD replacBdd_new = replaceBdd;
        BDD minterm = netlist.getFac().one();
        //TODO: xWITH
        for (NetlistVariable var : newinputs) {
            if (b.get(index)) {
                bdd_new = bdd_new.restrict(var.toBDD());
                replacBdd_new = replacBdd_new.restrict(var.toBDD());
                minterm = minterm.and(var.toBDD());
            } else {
                bdd_new = bdd_new.restrict(var.toNotBDD());
                replacBdd_new = replacBdd_new.restrict(var.toNotBDD());
                minterm = minterm.and(var.toNotBDD());
            }
            index++;
        }
        if (replacBdd_new.isZero()) {
            bdd_new = bdd_new.restrict(replaceVar.toNotBDD());
        } else if (replacBdd_new.isOne()) {
            bdd_new = bdd_new.restrict(replaceVar.toBDD());
        } else {
            logger.error("Repl BDD should be one or zero");
        }

        if (bdd_new.isZero()) {

        } else if (bdd_new.isOne()) {
            retVal.orWith(minterm);
        } else {
            logger.error("BDD should be one or zero");
        }

        BitSetHelper.dualNext(b);
    }

    //      if(bddvars.size() == 1) {
    //         logger.debug("RetVal: " + getFunctionString(retVal, netlist));
    //      }

    return retVal;
}