Example usage for java.util Set addAll

List of usage examples for java.util Set addAll

Introduction

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

Prototype

boolean addAll(Collection<? extends E> c);

Source Link

Document

Adds all of the elements in the specified collection to this set if they're not already present (optional operation).

Usage

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

public static Table filterColumnsForTask(final Table source, final List<Set<String>> labelValueGroups,
        final String identifierColumnName, Set<String> reduction)
        throws TypeMismatchException, InvalidColumnException {
    final Table result = source.copy();

    // 1. filter out columns were label is not defined.

    final Set<String> keepSet = new HashSet<String>();
    for (final Set<String> labelGroup : labelValueGroups) { // if label value is in a label group, keep this column
        keepSet.addAll(labelGroup);
    }/*from  w w w. j a  va 2s. com*/

    keepSet.add(identifierColumnName);
    // keep only those samples also in reduction:
    reduction.add(identifierColumnName);
    keepSet.retainAll(reduction);

    filterColumns(result, keepSet);
    return result;
}

From source file:com.alibaba.dubbo.governance.web.governance.module.screen.Routes.java

/**
 * ??Owner//from  w  ww.  j a  v a  2s  .co m
 * 
 * @param usernames ??
 * @param serviceNamePattern ??Glob?
 */
public static void addOwnersOfServicePattern(Set<String> usernames, String serviceNamePattern,
        OwnerService ownerDAO) {
    List<String> serviceNamePatterns = ownerDAO.findAllServiceNames();
    for (String p : serviceNamePatterns) {
        if (ParseUtils.hasIntersection(p, serviceNamePattern)) {
            List<String> list = ownerDAO.findUsernamesByServiceName(p);
            usernames.addAll(list);
        }
    }
}

From source file:com.espertech.esper.epl.core.ResultSetProcessorFactory.java

private static Set<Pair<Integer, String>> getGroupByProperties(List<ExprNode> groupByNodes)
        throws ExprValidationException {
    // Get the set of properties refered to by all group-by expression nodes.
    Set<Pair<Integer, String>> propertiesGroupBy = new HashSet<Pair<Integer, String>>();

    for (ExprNode groupByNode : groupByNodes) {
        ExprNodeIdentifierVisitor visitor = new ExprNodeIdentifierVisitor(true);
        groupByNode.accept(visitor);//from  ww w . ja  v  a2 s.co m
        List<Pair<Integer, String>> propertiesNode = visitor.getExprProperties();
        propertiesGroupBy.addAll(propertiesNode);

        // For each group-by expression node, require at least one property.
        if (propertiesNode.isEmpty()) {
            throw new ExprValidationException("Group-by expressions must refer to property names");
        }
    }

    return propertiesGroupBy;
}

From source file:com.liferay.events.global.mobile.Utils.java

public static double getInterestLikeness(EventContact me, EventContact targetContact) throws JSONException {

    JSONArray words1o = JSONFactoryUtil.createJSONArray(me.getInterests());
    JSONArray words2o = JSONFactoryUtil.createJSONArray(targetContact.getInterests());

    List<String> words1 = new ArrayList<String>();
    List<String> words2 = new ArrayList<String>();
    Map<String, Integer> count1 = new HashMap<String, Integer>();
    Map<String, Integer> count2 = new HashMap<String, Integer>();
    Map<String, Double> weight1 = new HashMap<String, Double>();
    Map<String, Double> weight2 = new HashMap<String, Double>();

    for (int i = 0; i < words1o.length(); i++) {
        JSONObject o = words1o.getJSONObject(i);

        String word = o.getString("word");
        int count = o.getInt("count");
        double weight = o.getDouble("weight");

        words1.add(word);//from   w w w  .  jav  a  2 s . c om
        count1.put(word, count);
        weight1.put(word, weight);
    }

    for (int i = 0; i < words2o.length(); i++) {
        JSONObject o = words2o.getJSONObject(i);

        String word = o.getString("word");
        int count = o.getInt("count");
        double weight = o.getDouble("weight");

        words2.add(word);
        count2.put(word, count);
        weight2.put(word, weight);
    }

    Set<String> commonWords = new HashSet<String>(words1);
    commonWords.retainAll(words2);

    Set<String> uncommonWords = new HashSet<String>(words1);
    uncommonWords.addAll(words2);
    uncommonWords.removeAll(commonWords);

    double matchedScore = 0.0;
    double unmatchedScore = 0.0;

    for (String commonWord : commonWords) {
        matchedScore += (((double) count1.get(commonWord) * weight1.get(commonWord))
                + (((double) count2.get(commonWord) * weight2.get(commonWord))));
    }

    for (String uncommonWord : uncommonWords) {
        if (words1.contains(uncommonWord)) {
            unmatchedScore += ((double) count1.get(uncommonWord) * weight1.get(uncommonWord));
        } else {
            unmatchedScore += ((double) count2.get(uncommonWord) * weight2.get(uncommonWord));
        }
    }

    return unmatchedScore > 0 ? ((matchedScore * 2.0) / (unmatchedScore + (matchedScore * 2.0))) : 1.0;
}

From source file:com.haulmont.cuba.core.global.filter.ParametersHelper.java

public static ParameterInfo[] parseQuery(String query, @Nullable QueryFilter filter) {
    Set<ParameterInfo> infos = new HashSet<>();

    Matcher matcher = QUERY_PARAMETERS_PATTERN.matcher(query);
    while (matcher.find()) {
        final ParameterInfo info = parse(matcher);
        infos.add(info);/*  ww  w  .  j av a2 s .c o  m*/
    }

    // Add parameters used by freemarker clauses
    Matcher templMatcher = TEMPL_CLAUSE_PATTERN.matcher(query);
    while (templMatcher.find()) {
        String templClause = templMatcher.group();

        Matcher paramMatcher = TEMPL_PARAM_PATTERN.matcher(templClause);
        while (paramMatcher.find()) {
            String param = paramMatcher.group();
            infos.add(parse(param, false));
        }
    }

    if (filter != null) {
        infos.addAll(filter.getParameters());
    }

    return infos.toArray(new ParameterInfo[infos.size()]);
}

From source file:io.github.moosbusch.lumpi.util.LumpiUtil.java

public static Set<Class<?>> getSuperTypes(Class<?> type, boolean includeType, boolean includeSuperClasses,
        boolean includeInterfaces) {
    Set<Class<?>> result = new LinkedHashSet<>();
    List<Class<?>> interfaces = ClassUtils.getAllInterfaces(type);
    List<Class<?>> superClasses = ClassUtils.getAllSuperclasses(type);

    if (includeType) {
        result.add(type);/*  w w w .j a  va2 s. co m*/
    }

    if (includeSuperClasses) {
        result.addAll(superClasses);
    }

    if (includeInterfaces) {
        result.addAll(interfaces);
    }

    return result;
}

From source file:edu.umass.cs.reconfiguration.ReconfigurableNode.java

private static Set<String> getAllNodes(String[] args) {
    Set<String> nodeIDs = new HashSet<String>();
    // search for START_ALL; only for backwards compatibility
    if (args[args.length - 1].equals(ReconfigurationConfig.CommandArgs.START_ALL.toString())
            // look for "start all" or "clear all" at the end
            || (args.length >= 2 && args[args.length - 1].equals(ReconfigurationConfig.CommandArgs.all)
                    && (args[args.length - 2].equals(ReconfigurationConfig.CommandArgs.start)
                            || args[args.length - 2].equals(ReconfigurationConfig.CommandArgs.clear)))) {
        nodeIDs.addAll(ReconfigurationConfig.getReconfiguratorIDs());
        nodeIDs.addAll(PaxosConfig.getActives().keySet());
    } else/*  w w w .jav  a 2 s  .  co  m*/
        for (int i = args.length - 1; i >= 0; i--)
            if ((ReconfigurationConfig.getReconfiguratorIDs().contains(args[i])
                    || PaxosConfig.getActives().keySet().contains(args[i]))
                    && !args[i].equals(ReconfigurationConfig.CommandArgs.start.toString())
                    && !args[i].equals(ReconfigurationConfig.CommandArgs.clear.toString()))
                nodeIDs.add(args[i]);
            else {
                clear = clear || args[i].equals(ReconfigurationConfig.CommandArgs.clear.toString());
                break;
            }
    return nodeIDs;
}

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

/**
 * Build the collection of submissions Checksims will be run on.
 *
 * TODO add unit tests//from  w  w  w  .  jav  a  2s  . co  m
 *
 * @param submissionDirs Directories to build submissions from
 * @param glob Glob matcher to use when building submissions
 * @param tokenizer Tokenizer to use when building submissions
 * @param recursive Whether to recursively traverse when building submissions
 * @return Collection of submissions which will be used to run Checksims
 * @throws IOException Thrown on issue reading files or traversing directories to build submissions
 */
public static Set<Submission> getSubmissions(Set<File> submissionDirs, String glob, boolean recursive,
        boolean retainEmpty) throws IOException, ChecksimsException {
    checkNotNull(submissionDirs);
    checkArgument(!submissionDirs.isEmpty(), "Must provide at least one submission directory!");
    checkNotNull(glob);

    submissionDirs = extractTurninFiles(submissionDirs);

    // Generate submissions to work on
    Set<Submission> submissions = new HashSet<>();
    for (File dir : submissionDirs) {
        if (logs != null) {
            logs.debug("Adding directory " + dir.getName());
        }

        submissions.addAll(Submission.submissionListFromDir(dir, glob, recursive));
    }

    // If not retaining empty submissions, filter the empty ones out
    if (!retainEmpty) {
        Set<Submission> submissionsNoEmpty = new HashSet<>();

        for (Submission s : submissions) {
            if (s.getContentAsString().isEmpty()) {
                if (logs != null) {
                    logs.warn("Discarding empty submission " + s.getName());
                }
            } else {
                submissionsNoEmpty.add(s);
            }
        }

        return submissionsNoEmpty;
    }

    return submissions;
}

From source file:me.vertretungsplan.parser.UntisCommonParser.java

private static Set<String> splitTeachers(String s, JSONObject data) {
    Set<String> teachers = new HashSet<>();
    if (data.optBoolean("splitTeachers", true)) {
        teachers.addAll(Arrays.asList(s.split(", ")));
    } else {//w w  w.  j a v a2s .  c om
        teachers.add(s);
    }
    return teachers;
}

From source file:com.puppycrawl.tools.checkstyle.XDocsPagesTest.java

private static Set<Node> findChildElementsByTag(Node node, String tag) {
    final Set<Node> result = new LinkedHashSet<>();

    for (Node child = node.getFirstChild(); child != null; child = child.getNextSibling()) {
        if (tag.equals(child.getNodeName())) {
            result.add(child);//from   w w w. ja  v  a 2s  .  com
        } else if (child.hasChildNodes()) {
            result.addAll(findChildElementsByTag(child, tag));
        }
    }

    return result;
}