Example usage for java.util ArrayList addAll

List of usage examples for java.util ArrayList addAll

Introduction

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

Prototype

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

Source Link

Document

Appends all of the elements in the specified collection to the end of this list, in the order that they are returned by the specified collection's Iterator.

Usage

From source file:gov.llnl.lc.smt.command.about.SmtAbout.java

public static ArrayList<SmtAboutRecord> getRecordsFromManifest(Object obj) {
    ArrayList<SmtAboutRecord> records = new ArrayList<SmtAboutRecord>();
    records.addAll(getRecordsFromFile(obj, "META-INF/MANIFEST.MF"));
    records.addAll(getRecordsFromFile(obj, "META-INF/Manifest.MF"));

    return records;
}

From source file:com.nuance.expertassistant.ContentCrawler.java

public static void crawl(String URL, int maxdepth) {

    final ArrayList<String> URLList1 = new ArrayList<String>();
    URLList1.addAll(listURLs(URL, 1));

    if (maxdepth == 1) {
        return;/*from   ww w . j a va2  s.  c o m*/
    }

    final ArrayList<String> URLList2 = new ArrayList<String>();

    for (int i = 0; i < URLList1.size(); i++) {
        URLList2.addAll(listURLs(URLList1.get(i), 2));
    }

    if (maxdepth == 2) {
        return;
    }

    final ArrayList<String> URLList3 = new ArrayList<String>();

    for (int i = 0; i < URLList2.size(); i++) {
        URLList3.addAll(listURLs(URLList2.get(i), 3));
    }

    if (maxdepth == 3) {
        return;
    }

    final ArrayList<String> URLList4 = new ArrayList<String>();

    for (int i = 0; i < URLList3.size(); i++) {
        URLList4.addAll(listURLs(URLList3.get(i), 4));
    }

    if (maxdepth == 4) {
        return;
    }

    final ArrayList<String> URLList5 = new ArrayList<String>();

    for (int i = 0; i < URLList4.size(); i++) {
        URLList5.addAll(listURLs(URLList4.get(i), 5));
    }

    if (maxdepth == 5) {
        return;
    }

    return;

}

From source file:com.laxser.blitz.web.portal.impl.DefaultPipeRender.java

public static JSONArray getAttributeAsArray(Window window, String key) {
    Object value = window.get(key);
    if (value == null) {
        return null;
    }/*from   w  w  w . j a  v a2 s  . com*/
    if (value instanceof Collection) {
        return new JSONArray(((Collection<?>) value));
    } else if (!(value instanceof Object[])) {
        ArrayList<Object> list = new ArrayList<Object>();
        list.add(value);
        return new JSONArray(list);
    }
    ArrayList<Object> list = new ArrayList<Object>();
    list.addAll(Arrays.asList((Object[]) value));
    return new JSONArray(list);
}

From source file:ReflectUtils.java

/**
 * Scans all classes accessible from the context class loader which belong to the given package and subpackages.
 *
 * @param packageName The base package//from ww  w .j  a va2 s .c om
 * @return The classes
 * @throws ClassNotFoundException
 * @throws IOException
 */
private static Class[] getClasses(String packageName) throws ClassNotFoundException, IOException {
    //        ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
    ClassLoader classLoader = ClassLoader.getSystemClassLoader();
    assert classLoader != null;
    String path = packageName.replace('.', '/');
    Enumeration<URL> resources = classLoader.getResources(path);
    List<File> dirs = new ArrayList<File>();
    while (resources.hasMoreElements()) {
        URL resource = resources.nextElement();
        dirs.add(new File(resource.getFile()));
    }
    ArrayList<Class> classes = new ArrayList<Class>();
    for (File directory : dirs) {
        classes.addAll(findClasses(directory, packageName));
    }
    return classes.toArray(new Class[classes.size()]);
}

From source file:de.awtools.basic.AWTools.java

/**
 * Erstellt ein ArrayList.//from  ww w.  j  ava2s  .c om
 *
 * @param <T> Typ der Liste.
 * @param values Werte der Liste.
 * @return Eine Liste.
 */
@SafeVarargs
public static <T> List<T> arrayList(final T... values) {
    ArrayList<T> list = new ArrayList<>();
    boolean addAll = list.addAll(Arrays.asList(values));
    if (!addAll) {
        throw new IllegalStateException("There is a failure here.");
    }
    return list;
}

From source file:com.feedzai.fos.server.remote.impl.RemoteInterfacesTest.java

/**
 * Scans all classes accessible from the context class loader which belong to the given package and subpackages.
 *
 * @param packageName The base package//w w w.  j ava  2 s  .c om
 * @return The classes
 * @throws ClassNotFoundException
 * @throws java.io.IOException
 */
private static Class[] getClasses(String packageName) throws ClassNotFoundException, IOException {
    ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
    assert classLoader != null;
    String path = packageName.replace('.', '/');
    Enumeration<URL> resources = classLoader.getResources(path);
    List<File> dirs = new ArrayList<>();
    while (resources.hasMoreElements()) {
        URL resource = resources.nextElement();
        dirs.add(new File(resource.getFile()));
    }
    ArrayList<Class> classes = new ArrayList<>();
    for (File directory : dirs) {
        classes.addAll(findClasses(directory, packageName));
    }
    return classes.toArray(new Class[classes.size()]);
}

From source file:coolmap.utils.statistics.test.CTest.java

public static void anova(CoolMapObject obj, Dimension direction, VNode... nodes) {
    try {//from w w  w . j  a v  a2  s  .  co  m
        ArrayList<VNode> leafNodes = new ArrayList<VNode>();
        if (direction == Dimension.ROW) {
            leafNodes.addAll(obj.getViewNodesRow());
        } else if (direction == Dimension.COLUMN) {
            leafNodes.addAll(obj.getViewNodesColumn());
        } else {
            return;
        }

        ArrayList<double[]> data = new ArrayList<double[]>();
        if (direction == Dimension.ROW) {
            for (VNode node : nodes) {
                data.add(extractRow(obj, node));
            }
        } else if (direction == Dimension.COLUMN) {
            for (VNode node : nodes) {
                data.add(extractColumn(obj, node));
            }
        }

        OneWayAnova anova = new OneWayAnova();
        double pValue = anova.anovaPValue(data);
        TestResult result = new TestResult("One-way ANOVA",
                "One way analysis of variance wiht alpha = 0.05. \nData: " + obj.getName() + "\nDirection: "
                        + direction + "\nGroups: " + Arrays.toString(nodes),
                pValue);
        CMConsole.log(result.toString());

    } catch (Exception e) {
        CMConsole.logError(
                "ANOVA error: " + " Dataset:" + obj + " Direction:" + direction + " Groups:" + nodes == null
                        ? null
                        : Arrays.toString(nodes));
    }
}

From source file:Main.java

public static ArrayList<View> getViewsByTag(ViewGroup root, String tag) {
    ArrayList<View> views = new ArrayList<View>();
    final int childCount = root.getChildCount();
    for (int i = 0; i < childCount; i++) {
        final View child = root.getChildAt(i);
        if (child instanceof ViewGroup) {
            views.addAll(getViewsByTag((ViewGroup) child, tag));
        }/*www  .  j a  v a  2s.  com*/

        final Object tagObj = child.getTag();
        if (tagObj != null && tagObj.equals(tag)) {
            views.add(child);
        }

    }
    return views;
}

From source file:coolmap.utils.statistics.test.CTest.java

public static void ttest(CoolMapObject obj, Dimension direction, VNode leafNode1, VNode leafNode2) {
    try {/*from  w  w  w  .  j  a v  a  2 s  .c o m*/
        ArrayList<VNode> leafNodes = new ArrayList<VNode>();
        if (direction == Dimension.ROW) {
            leafNodes.addAll(obj.getViewNodesRow());
        } else if (direction == Dimension.COLUMN) {
            leafNodes.addAll(obj.getViewNodesColumn());
        } else {
            return;
        }

        if (leafNodes.contains(leafNode1) && leafNodes.contains(leafNode2)) {

            double[] data1 = null;
            double[] data2 = null;

            if (direction == Dimension.ROW) {
                data1 = extractRow(obj, leafNode1);
                data2 = extractRow(obj, leafNode2);
            } else if (direction == Dimension.COLUMN) {
                data1 = extractColumn(obj, leafNode1);
                data2 = extractColumn(obj, leafNode2);
            }

            TTest test = new TTest();
            double pValue = test.pairedTTest(data1, data2);

            TestResult result = new TestResult("Student Paired T-Test",
                    "Two tailed paired t-test with alpha = 0.05.\nData: " + obj.getName() + "\nDirection: "
                            + direction + "\nGroups: " + leafNode1 + ", " + leafNode2,
                    pValue);
            CMConsole.log(result.toString());

        } else {
            CMConsole.logError(
                    "T-test error: group dimension mismatch, must both be row ontology group or column ontology groups.");
        }

    } catch (Exception e) {
        CMConsole.logError("T-test error: " + " Dataset:" + obj + " Direction:" + direction + " Group1:"
                + leafNode1 + " Group2:" + leafNode2);
    }
}

From source file:edu.lafayette.metadb.model.dataman.DataExporter.java

/**
 * Export data from a project for one item. 
 * @param projectName The project name./*from w  w  w. j av a2s.c o  m*/
 * @param itemNumber The item number to export.
 * @param delimiter The delimiter to use when writing the export (currently TSV/CSV)
 * @param encoder The character set encoding.
 * @param technical Flag indicating whether to include technical data in the export file.
 * @param replaceEntity Flag indicating whether to escape special characters with their HTML entity codes.
 * @return a String[] representing one row in the exported data file.
 */
public static String[] exportData(String projectName, int itemNumber, char delimiter, String encoder,
        boolean technical, boolean replaceEntity) {
    ArrayList adminDescData = null;
    Item it = ItemsDAO.getItem(projectName, itemNumber);
    adminDescData = it.getData(Global.MD_TYPE_DESC);
    adminDescData.addAll(it.getData(Global.MD_TYPE_ADMIN));

    ArrayList techData = new ArrayList();
    if (technical)
        techData = ItemsDAO.getTechData(projectName, itemNumber);

    String[] out = new String[adminDescData.size() + techData.size()];
    for (int i = 0; i < adminDescData.size(); i++) {
        try {
            String outStr = StringUtils.trimToEmpty(
                    new String(((AdminDescItem) adminDescData.get(i)).getData().getBytes("UTF-8"), encoder)
                            .replace('\t', ' '));
            out[i] = (replaceEntity ? StringEscapeUtils.escapeHtml(outStr)//outStr.replaceAll("&", "&#38;").replaceAll("[\"]", "&#34;").replaceAll("%", "&#37;").replaceAll("'", "&#39;").replaceAll(",", "&#44;")
                    : outStr);
        } catch (Exception e) {
            MetaDbHelper.logEvent(e);
            out[i] = ((AdminDescItem) adminDescData.get(i)).getData();
        }
    }
    //MetaDbHelper.note("Exporting tech data");
    for (int i = 0; i < techData.size(); i++)
        try {
            out[i + adminDescData.size()] = StringUtils
                    .trimToEmpty(new String(((Metadata) techData.get(i)).getData().getBytes("UTF-8"), encoder)
                            .replace('\t', ' '));
        } catch (Exception e) {
            MetaDbHelper.logEvent(e);
            out[i + adminDescData.size()] = ((Metadata) techData.get(i)).getData();
        }

    return out;
}