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.puppycrawl.tools.checkstyle.checks.design.VisibilityModifierCheck.java

/**
 * Checks whether variable has static final modifiers.
 * @param variableDef Variable definition node.
 * @return true of variable has static final modifiers.
 *///from   ww  w  .j av a 2  s  . co  m
private static boolean isStaticFinalVariable(DetailAST variableDef) {
    final Set<String> modifiers = getModifiers(variableDef);
    return modifiers.contains(STATIC_KEYWORD) && modifiers.contains(FINAL_KEYWORD);
}

From source file:com.adobe.acs.commons.analysis.jcrchecksum.impl.JSONGenerator.java

/**
 * @param node//  w ww  .  j av  a2  s .  co  m
 * @param opts
 * @param out
 * @throws RepositoryException
 * @throws JSONException
 * @throws ValueFormatException
 * @throws IOException 
 */
private static void outputProperties(Node node, ChecksumGeneratorOptions opts, JsonWriter out)
        throws RepositoryException, ValueFormatException, IOException {
    Set<String> excludes = opts.getExcludedProperties();

    SortedMap<String, Property> props = new TreeMap<String, Property>();
    PropertyIterator propertyIterator = node.getProperties();

    // sort the properties by name as the JCR makes no guarantees on property order
    while (propertyIterator.hasNext()) {
        Property property = propertyIterator.nextProperty();
        //skip the property if it is in the excludes list
        if (excludes.contains(property.getName())) {
            continue;
        } else {
            props.put(property.getName(), property);
        }
    }

    for (Property property : props.values()) {
        outputProperty(property, opts, out);
    }
}

From source file:net.sourceforge.doddle_owl.utils.Utils.java

private static void addCompoundWord(String compoundWord, List<String> compoundWordElementList,
        List<String> tokenList, Set compoundWordSet) {
    for (int i = 0; i < tokenList.size(); i++) {
        List<String> compoundWordSizeList = new ArrayList<String>();
        for (int j = 0; compoundWordSizeList.size() != compoundWordElementList.size(); j++) {
            if ((i + j) == tokenList.size()) {
                break;
            }/*www .  j a  v a2s. c o m*/
            String nw = tokenList.get(i + j);
            if (compoundWordSet.contains(nw)) {
                continue;
            }
            compoundWordSizeList.add(nw);
        }
        if (compoundWordElementList.size() == compoundWordSizeList.size()) {
            boolean isCompoundWordList = true;
            for (int j = 0; j < compoundWordElementList.size(); j++) {
                if (!compoundWordElementList.get(j).equals(compoundWordSizeList.get(j))) {
                    isCompoundWordList = false;
                    break;
                }
            }
            if (isCompoundWordList) {
                tokenList.add(i, compoundWord);
                i++;
            }
        }
    }
}

From source file:au.org.ala.delta.intkey.model.SortingUtils.java

private static Pair<boolean[], Integer> getStatePresenceForAttribute(Attribute attr, int totalNumStates,
        OrderingType orderingType, DiagType diagType) {
    Character ch = attr.getCharacter();

    // has a boolean value for each character state. A true value
    // designates the presence of the corresponding character state
    // for the attribute.
    boolean[] statePresence = new boolean[totalNumStates];

    int numStatesPresent = 0;

    // determine which character states are present for the
    // attribute.

    if (attr.isUnknown()) {
        // treat attribute as variable
        Arrays.fill(statePresence, true);
        numStatesPresent = totalNumStates;
    } else if (attr.isInapplicable() && (orderingType == OrderingType.SEPARATE
            || (orderingType == OrderingType.DIAGNOSE && diagType == DiagType.SPECIMENS))) {
        // treat attribute as variable
        Arrays.fill(statePresence, true);
        numStatesPresent = totalNumStates;
    } else {//ww w.  java2s.c o m
        Arrays.fill(statePresence, false);

        if (ch.getCharacterType() == CharacterType.OrderedMultiState
                || ch.getCharacterType() == CharacterType.UnorderedMultiState) {
            MultiStateAttribute multiStateAttr = (MultiStateAttribute) attr;
            Set<Integer> attrPresentStates = multiStateAttr.getPresentStates();

            for (int i = 0; i < totalNumStates; i++) {
                if (attrPresentStates.contains(i + 1)) {
                    statePresence[i] = true;
                    numStatesPresent++;
                }
            }

        } else if (ch.getCharacterType() == CharacterType.IntegerNumeric) {
            IntegerCharacter intChar = (IntegerCharacter) ch;
            IntegerAttribute intAttr = (IntegerAttribute) attr;

            // for an integer character, 1 state for each value
            // between
            // the minimum and
            // maximum (inclusive), 1 state for all values below the
            // minimum, and 1 state for
            // all values above the maximum

            Set<Integer> attrPresentStates = intAttr.getPresentValues();

            int offset = intChar.getMinimumValue() - 1;

            for (int i = 0; i < totalNumStates; i++) {
                if (attrPresentStates.contains(i + offset)) {
                    statePresence[i] = true;
                    numStatesPresent++;
                }
            }

        } else if (ch.getCharacterType() == CharacterType.RealNumeric) {
            RealCharacter realChar = (RealCharacter) ch;
            RealAttribute realAttr = (RealAttribute) attr;
            FloatRange presentRange = realAttr.getPresentRange();

            // convert real value into multistate value.
            numStatesPresent = generateKeyStatesForRealCharacter(realChar, presentRange, statePresence);
        } else {
            throw new RuntimeException("Invalid character type " + ch.toString());
        }
    }

    return new Pair<boolean[], Integer>(statePresence, numStatesPresent);
}

From source file:com.janrain.backplane2.server.Scope.java

/**
 * @return a new Scope consisting of all scope values present in the first one, less the auth-req scope values in 'revoke'
 *//* ww w  .  j a  va  2 s  .com*/
public static Scope revoke(@NotNull Scope scope, @NotNull Scope revoke) {
    Map<BackplaneMessage.Field, LinkedHashSet<String>> newScope = new LinkedHashMap<BackplaneMessage.Field, LinkedHashSet<String>>();

    for (BackplaneMessage.Field scopeKey : scope.getScopeMap().keySet()) {
        Set<String> revokeValues = revoke.getScopeFieldValues(scopeKey);
        if (scopeKey.getScopeType() != ScopeType.AUTHZ_REQ || revokeValues == null || revokeValues.isEmpty()) {
            newScope.put(scopeKey, scope.getScopeMap().get(scopeKey));
        } else {
            LinkedHashSet<String> newValues = new LinkedHashSet<String>();
            for (String scopeValue : scope.getScopeFieldValues(scopeKey)) {
                if (!revokeValues.contains(scopeValue)) {
                    newValues.add(scopeValue);
                }
            }
            newScope.put(scopeKey, newValues);
        }
    }

    return new Scope(newScope);
}

From source file:it.unibo.alchemist.language.protelis.util.ProtelisLoader.java

private static void loadResourcesRecursively(final XtextResourceSet target, final String programURI,
        final Set<String> alreadyInQueue) throws IOException {
    final String realURI = (programURI.startsWith("/") ? "classpath:" : "") + programURI;
    if (!alreadyInQueue.contains(realURI)) {
        alreadyInQueue.add(realURI);/*ww  w . j a  v a2 s . c o m*/
        final URI uri = URI.createURI(realURI);
        final org.springframework.core.io.Resource protelisFile = RESOLVER.getResource(realURI);
        final InputStream is = protelisFile.getInputStream();
        final String ss = IOUtils.toString(is, "UTF-8");
        final Matcher matcher = REGEX_PROTELIS_IMPORT.matcher(ss);
        while (matcher.find()) {
            final int start = matcher.start(1);
            final int end = matcher.end(1);
            final String imp = ss.substring(start, end);
            final String classpathResource = "classpath:/" + imp.replace(":", "/") + "."
                    + PROTELIS_FILE_EXTENSION;
            loadResourcesRecursively(target, classpathResource, alreadyInQueue);
        }
        target.getResource(uri, true);
    }
}

From source file:com.newatlanta.appengine.nio.file.GaePath.java

@SuppressWarnings("unchecked")
private static void checkByteChannelOpenOptions(Set<? extends OpenOption> options) {
    if (options.contains(SYNC)) {
        throw new UnsupportedOperationException(SYNC.name());
    }//from  w w  w .  ja  va  2 s  . c  o m
    if (options.contains(DSYNC)) {
        throw new UnsupportedOperationException(DSYNC.name());
    }
    if (options.contains(DELETE_ON_CLOSE)) {
        throw new UnsupportedOperationException(DELETE_ON_CLOSE.name());
    }
    if (options.contains(APPEND)) {
        if (options.contains(READ)) {
            throw new IllegalArgumentException(
                    "Cannot specify both " + APPEND.name() + " and " + READ.name() + " options.");
        }
        if (options.contains(TRUNCATE_EXISTING)) {
            throw new IllegalArgumentException(
                    "Cannot specify both " + APPEND.name() + " and " + TRUNCATE_EXISTING.name() + " options.");
        }
        ((Set<OpenOption>) options).add(WRITE); // APPEND implies WRITE
    }
    if (!options.contains(WRITE)) { // some options ignored if not writing
        options.remove(TRUNCATE_EXISTING);
        options.remove(CREATE);
        options.remove(CREATE_NEW);
        options.remove(SPARSE); // ignored if not creating new file
    }
    if (options.contains(SPARSE)) {
        throw new UnsupportedOperationException(SPARSE.name());
    }
}

From source file:ml.shifu.shifu.core.dtrain.DTrainUtils.java

public static int getFeatureInputsCnt(ModelConfig modelConfig, List<ColumnConfig> columnConfigList,
        Set<Integer> featureSet) {
    if (modelConfig.getNormalizeType().equals(ModelNormalizeConf.NormType.ONEHOT)) {
        int inputCount = 0;
        for (ColumnConfig columnConfig : columnConfigList) {
            if (featureSet.contains(columnConfig.getColumnNum())) {
                if (columnConfig.isNumerical()) {
                    inputCount += (columnConfig.getBinBoundary().size() + 1);
                } else {
                    inputCount += (columnConfig.getBinCategory().size() + 1);
                }/*from  w  ww  .  j  a  v  a 2 s .  c o  m*/
            }
        }
        return inputCount;
    } else if (modelConfig.getNormalizeType().equals(ModelNormalizeConf.NormType.ZSCALE_ONEHOT)) {
        int inputCount = 0;
        for (ColumnConfig columnConfig : columnConfigList) {
            if (featureSet.contains(columnConfig.getColumnNum())) {
                if (columnConfig.isNumerical()) {
                    inputCount += 1;
                } else {
                    inputCount += (columnConfig.getBinCategory().size() + 1);
                }
            }
        }
        return inputCount;
    } else {
        return featureSet.size();
    }
}

From source file:com.cdd.bao.Main.java

private static void diffVocab(String[] options) throws Exception {
    String fn1 = options[0], fn2 = options[1], fn3 = options.length >= 3 ? options[2] : null;
    Util.writeln("Differences between vocab dumps...");
    Util.writeln("    OLD:" + fn1);
    Util.writeln("    NEW:" + fn2);

    InputStream istr = new FileInputStream(fn1);
    SchemaVocab sv1 = SchemaVocab.deserialise(istr, new Schema[0]); // note: giving no schemata works for this purpose
    istr.close();/*  w w w .ja va 2s. c o m*/
    istr = new FileInputStream(fn2);
    SchemaVocab sv2 = SchemaVocab.deserialise(istr, new Schema[0]); // note: giving no schemata works for this purpose
    istr.close();

    Schema schema = null;
    if (fn3 != null)
        schema = ModelSchema.deserialise(new File(fn3));

    Util.writeln("Term counts: [" + sv1.numTerms() + "] -> [" + sv2.numTerms() + "]");
    Util.writeln("Prefixes: [" + sv1.numPrefixes() + "] -> [" + sv2.numPrefixes() + "]");

    // note: only shows trees on both sides
    for (SchemaVocab.StoredTree tree1 : sv1.getTrees())
        for (SchemaVocab.StoredTree tree2 : sv2.getTrees()) {
            if (!tree1.schemaPrefix.equals(tree2.schemaPrefix) || !tree1.locator.equals(tree2.locator))
                continue;

            String info = "locator: " + tree1.locator;
            if (schema != null && tree1.schemaPrefix.equals(schema.getSchemaPrefix())) {
                Schema.Assignment assn = schema.obtainAssignment(tree1.locator);
                info = "assignment: " + assn.name + " (locator: " + tree1.locator + ")";
            }

            Util.writeln("Schema [" + tree1.schemaPrefix + "], " + info);
            Set<String> terms1 = new HashSet<>(), terms2 = new HashSet<>();
            for (SchemaTree.Node node : tree1.tree.getFlat())
                terms1.add(node.uri);
            for (SchemaTree.Node node : tree2.tree.getFlat())
                terms2.add(node.uri);

            Set<String> extra1 = new TreeSet<>(), extra2 = new TreeSet<>();
            for (String uri : terms1)
                if (!terms2.contains(uri))
                    extra1.add(uri);
            for (String uri : terms2)
                if (!terms1.contains(uri))
                    extra2.add(uri);

            Util.writeln("    terms removed: " + extra1.size());
            for (String uri : extra1)
                Util.writeln("        <" + uri + "> " + sv1.getLabel(uri));

            Util.writeln("    terms added: " + extra2.size());
            for (String uri : extra2)
                Util.writeln("        <" + uri + "> " + sv2.getLabel(uri));
        }
}

From source file:com.baasbox.db.DbHelper.java

public static boolean isConnectedAsAdmin(boolean excludeInternal) {
    OUser user = getConnection().getUser();
    Set<ORole> roles = user.getRoles();
    boolean isAdminRole = roles.contains(RoleDao.getRole(DefaultRoles.ADMIN.toString()));
    return excludeInternal ? isAdminRole && !BBConfiguration.getBaasBoxAdminUsername().equals(user.getName())
            : isAdminRole;//w  ww  . java2 s  .  c om
}