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:com.splicemachine.mrio.api.SpliceTableMapReduceUtil.java

/**
 * Add the jars containing the given classes to the job's configuration
 * such that JobClient will ship them to the cluster and add them to
 * the DistributedCache./* www  .  j a v  a2s . c  o  m*/
 */
public static void addDependencyJars(Configuration conf, Class... classes) throws IOException {

    FileSystem localFs = FileSystem.getLocal(conf);

    Set<String> jars = new HashSet<String>();

    // Add jars that are already in the tmpjars variable
    jars.addAll(conf.getStringCollection("tmpjars"));

    // Add jars containing the specified classes
    for (Class clazz : classes) {
        if (clazz == null)
            continue;

        String pathStr = findOrCreateJar(clazz);
        if (pathStr == null) {
            LOG.warn("Could not find jar for class " + clazz + " in order to ship it to the cluster.");
            continue;
        }
        Path path = new Path(pathStr);
        if (!localFs.exists(path)) {
            LOG.warn("Could not validate jar file " + path + " for class " + clazz);
            continue;
        }
        jars.add(path.makeQualified(localFs).toString());
    }
    if (jars.isEmpty())
        return;

    conf.set("tmpjars", StringUtils.arrayToString(jars.toArray(new String[0])));
}

From source file:com.frostwire.gui.bittorrent.TorrentUtil.java

public static Set<File> getIgnorableFiles() {
    Set<File> set = TorrentUtil.getIncompleteFiles();
    set.addAll(TorrentUtil.getSkipedFiles());
    return set;/* w  ww  .  j  av  a2  s  . c om*/
}

From source file:com.intuit.tank.script.util.OwaspReader.java

/**
 * @param rawdata/*from  w  ww.  j a  v  a 2s.c  o  m*/
 * @return
 * @throws JSONException
 */
public static Set<RequestData> rawJsonToSet(String response) throws JSONException {
    Set<RequestData> map = new LinkedHashSet<RequestData>();
    JSONObject jsonObject = new JSONObject(response);
    String[] names = JSONObject.getNames(jsonObject);
    List<RequestData> itemList = new ArrayList<RequestData>();
    for (String name : names) {
        traverse(name, jsonObject, itemList, new RequestDataBuilder(RequestDataType.requestPostData.name()));
    }
    map.addAll(itemList);

    return map;
}

From source file:musite.ProteinsUtil.java

/**
 * Merge proteins with the same accessions.
 * @param proteinsList/*from   w w w. j a va 2s  . co  m*/
 * @param operation
 * @return Proteins.
 */
public static Proteins mergeProteins(List<Proteins> proteinsList, MergeOperation operationOnProteins,
        MergeOperation operationOnSites) {
    if (proteinsList == null || proteinsList.size() < 2) {
        throw new java.lang.IllegalArgumentException("Number of Proteins should be larger than 2.");
    }

    Proteins res = new ProteinsImpl();
    switch (operationOnProteins) {
    case UNION: {
        Proteins first = proteinsList.get(0);
        res.addAll(first, true, null, Proteins.ConfictHandleOption.RENAME);
        int n = proteinsList.size();
        Set<String> accs = new HashSet<String>(first.getProteinsAccessions());
        for (int i = 1; i < n; i++) {
            Proteins proteins = proteinsList.get(i);
            accs.addAll(proteins.getProteinsAccessions());

            for (String acc : accs) {
                Protein protein = proteins.getProtein(acc);
                Protein curr = res.getProtein(acc);
                Protein merged = mergeProteins(curr, protein, operationOnSites);
                if (merged != null)
                    res.addProtein(merged, Proteins.ConfictHandleOption.OVERWRITE);
            }
        }
        break;
    }
    case INTERSECTION: {
        Proteins first = proteinsList.get(0);
        int n = proteinsList.size();
        Iterator<Protein> it = first.proteinIterator();
        while (it.hasNext()) {
            Protein protein = it.next();
            String acc = protein.getAccession();
            List<Protein> pros = new ArrayList();
            for (int i = 1; i < n; i++) {
                Protein pro = proteinsList.get(i).getProtein(acc);
                if (pro == null)
                    break;
                pros.add(pro);
            }

            if (pros.size() == n - 1) {
                Protein merged = protein;
                for (Protein pro : pros) {
                    merged = mergeProteins(merged, pro, operationOnSites);
                }
                res.addProtein(merged);
            }
        }
        break;
    }
    case DIFFERENCE: {
        if (proteinsList.size() > 2) {
            throw new java.lang.IllegalArgumentException(
                    "DIFFERENCE operation" + "can only be performed on two proteins.");
        }

        Proteins first = proteinsList.get(0);
        Proteins second = proteinsList.get(1);
        Iterator<Protein> it = first.proteinIterator();
        while (it.hasNext()) {
            Protein protein = it.next();
            if (second.getProtein(protein.getAccession()) == null) {
                res.addProtein(protein);
            }
        }
        break;
    }
    default:
        throw new java.lang.UnsupportedOperationException();
    }

    return res;
}

From source file:edu.stanford.muse.groups.SimilarGroupMethods.java

/**
 * find intersections till fixed point and compute frequency for each group.
 * returns a run log and list of similar groups
 *///from   w ww  .  j ava2 s  . c  om
private static <T extends Comparable<? super T>> Set<SimilarGroup<T>> intersectGroups(
        Collection<SimilarGroup<T>> startingGroups, int minSize, GroupAlgorithmStats stats) {
    boolean fixedPoint = false;
    Set<SimilarGroup<T>> candidates = new LinkedHashSet<SimilarGroup<T>>();

    // add all the actually occurring (exact) recipient sets
    candidates.addAll(startingGroups);
    // allGroups will be the master list of all groups that we have (uptil
    // the previous iteration)

    Set<SimilarGroup<T>> newGroupsPrevIteration = candidates;
    // newGroupsPrevIteration will start off as all groups in the first iteration,
    // but reduce to only the newly derived groups at the end of each iteration.
    // we do this so as have to check for intersections only between the newly
    // derived groups and all other groups. trying to intersect each group with
    // every other group known in each iteration might be too expensive.

    int iteration = 1;
    while (!fixedPoint) {
        // newGroups will be the groups we derive in this iteration
        Set<SimilarGroup<T>> newGroups = new LinkedHashSet<SimilarGroup<T>>();

        // brute force: all to all intersection between existing groups and
        // groups newly created in prev. iteration can be made more efficient
        // by maintaining person -> group map and only intersecting those
        // groups that have at least one person in common.
        for (SimilarGroup<T> g1 : candidates)
            for (SimilarGroup<T> g2 : newGroupsPrevIteration) {
                SimilarGroup<T> newGroup = new SimilarGroup<T>(g1.intersect(g2));
                if (newGroup.size() == 0)
                    continue;
                if (newGroup.size() < minSize)
                    continue;
                // add to newGroups if we dont already have it
                if (!candidates.contains(newGroup) && !newGroups.contains(newGroup))
                    newGroups.add(newGroup);
            }

        log.info("Intersection iteration " + iteration + ": " + newGroups.size() + " new sets");
        stats.intersectionGroupsAdded.add(new GroupStats(newGroups));

        for (SimilarGroup<T> g : newGroups)
            log.debug("new group: " + g);

        candidates.addAll(newGroups);

        iteration++;
        // reached fixed point when no new groups
        fixedPoint = (newGroups.size() == 0);
        newGroupsPrevIteration = newGroups;
    }

    return candidates;
}

From source file:biz.netcentric.cq.tools.actool.configuration.CqActionsMapping.java

public static AceBean getConvertedPrivilegeBean(AceBean bean) {
    Set<String> actions = new LinkedHashSet<String>();
    Set<String> privileges = new LinkedHashSet<String>();

    if (bean.getActions() != null) {
        actions = new LinkedHashSet<String>(Arrays.asList(bean.getActions()));
    }//from   w  w w .j a v a  2 s.com
    if (bean.getPrivileges() != null) {
        privileges = new LinkedHashSet<String>(Arrays.asList(bean.getPrivileges()));
    }

    // convert cq:actions to their jcr:privileges
    for (String action : actions) {
        if (ACTIONS_MAP.containsKey(action)) { // fix for possible NPE
            privileges.addAll(ACTIONS_MAP.get(action));
        } else {
            LOG.warn("Unrecognized action: '{}' for bean {}", action, bean);
        }
    }
    bean.clearActions();
    bean.setActionsStringFromConfig("");

    StringBuilder sb = new StringBuilder();
    for (String privilege : privileges) {
        sb.append(privilege).append(",");
    }

    bean.setPrivilegesString(StringUtils.chop(sb.toString()));

    return bean;

}

From source file:com.google.appinventor.buildserver.ProjectBuilder.java

private static Set<String> getComponentTypes(List<String> files) throws IOException {
    Set<String> componentTypes = Sets.newHashSet();
    for (String f : files) {
        if (f.endsWith(".scm")) {
            File scmFile = new File(f);
            String scmContent = new String(Files.toByteArray(scmFile), PathUtil.DEFAULT_CHARSET);
            componentTypes.addAll(getTypesFromScm(scmContent));
        }/*from  www  . ja  v  a  2 s .c  o  m*/
    }
    return componentTypes;
}

From source file:co.aikar.timings.TimingsExport.java

/**
 * Checks if any pending reports are being requested, and builds one if needed.
 *///from  w w  w  . j ava  2 s.c  o  m
static void reportTimings() {
    if (requestingReport.isEmpty()) {
        return;
    }
    TimingsReportListener listeners = new TimingsReportListener(requestingReport);
    listeners.addConsoleIfNeeded();

    requestingReport.clear();
    long now = System.currentTimeMillis();
    final long lastReportDiff = now - lastReport;
    if (lastReportDiff < 60000) {
        listeners.sendMessage(ChatColor.RED + "Please wait at least 1 minute in between Timings reports. ("
                + (int) ((60000 - lastReportDiff) / 1000) + " seconds)");
        listeners.done();
        return;
    }
    final long lastStartDiff = now - TimingsManager.timingStart;
    if (lastStartDiff < 180000) {
        listeners.sendMessage(ChatColor.RED
                + "Please wait at least 3 minutes before generating a Timings report. Unlike Timings v1, v2 benefits from longer timings and is not as useful with short timings. ("
                + (int) ((180000 - lastStartDiff) / 1000) + " seconds)");
        listeners.done();
        return;
    }
    listeners.sendMessage(ChatColor.GREEN + "Preparing Timings Report...");
    lastReport = now;
    Map parent = createObject(
            // Get some basic system details about the server
            pair("version", Bukkit.getVersion()), pair("maxplayers", Bukkit.getMaxPlayers()),
            pair("start", TimingsManager.timingStart / 1000), pair("end", System.currentTimeMillis() / 1000),
            pair("sampletime", (System.currentTimeMillis() - TimingsManager.timingStart) / 1000));
    if (!TimingsManager.privacy) {
        appendObjectData(parent, pair("server", Bukkit.getServerName()),
                pair("motd", Bukkit.getServer().getMotd()),
                pair("online-mode", Bukkit.getServer().getOnlineMode()),
                pair("icon", Bukkit.getServer().getServerIcon().getData()));
    }

    final Runtime runtime = Runtime.getRuntime();
    RuntimeMXBean runtimeBean = ManagementFactory.getRuntimeMXBean();

    parent.put("system", createObject(pair("timingcost", getCost()),
            pair("name", System.getProperty("os.name")), pair("version", System.getProperty("os.version")),
            pair("jvmversion", System.getProperty("java.version")), pair("arch", System.getProperty("os.arch")),
            pair("maxmem", runtime.maxMemory()), pair("cpu", runtime.availableProcessors()),
            pair("runtime", ManagementFactory.getRuntimeMXBean().getUptime()),
            pair("flags", StringUtils.join(runtimeBean.getInputArguments(), " ")),
            pair("gc",
                    toObjectMapper(ManagementFactory.getGarbageCollectorMXBeans(),
                            input -> pair(input.getName(),
                                    toArray(input.getCollectionCount(), input.getCollectionTime()))))));

    Set<Material> tileEntityTypeSet = Sets.newHashSet();
    Set<EntityType> entityTypeSet = Sets.newHashSet();

    int size = HISTORY.size();
    TimingHistory[] history = new TimingHistory[size + 1];
    int i = 0;
    for (TimingHistory timingHistory : HISTORY) {
        tileEntityTypeSet.addAll(timingHistory.tileEntityTypeSet);
        entityTypeSet.addAll(timingHistory.entityTypeSet);
        history[i++] = timingHistory;
    }

    history[i] = new TimingHistory(); // Current snapshot
    tileEntityTypeSet.addAll(history[i].tileEntityTypeSet);
    entityTypeSet.addAll(history[i].entityTypeSet);

    Map handlers = createObject();
    for (TimingIdentifier.TimingGroup group : TimingIdentifier.GROUP_MAP.values()) {
        for (TimingHandler id : group.handlers) {
            if (!id.isTimed() && !id.isSpecial()) {
                continue;
            }
            handlers.put(id.id, toArray(group.id, id.name));
        }
    }

    parent.put("idmap",
            createObject(
                    pair("groups",
                            toObjectMapper(
                                    TimingIdentifier.GROUP_MAP.values(), group -> pair(group.id, group.name))),
                    pair("handlers", handlers), pair(
                            "worlds",
                            toObjectMapper(TimingHistory.worldMap.entrySet(),
                                    input -> pair(input.getValue(), input.getKey()))),
                    pair("tileentity",
                            toObjectMapper(tileEntityTypeSet, input -> pair(input.getId(), input.name()))),
                    pair("entity",
                            toObjectMapper(entityTypeSet, input -> pair(input.getTypeId(), input.name())))));

    // Information about loaded plugins

    parent.put("plugins",
            toObjectMapper(Bukkit.getPluginManager().getPlugins(), plugin -> pair(plugin.getName(),
                    createObject(pair("version", plugin.getDescription().getVersion()),
                            pair("description",
                                    String.valueOf(plugin.getDescription().getDescription()).trim()),
                            pair("website", plugin.getDescription().getWebsite()),
                            pair("authors", StringUtils.join(plugin.getDescription().getAuthors(), ", "))))));

    // Information on the users Config

    parent.put("config", createObject(pair("bukkit", mapAsJSON(Bukkit.spigot().getConfig(), null))));

    new TimingsExport(listeners, parent, history).start();
}

From source file:ClassFileUtilities.java

/**
 * Returns the dependencies of the given class.
 * @return a list of strings representing the used classes.
 */// w  w  w  .  ja  v a2s .  co  m
public static Set getClassDependencies(InputStream is) throws IOException {
    DataInputStream dis = new DataInputStream(is);

    if (dis.readInt() != 0xcafebabe) {
        throw new IOException("Invalid classfile");
    }

    dis.readInt();

    int len = dis.readShort();
    String[] strs = new String[len];
    Set classes = new HashSet();
    Set desc = new HashSet();

    for (int i = 1; i < len; i++) {
        int constCode = dis.readByte() & 0xff;
        switch (constCode) {
        case CONSTANT_LONG_INFO:
        case CONSTANT_DOUBLE_INFO:
            dis.readLong();
            i++;
            break;

        case CONSTANT_FIELDREF_INFO:
        case CONSTANT_METHODREF_INFO:
        case CONSTANT_INTERFACEMETHODREF_INFO:
        case CONSTANT_INTEGER_INFO:
        case CONSTANT_FLOAT_INFO:
            dis.readInt();
            break;

        case CONSTANT_CLASS_INFO:
            classes.add(new Integer(dis.readShort() & 0xffff));
            break;

        case CONSTANT_STRING_INFO:
            dis.readShort();
            break;

        case CONSTANT_NAMEANDTYPE_INFO:
            dis.readShort();
            desc.add(new Integer(dis.readShort() & 0xffff));
            break;

        case CONSTANT_UTF8_INFO:
            strs[i] = dis.readUTF();
            break;

        default:
            throw new RuntimeException("unexpected data in constant-pool:" + constCode);
        }
    }

    Set result = new HashSet();

    Iterator it = classes.iterator();
    while (it.hasNext()) {
        result.add(strs[((Integer) it.next()).intValue()]);
    }

    it = desc.iterator();
    while (it.hasNext()) {
        result.addAll(getDescriptorClasses(strs[((Integer) it.next()).intValue()]));
    }

    return result;
}

From source file:at.alladin.rmbt.qos.QoSUtil.java

/**
 * // w w  w .  java 2s  . c o  m
 * @param settings
 * @param conn
 * @param answer
 * @param lang
 * @param errorList
 * @throws SQLException 
 * @throws JSONException 
 * @throws HstoreParseException 
 * @throws IllegalAccessException 
 * @throws IllegalArgumentException 
 */
public static void evaluate(final ResourceBundle settings, final Connection conn, final TestUuid uuid,
        final JSONObject answer, String lang, final ErrorList errorList) throws SQLException,
        HstoreParseException, JSONException, IllegalArgumentException, IllegalAccessException {
    // Load Language Files for Client

    final List<String> langs = Arrays.asList(settings.getString("RMBT_SUPPORTED_LANGUAGES").split(",\\s*"));

    if (langs.contains(lang)) {
        errorList.setLanguage(lang);
    } else {
        lang = settings.getString("RMBT_DEFAULT_LANGUAGE");
    }

    if (conn != null) {

        final Client client = new Client(conn);
        final Test test = new Test(conn);

        boolean necessaryDataAvailable = false;

        if (uuid != null && uuid.getType() != null && uuid.getUuid() != null) {
            switch (uuid.getType()) {
            case OPEN_TEST_UUID:
                if (test.getTestByOpenTestUuid(UUID.fromString(uuid.getUuid())) > 0
                        && client.getClientByUid(test.getField("client_id").intValue())) {
                    necessaryDataAvailable = true;
                }
                break;
            case TEST_UUID:
                if (test.getTestByUuid(UUID.fromString(uuid.getUuid())) > 0
                        && client.getClientByUid(test.getField("client_id").intValue())) {
                    necessaryDataAvailable = true;
                }
                break;
            }
        }

        final long timeStampFullEval = System.currentTimeMillis();

        if (necessaryDataAvailable) {

            final Locale locale = new Locale(lang);
            final ResultOptions resultOptions = new ResultOptions(locale);
            final JSONArray resultList = new JSONArray();

            QoSTestResultDao resultDao = new QoSTestResultDao(conn);
            List<QoSTestResult> testResultList = resultDao.getByTestUid(test.getUid());
            if (testResultList == null || testResultList.isEmpty()) {
                throw new UnsupportedOperationException("test " + test + " has no result list");
            }
            //map that contains all test types and their result descriptions determined by the test result <-> test objectives comparison
            Map<TestType, TreeSet<ResultDesc>> resultKeys = new HashMap<>();

            //test description set:
            Set<String> testDescSet = new TreeSet<>();
            //test summary set:
            Set<String> testSummarySet = new TreeSet<>();

            //Staring timestamp for evaluation time measurement
            final long timeStampEval = System.currentTimeMillis();

            //iterate through all result entries
            for (final QoSTestResult testResult : testResultList) {

                //reset test counters
                testResult.setFailureCounter(0);
                testResult.setSuccessCounter(0);

                //get the correct class of the result;
                TestType testType = null;
                try {
                    testType = TestType.valueOf(testResult.getTestType().toUpperCase(Locale.US));
                } catch (IllegalArgumentException e) {
                    final String errorMessage = "WARNING: QoS TestType '"
                            + testResult.getTestType().toUpperCase(Locale.US)
                            + "' not supported by ControlServer. Test with UID: " + testResult.getUid()
                            + " skipped.";
                    System.out.println(errorMessage);
                    errorList.addErrorString(errorMessage);
                    testType = null;
                }

                if (testType == null) {
                    continue;
                }

                Class<? extends AbstractResult<?>> clazz = testType.getClazz();
                //parse hstore data
                final JSONObject resultJson = new JSONObject(testResult.getResults());
                AbstractResult<?> result = QoSUtil.HSTORE_PARSER.fromJSON(resultJson, clazz);
                result.setResultJson(resultJson);

                if (result != null) {
                    //add each test description key to the testDescSet (to fetch it later from the db)
                    if (testResult.getTestDescription() != null) {
                        testDescSet.add(testResult.getTestDescription());
                    }
                    if (testResult.getTestSummary() != null) {
                        testSummarySet.add(testResult.getTestSummary());
                    }
                    testResult.setResult(result);

                }

                //compare test results
                compareTestResults(testResult, result, resultKeys, testType, resultOptions);

                //resultList.put(testResult.toJson());

                //save all test results after the success and failure counters have been set
                //resultDao.updateCounter(testResult);
            }

            //ending timestamp for evaluation time measurement
            final long timeStampEvalEnd = System.currentTimeMillis();

            //-------------------------------------------------------------
            //fetch all result strings from the db
            QoSTestDescDao descDao = new QoSTestDescDao(conn, locale);

            //FIRST: get all test descriptions
            Set<String> testDescToFetchSet = testDescSet;
            testDescToFetchSet.addAll(testSummarySet);

            Map<String, String> testDescMap = descDao.getAllByKeyToMap(testDescToFetchSet);

            for (QoSTestResult testResult : testResultList) {

                //and set the test results + put each one to the result list json array
                String preParsedDesc = testDescMap.get(testResult.getTestDescription());
                if (preParsedDesc != null) {
                    String description = String.valueOf(
                            TestScriptInterpreter.interprete(testDescMap.get(testResult.getTestDescription()),
                                    QoSUtil.HSTORE_PARSER, testResult.getResult(), true, resultOptions));
                    testResult.setTestDescription(description);
                }

                //do the same for the test summary:
                String preParsedSummary = testDescMap.get(testResult.getTestSummary());
                if (preParsedSummary != null) {
                    String description = String.valueOf(
                            TestScriptInterpreter.interprete(testDescMap.get(testResult.getTestSummary()),
                                    QoSUtil.HSTORE_PARSER, testResult.getResult(), true, resultOptions));
                    testResult.setTestSummary(description);
                }

                resultList.put(testResult.toJson(uuid.getType()));
            }

            //finally put results to json
            answer.put("testresultdetail", resultList);

            JSONArray resultDescArray = new JSONArray();

            //SECOND: fetch all test result descriptions 
            for (TestType testType : resultKeys.keySet()) {
                TreeSet<ResultDesc> descSet = resultKeys.get(testType);
                //fetch results to same object
                descDao.loadToTestDesc(descSet);

                //another tree set for duplicate entries:
                //TODO: there must be a better solution 
                //(the issue is: compareTo() method returns differnt values depending on the .value attribute (if it's set or not))
                TreeSet<ResultDesc> descSetNew = new TreeSet<>();
                //add fetched results to json

                for (ResultDesc desc : descSet) {
                    if (!descSetNew.contains(desc)) {
                        descSetNew.add(desc);
                    } else {
                        for (ResultDesc d : descSetNew) {
                            if (d.compareTo(desc) == 0) {
                                d.getTestResultUidList().addAll(desc.getTestResultUidList());
                            }
                        }
                    }
                }

                for (ResultDesc desc : descSetNew) {
                    if (desc.getValue() != null) {
                        resultDescArray.put(desc.toJson());
                    }
                }

            }
            //System.out.println(resultDescArray);
            //put result descriptions to json
            answer.put("testresultdetail_desc", resultDescArray);

            QoSTestTypeDescDao testTypeDao = new QoSTestTypeDescDao(conn, locale);
            JSONArray testTypeDescArray = new JSONArray();
            for (QoSTestTypeDesc desc : testTypeDao.getAll()) {
                final JSONObject testTypeDesc = desc.toJson();
                if (testTypeDesc != null) {
                    testTypeDescArray.put(testTypeDesc);
                }
            }

            //put result descriptions to json
            answer.put("testresultdetail_testdesc", testTypeDescArray);
            JSONObject evalTimes = new JSONObject();
            evalTimes.put("eval", (timeStampEvalEnd - timeStampEval));
            evalTimes.put("full", (System.currentTimeMillis() - timeStampFullEval));
            answer.put("eval_times", evalTimes);

            //System.out.println(answer);
        } else
            errorList.addError("ERROR_REQUEST_TEST_RESULT_DETAIL_NO_UUID");

    } else
        errorList.addError("ERROR_DB_CONNECTION");
}