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.perl5.lang.perl.util.PerlPackageUtil.java

private static void recursivelyCollectPerlClassRoots(Module module, List<VirtualFile> result,
        boolean includeUnexported, Set<Module> moduleRecursionControl) {
    if (moduleRecursionControl.contains(module)) {
        return;//from   w w w  .ja v a2s.c  o m
    }
    moduleRecursionControl.add(module);

    ModuleRootManager moduleRootManager = ModuleRootManager.getInstance(module);

    addIfMissing(result, moduleRootManager.getSourceRoots(JpsPerlLibrarySourceRootType.INSTANCE));

    for (OrderEntry orderEntry : moduleRootManager.getOrderEntries()) {
        if (includeUnexported && PlatformUtils.isIntelliJ() && orderEntry instanceof JdkOrderEntry) {
            Sdk jdk = ((JdkOrderEntry) orderEntry).getJdk();
            if (jdk != null && jdk.getSdkType() == PerlSdkType.getInstance()) {
                addIfMissing(result, Arrays.asList(orderEntry.getFiles(OrderRootType.CLASSES)));
            }
        }

        if (!(orderEntry instanceof ExportableOrderEntry)) {
            continue;
        }
        if (!includeUnexported && !((ExportableOrderEntry) orderEntry).isExported()) {
            continue;
        }

        if (orderEntry instanceof LibraryOrderEntry) {
            addIfMissing(result, Arrays.asList(orderEntry.getFiles(OrderRootType.CLASSES)));
        } else if (orderEntry instanceof ModuleOrderEntry) {
            recursivelyCollectPerlClassRoots(((ModuleOrderEntry) orderEntry).getModule(), result, false,
                    moduleRecursionControl);
        }
    }

}

From source file:com.vmware.identity.openidconnect.sample.RelyingPartyController.java

private static void validateAccessToken(com.vmware.identity.openidconnect.protocol.AccessToken accessToken,
        TokenType expectedTokenType) {/*from w ww  .j  a v a2  s  .co  m*/
    validateToken(accessToken, expectedTokenType);

    String error = null;

    if (accessToken.getGroups() == null) {
        error = "missing groups claim";
    }

    if (error == null && !accessToken.getAudience().contains("rs_admin_server")) {
        error = "audience does not contain rs_admin_server";
    }

    if (error == null && !accessToken.getAudience().contains("rs_some_other_resource_server")) {
        error = "audience does not contain rs_some_other_resource_server";
    }

    String adminServerRole = accessToken.getAdminServerRole();
    Set<String> roles = new HashSet<String>();
    roles.add("Administrator");
    roles.add("ConfigurationUser");
    roles.add("RegularUser");
    roles.add("GuestUser");
    if (error == null && (adminServerRole == null || !roles.contains(adminServerRole))) {
        error = "unexpected admin_server_role value: " + adminServerRole;
    }

    if (error != null) {
        throw new IllegalStateException("access_token validation error: " + error);
    }
}

From source file:net.lldp.checksims.ChecksimsCommandLine.java

public static SubmissionPreprocessor getCommonCodeRemoval(String commonCodeDirString,
        Set<File> submissionAndArchiveDirs, String glob) throws ChecksimsException, IOException {
    // Make a file from it
    File commonCodeDir = new File(commonCodeDirString).getAbsoluteFile();

    // Verify that it's not a submission dir
    if (submissionAndArchiveDirs.contains(commonCodeDir)) {
        throw new ChecksimsException("Common code directory cannot be a submission directory!");
    }/*from w  ww  .j  a  v  a2 s  . c o  m*/

    // All right, parse common code
    Submission commonCodeSubmission = Submission.submissionFromDir(commonCodeDir, glob, true);

    if (!commonCodeSubmission.getContentAsString().isEmpty()) {
        return new CommonCodeLineRemovalPreprocessor(commonCodeSubmission);
    }

    throw new ChecksimsException("Common Code directory is empty");
}

From source file:com.baidu.bjf.remoting.protobuf.ProtobufIDLProxy.java

/**
 * to generate @Protobuf defined code for target field.
 * //w  w  w  .ja  va2 s .co m
 * @param code
 * @param field
 */
private static void generateProtobufDefinedForField(StringBuilder code, Field field, Set<String> enumNames) {
    code.append("@").append(Protobuf.class.getSimpleName()).append("(");

    String fieldType = fieldTypeMapping.get(field.getType());
    if (fieldType == null) {
        if (enumNames.contains(field.getType())) {
            fieldType = "FieldType.ENUM";
        } else {
            fieldType = "FieldType.OBJECT";
        }
    }

    code.append("fieldType=").append(fieldType);
    code.append(", order=").append(field.getTag());
    if (Label.OPTIONAL == field.getLabel()) {
        code.append(", required=false");
    } else if (Label.REQUIRED == field.getLabel()) {
        code.append(", required=true");
    }
    code.append(")\n");

}

From source file:com.jkoolcloud.tnt4j.streams.custom.kafka.interceptors.reporters.metrics.MetricsReporter.java

protected static PropertySnapshot processAttrValue(PropertySnapshot snapshot, PropertyNameBuilder propName,
        Object value) {//from   w  w w.j  a va2  s.  c  om
    if (value instanceof CompositeData) {
        CompositeData cdata = (CompositeData) value;
        Set<String> keys = cdata.getCompositeType().keySet();
        boolean isKVSet = keys.contains("key") && keys.contains("value"); // NON-NLS
        for (String key : keys) {
            Object cVal = cdata.get(key);
            if (isKVSet && "key".equals(key)) { // NON-NLS
                propName.append(Utils.toString(cVal));
            } else if (isKVSet && "value".equals(key)) { // NON-NLS
                processAttrValue(snapshot, propName, cVal);
            } else {
                processAttrValue(snapshot, propName.append(key), cVal);
            }
        }
        propName.popLevel();
    } else if (value instanceof TabularData) {
        TabularData tData = (TabularData) value;
        Collection<?> values = tData.values();
        int row = 0;
        for (Object tVal : values) {
            processAttrValue(snapshot,
                    tVal instanceof CompositeData ? propName : propName.append(padNumber(++row)), tVal);
        }
        propName.popLevel();
    } else {
        snapshot.add(propName.propString(), value);
    }
    return snapshot;
}

From source file:edu.cornell.med.icb.geo.tools.MicroarrayTrainEvaluate.java

public static void filterColumns(final Table result, final Set<String> keepSet) {
    final Vector<String> toRemove = new Vector<String>();
    for (int i = 0; i < result.getColumnNumber(); i++) {

        final String identifier = result.getIdentifier(i);
        if (!keepSet.contains(identifier)) {
            toRemove.add(identifier);/*w  w  w .ja  va2  s .co m*/
        }
    }
    for (final String columnIdf : toRemove) {
        try {
            result.removeColumn(columnIdf);
        } catch (InvalidColumnException e) {
            e.printStackTrace();
            assert false : e;
        }
    }

}

From source file:com.amalto.webapp.core.util.Util.java

public static boolean userCanWrite(ILocalUser user) {
    if (Webapp.INSTANCE.isEnterpriseVersion()) {
        Set<String> roles = user.getRoles();
        return roles.contains(ICoreConstants.ADMIN_PERMISSION)
                || roles.contains(ICoreConstants.SYSTEM_ADMIN_ROLE)
                || roles.contains(ICoreConstants.SYSTEM_INTERACTIVE_ROLE)
                || roles.contains(ICoreConstants.SYSTEM_WEB_ROLE);
    }/*from   w  w w  .  j  a  v a 2  s  .  co m*/
    return true;
}

From source file:net.solarnetwork.util.ClassUtils.java

/**
 * Get a Map of non-null bean properties for an object.
 * /*from www .  j  a v a2s . c  o  m*/
 * @param o the object to inspect
 * @param ignore a set of property names to ignore (optional)
 * @param serializeIgnore if <em>true</em> test for the {@link SerializeIgnore}
 * annotation for ignoring properties
 * @return Map (never null)
 */
public static Map<String, Object> getBeanProperties(Object o, Set<String> ignore, boolean serializeIgnore) {
    if (o == null) {
        return null;
    }
    if (ignore == null) {
        ignore = DEFAULT_BEAN_PROP_NAME_IGNORE;
    }
    Map<String, Object> result = new LinkedHashMap<String, Object>();
    BeanWrapper bean = PropertyAccessorFactory.forBeanPropertyAccess(o);
    PropertyDescriptor[] props = bean.getPropertyDescriptors();
    for (PropertyDescriptor prop : props) {
        if (prop.getReadMethod() == null) {
            continue;
        }
        String propName = prop.getName();
        if (ignore != null && ignore.contains(propName)) {
            continue;
        }
        Object propValue = bean.getPropertyValue(propName);
        if (propValue == null) {
            continue;
        }
        if (serializeIgnore) {
            Method getter = prop.getReadMethod();
            if (getter != null && getter.isAnnotationPresent(SerializeIgnore.class)) {
                continue;
            }
        }
        result.put(propName, propValue);
    }
    return result;
}

From source file:com.puppycrawl.tools.checkstyle.checks.design.VisibilityModifierCheck.java

/**
 * Returns the visibility scope for the variable.
 * @param variableDef Variable definition node.
 * @return one of "public", "private", "protected", "package"
 *///from   w w  w . ja  va  2s.  co m
private static String getVisibilityScope(DetailAST variableDef) {
    final Set<String> modifiers = getModifiers(variableDef);
    String accessModifier = PACKAGE_ACCESS_MODIFIER;
    for (final String modifier : EXPLICIT_MODS) {
        if (modifiers.contains(modifier)) {
            accessModifier = modifier;
            break;
        }
    }
    return accessModifier;
}

From source file:com.shieldsbetter.sbomg.ViewModelGenerator.java

private static void outfitModelWithList(ModelClass dest, String contextName, Set<String> listOptions,
        Object elDesc) {//ww  w .  j  a v  a 2 s  .c o  m
    boolean immutableFlag = listOptions.contains("immutable");
    boolean replaceableFlag = listOptions.contains("replaceable");

    ListElementTypeData elTypeData = outfitModelWithListElementType(dest, contextName, elDesc);
    String elTypeRaw = elTypeData.getRawTypeName();
    TypeName elType = ClassName.get("", elTypeRaw);

    String slotTypeRaw = contextName + "Key";
    TypeName slotType = ClassName.get("", slotTypeRaw);

    TypeSpec.Builder keyType = TypeSpec.classBuilder(slotTypeRaw)
            .addModifiers(Modifier.PUBLIC, Modifier.STATIC, Modifier.FINAL)
            .addMethod(MethodSpec.constructorBuilder().addModifiers(Modifier.PRIVATE)
                    .addParameter(elType, "value").addStatement("myValue = value").build())
            .addMethod(MethodSpec.methodBuilder("getValue").addModifiers(Modifier.PRIVATE).returns(elType)
                    .addStatement("return myValue").build());

    if (elTypeData.isFinal() || immutableFlag) {
        keyType.addField(elType, "myValue", Modifier.PRIVATE, Modifier.FINAL);
    } else {
        keyType.addField(elType, "myValue", Modifier.PRIVATE);
        keyType.addMethod(MethodSpec.methodBuilder("setValue").addModifiers(Modifier.PRIVATE)
                .addParameter(elType, "value").addStatement("myValue = value").build());
    }

    dest.addType(keyType.build());

    FieldSpec.Builder field = FieldSpec
            .builder(ParameterizedTypeName.get(ClassName.get("java.util", "List"), slotType),
                    "my" + contextName + "List", Modifier.PRIVATE)
            .initializer("new $T<>()", ClassName.get("java.util", "LinkedList"));

    if (!replaceableFlag) {
        field.addModifiers(Modifier.FINAL);
    }

    dest.addField(field.build());

    dest.addRootMethod("get" + contextName + "Element", elType,
            ImmutableList.of(ImmutablePair.of("index", TypeName.INT)),
            CodeBlock.builder().addStatement("return my$LList.get(index).getValue()", contextName).build());

    dest.addRootMethod("get" + contextName + "Element", elType,
            ImmutableList.of(ImmutablePair.of("key", slotType)),
            CodeBlock.builder().addStatement("int index = my$LList.indexOf(key)", contextName)
                    .addStatement("return my$LList.get(index).getValue()", contextName).build());

    // TODO: Fix this.  The generated field contians keys not elements.
    /*
    dest.addRootMethod("contains" + contextName + "Element",
        TypeName.BOOLEAN, ImmutableList.of(
            ImmutablePair.of("element", elType)),
        renderCodeBlock(LIST_CONTAINS_VALUE_METHOD_TEMPL,
                "fieldName", contextName,
                "valueParam", "element"));
    */

    if (contextName.isEmpty()) {
        String parentInterfaceName = elTypeRaw;
        if (elTypeData.isInnerClass()) {
            parentInterfaceName = dest.getName() + "." + parentInterfaceName;
        }

        dest.addImplements(ParameterizedTypeName.get(ClassName.get("", "Iterable"),
                ClassName.get("", parentInterfaceName)));
        dest.addOverriddenRootMethod("iterator",
                ParameterizedTypeName.get(ClassName.get(Iterator.class), elType), ImmutableList.of(),
                renderCodeBlock(LIST_ITERATOR_TEMPL, "elementType", elTypeRaw, "contextName", contextName,
                        "baseIterable", "my" + contextName + "List"));
    } else {
        // Gross workaround here.  JavaPoet doesn't provide any way to
        // include a random non-static import.  So we render out a template
        // that happens to include an unresolved $T, then replace it with
        // the type we want to import.
        dest.addRootMethod(CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_CAMEL, contextName),
                ParameterizedTypeName.get(ClassName.get("", "Iterable"), elType), ImmutableList.of(),
                CodeBlock.of(
                        renderTemplate(RETURN_LIST_METHOD_TEMPL, "elementType", elTypeRaw, "iteratorCode",
                                renderTemplate(LIST_ITERATOR_TEMPL, "elementType", elTypeRaw, "contextName",
                                        contextName, "baseIterable", "my" + contextName + "List")),
                        ParameterizedTypeName.get(ClassName.get(Iterator.class), elType)));
    }

    if (immutableFlag) {
        String elementParam = CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_CAMEL, contextName + "Elements");
        dest.addInitializationParameter(elementParam,
                ParameterizedTypeName.get(ClassName.get("", "Iterable"), elType));

        CodeBlock.Builder init = CodeBlock.builder().beginControlFlow("for ($T e : $L)", elType, elementParam)
                .addStatement("$LKey k = new $LKey(e);", contextName, contextName)
                .addStatement("my$LList.add(k)", contextName);

        if (!elTypeData.isLeaf()) {
            init.addStatement("subscribeIfNotNull(k)");
        }

        init.endControlFlow();
        dest.addInitializationCode(init.build());
    }

    if (replaceableFlag) {
        dest.addListenerEvent(contextName + "Replaced", ImmutableList.of(ImmutablePair.of("newValue",
                ParameterizedTypeName.get(ClassName.get("java.util", "List"), elType))));

        dest.addRootMethod("replace" + contextName, TypeName.VOID,
                ImmutableList.of(ImmutablePair.of("elements",
                        ParameterizedTypeName.get(ClassName.get("", "Iterable"), elType))),
                renderCodeBlock(REPLACE_LIST_METHOD_TEMPL, "contextName", contextName, "elementType", elTypeRaw,
                        "parentType", dest.getName(), "elementsParam", "elements", "leafFlag",
                        elTypeData.isLeaf()));

        dest.addBuildCode(CodeBlock.builder().beginControlFlow("")
                .addStatement("List<$T> valueList = new $T<>()", elType, LinkedList.class)
                .beginControlFlow("for ($T s : my$LList)", slotType, contextName)
                .addStatement("valueList.add(s.getValue())").endControlFlow()
                .addStatement("l.on$LReplaced(this, " + "$T.unmodifiableList(valueList))", contextName,
                        Collections.class)
                .endControlFlow().build());
    }

    if (!elTypeData.isLeaf()) {
        dest.addField(FieldSpec
                .builder(
                        ParameterizedTypeName.get(ClassName.get("java.util", "Map"), slotType,
                                ClassName.get("", elTypeRaw + ".Subscription")),
                        "my" + contextName + "Subscriptions", Modifier.PRIVATE, Modifier.FINAL)
                .initializer("new $T<>()", ClassName.get("java.util", "HashMap")).build());

        dest.addListenerEvent(contextName + "Updated",
                ImmutableList.of(ImmutablePair.of("updatedElement", elType),
                        ImmutablePair.of("index", TypeName.INT), ImmutablePair.of("key", slotType),
                        ImmutablePair.of("event", ClassName.get("", elTypeRaw + ".Event"))));
        dest.addRootMethod(MethodSpec.methodBuilder("subscribeIfNotNull").returns(TypeName.VOID)
                .addModifiers(Modifier.PRIVATE).addParameter(slotType, "key", Modifier.FINAL)
                .addCode(renderCodeBlock(SUBSCRIBE_IF_NOT_NULL_TEMPL, "keyParam", "key", "fieldName",
                        contextName, "fieldType", elTypeRaw, "parentType", dest.getName()))
                .build());
    }

    if (!immutableFlag) {
        if (!replaceableFlag) {
            dest.addBuildCode(CodeBlock.builder().beginControlFlow("").addStatement("int i = 0")
                    .beginControlFlow("for ($T s : my$LList)", slotType, contextName)
                    .addStatement("l.on$LAdded(this, s.getValue(), i, s)", contextName).addStatement("i++")
                    .endControlFlow().endControlFlow().build());
        }

        dest.addListenerEvent(contextName + "Added", ImmutableList.of(ImmutablePair.of("addedElement", elType),
                ImmutablePair.of("index", TypeName.INT), ImmutablePair.of("key", slotType)));
        dest.addRootMethod("add" + contextName, slotType,
                ImmutableList.of(ImmutablePair.of("newElement", elType)),
                renderCodeBlock(LIST_ADD_METHOD_TEMPL, "valueParam", "newElement", "fieldName", contextName,
                        "fieldType", elTypeRaw, "leafFlag", elTypeData.isLeaf(), "parentType", dest.getName()));

        dest.addListenerEvent(contextName + "Removed",
                ImmutableList.of(ImmutablePair.of("removedElement", elType),
                        ImmutablePair.of("index", TypeName.INT), ImmutablePair.of("key", slotType)));
        dest.addRootMethod("remove" + contextName, TypeName.VOID,
                ImmutableList.of(ImmutablePair.of("index", TypeName.INT)), renderCodeBlock(
                        LIST_REMOVE_METHOD_BY_INDEX_TEMPL, "indexParam", "index", "fieldName", contextName));
        dest.addRootMethod("remove" + contextName, TypeName.VOID,
                ImmutableList.of(ImmutablePair.of("key", slotType)),
                renderCodeBlock(LIST_REMOVE_METHOD_BY_KEY_TEMPL, "keyParam", "key", "fieldName", contextName));
        dest.addRootMethod(MethodSpec.methodBuilder("remove" + contextName).addModifiers(Modifier.PRIVATE)
                .returns(TypeName.VOID).addParameter(TypeName.INT, "index", Modifier.FINAL)
                .addParameter(slotType, "key", Modifier.FINAL)
                .addCode(renderCodeBlock(LIST_REMOVE_METHOD_CORE_TEMPL, "fieldName", contextName, "keyParam",
                        "key", "indexParam", "index", "leafFlag", elTypeData.isLeaf(), "parentType",
                        dest.getName()))
                .build());

        dest.addRootMethod("clear" + contextName, TypeName.VOID,
                ImmutableList.<ImmutablePair<String, TypeName>>of(),
                renderCodeBlock(LIST_CLEAR_METHOD_TEMPL, "fieldName", contextName));

        if (!elTypeData.isFinal()) {
            dest.addListenerEvent(contextName + "Set",
                    ImmutableList.of(ImmutablePair.of("oldValue", elType), ImmutablePair.of("newValue", elType),
                            ImmutablePair.of("index", TypeName.INT), ImmutablePair.of("key", slotType)));
            dest.addRootMethod("set" + contextName, TypeName.VOID,
                    ImmutableList.of(ImmutablePair.of("index", TypeName.INT),
                            ImmutablePair.of("newValue", elType)),
                    renderCodeBlock(LIST_SET_METHOD_BY_INDEX_TEMPL, "fieldName", contextName, "indexParam",
                            "index", "valueParam", "newValue"));
            dest.addRootMethod("set" + contextName, TypeName.VOID,
                    ImmutableList.of(ImmutablePair.of("key", slotType), ImmutablePair.of("newValue", elType)),
                    renderCodeBlock(LIST_SET_METHOD_BY_KEY_TEMPL, "keyParam", "key", "fieldName", contextName,
                            "valueParam", "newValue"));
            dest.addRootMethod(MethodSpec.methodBuilder("set" + contextName).returns(TypeName.VOID)
                    .addModifiers(Modifier.PRIVATE).addParameter(TypeName.INT, "index", Modifier.FINAL)
                    .addParameter(slotType, "key", Modifier.FINAL).addParameter(elType, "value", Modifier.FINAL)
                    .addCode(renderCodeBlock(LIST_SET_METHOD_CORE_TEMPL, "keyParam", "key", "indexParam",
                            "index", "valueParam", "value", "leafFlag", elTypeData.isLeaf(), "fieldName",
                            contextName, "fieldType", elTypeRaw, "parentType", dest.getName()))
                    .build());
        }
    }
}