Example usage for java.util Collection add

List of usage examples for java.util Collection add

Introduction

In this page you can find the example usage for java.util Collection add.

Prototype

boolean add(E e);

Source Link

Document

Ensures that this collection contains the specified element (optional operation).

Usage

From source file:cz.muni.fi.nbs.utils.Helpers.java

public static void processResults(Collection<RunResult> runResults, String resultsDirectory) {

    resultsDir = resultsDirectory;/*from w  ww .jav  a  2 s  .c o m*/
    String benchmarkName = null;
    Map<String, Collection<Result>> results = new HashMap<>();

    Iterator<RunResult> it = runResults.iterator();

    //process the runs
    while (it.hasNext()) {
        RunResult runResult = it.next();
        Collection<BenchmarkResult> benchmarkResults = runResult.getBenchmarkResults();

        //Extract the benchmark class name.
        Collection<String> benchNames = new ArrayList<>();
        benchNames.add(runResult.getParams().getBenchmark());
        Map<String, String> denseClassNames = ClassUtils.denseClassNames(benchNames);
        //TODO: Modify for multiple results!
        String denseClassName = denseClassNames.get(denseClassNames.keySet().iterator().next());
        String[] splitName = denseClassName.split("\\.");
        StringBuilder benchmarkClass = new StringBuilder(splitName[0]);
        benchmarkName = benchmarkClass.toString();

        Iterator<BenchmarkResult> brit = benchmarkResults.iterator();

        //process the results
        while (brit.hasNext()) {

            BenchmarkResult benchmarkResult = brit.next();

            // get params
            Iterator<String> iterator = benchmarkResult.getParams().getParamsKeys().iterator();
            while (iterator.hasNext()) {
                String param = iterator.next();
                String suffix = "_" + param + "_" + benchmarkResult.getParams().getParam(param);
                benchmarkClass.append(suffix);
            }

            if (!results.containsKey(benchmarkClass.toString()))
                results.put(benchmarkClass.toString(), new ArrayList<Result>());

            Result r = benchmarkResult.getPrimaryResult();
            results.get(benchmarkClass.toString()).add(r);
        }
    }

    //output the results
    exportToHTML(results, benchmarkName, true);
    exportToPNG(results);
}

From source file:com.torodb.integration.mongo.v3m0.jstests.AbstractIntegrationTest.java

protected static Collection<Object[]> parameters(ScriptClassifier classifier) {
    IntegrationTestEnvironment ite = IntegrationTestEnvironment.CURRENT_INTEGRATION_TEST_ENVIRONMENT;

    Multimap<TestCategory, Script> scriptFor = classifier.getScriptFor(ite);

    Collection<Object[]> result = new ArrayList<>(scriptFor.size());

    for (Entry<TestCategory, Script> entry : scriptFor.entries()) {
        result.add(new Object[] { entry.getKey(), entry.getValue() });
    }/*  ww w  .j a v a2s  . c  om*/

    return result;
}

From source file:Main.java

/**
 * Answer the junction between a and b. Answer is of the same type as a.
 * //from w  w  w . j  a  v a2s.  c  om
 * @param a
 * @param b
 * @return
 */
public static Collection junction(Collection a, Collection b) {
    Collection answer = createCollection(a);
    for (Iterator i = a.iterator(); i.hasNext();) {
        Object oa = i.next();
        for (Iterator k = b.iterator(); k.hasNext();) {
            Object ob = k.next();
            if (oa.equals(ob)) {
                answer.add(oa);
            }
        }
    }
    return answer;
}

From source file:com.github.jrh3k5.plugin.maven.l10n.data.AuthoritativeMessagesProperties.java

/**
 * Parse the translation keys into their respective class representations.
 * //from   ww  w .  j a  v  a2  s .c  o  m
 * @param translationKeys
 *            The keys to be parsed.
 * @return A {@link Collection} of {@link TranslationClass} objects representing the classes represented by the given translation keys.
 */
private static Collection<TranslationClass> parseTranslationClasses(Collection<String> translationKeys) {
    final Map<String, Set<String>> classStaging = new HashMap<>();

    for (String translationKey : translationKeys) {
        final int lastPeriodPos = translationKey.lastIndexOf('.');
        if (lastPeriodPos < 0) {
            continue;
        }

        final String className = sanitizeClassName(translationKey.substring(0, lastPeriodPos));
        final String keyName = translationKey.substring(lastPeriodPos + 1);
        if (classStaging.containsKey(className)) {
            classStaging.get(className).add(keyName);
        } else {
            final Set<String> keys = new HashSet<>();
            keys.add(keyName);
            classStaging.put(className, keys);
        }
    }

    final Collection<TranslationClass> translationClasses = new ArrayList<>();
    for (Entry<String, Set<String>> stagedClass : classStaging.entrySet()) {
        translationClasses.add(new TranslationClass(stagedClass.getKey(), stagedClass.getValue()));
    }

    return translationClasses;
}

From source file:Main.java

public static <E> boolean addAll(final Collection<? super E> c, final E... array) {
    boolean result = false;

    for (final E element : array) {
        result |= c.add(element);
    }//from   ww  w  . j av  a2 s. co m

    return result;
}

From source file:com.iggroup.oss.restdoclet.plugin.util.ServiceUtils.java

/**
 * Collects documentation of controllers created by XmlDoclet. It collects
 * documentation from the current directory and all its sub-directories
 * recursively./*from  w  w w. j a  va  2 s  .c  o  m*/
 * 
 * @param start the directory to start looking for documentation.
 * @param javadocs the collection to which documentation files are added.
 */
private static void collectControllerJavadocs(final File start, final Collection<File> javadocs) {
    final ControllerJavadocFilenameFilter jfilter = new ControllerJavadocFilenameFilter();
    for (File javadoc : start.listFiles(jfilter)) {
        javadocs.add(javadoc);
        LOG.info(javadoc.getAbsolutePath());
    }
    final MavenDirectoryFilter dfilter = new MavenDirectoryFilter(true, false);
    for (File dir : start.listFiles(dfilter)) {
        collectControllerJavadocs(dir, javadocs);
    }
}

From source file:Main.java

public static <V> void get(final Map<?, ? extends V> map, final Collection<? extends Object> keys,
        final Collection<? super V> values) {
    for (final Object key : keys) {
        if (!map.containsKey(key)) {
            continue;
        }//  w ww.  jav  a  2  s  .  c  o  m

        final V value = map.get(key);
        values.add(value);
    }
}

From source file:Main.java

public static <T> Collection<Collection<T>> split(Iterable<T> coll, int size) {
    if (size < 1) {
        return Collections.emptyList();
    }/*from  w  ww  .  j a  v a2  s  . com*/
    final List<Collection<T>> ret = new ArrayList<>();
    final Iterator<T> it = coll.iterator();
    Collection<T> box = null;
    for (int i = 0; it.hasNext(); ++i) {
        if (i % size == 0) {
            if (box != null) {
                ret.add(box);
            }
            box = new ArrayList<>(size);
        }
        //noinspection ConstantConditions
        box.add(it.next());
    }
    if (box != null) {
        ret.add(box);
    }
    return ret;
}

From source file:com.kijes.ela.common.JSONSerializers.java

public static Collection<ElaUser> usersFromJson(JSONObject jsonUsers) throws InvalidDataException {
    Collection<ElaUser> elaUsers = new ArrayList<>();
    JSONArray jsonUserList = jsonUsers.getJSONArray(USER_LIST_PROPERTY);
    for (int i = 0; i < jsonUserList.length(); i++) {
        JSONObject jsonUser = jsonUserList.getJSONObject(i);
        elaUsers.add(userFromJson(jsonUser));
    }/*  ww w. j  a va 2 s.c o  m*/
    return elaUsers;
}

From source file:edu.uci.ics.asterix.test.runtime.ExecutionTest.java

private static Collection<Object[]> buildTestsInXml(String xmlfile) throws Exception {
    Collection<Object[]> testArgs = new ArrayList<Object[]>();
    TestCaseContext.Builder b = new TestCaseContext.Builder();
    for (TestCaseContext ctx : b.build(new File(PATH_BASE), xmlfile)) {
        testArgs.add(new Object[] { ctx });
    }/*from w  ww.  j  a  va  2 s  . co m*/
    return testArgs;

}