Example usage for java.util List addAll

List of usage examples for java.util List addAll

Introduction

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

Prototype

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 (optional operation).

Usage

From source file:Main.java

public static <E> void updateList(List<E> origList, Collection<? extends E> updateList, boolean add,
        boolean replace, boolean remove, BiPredicate<? super E, ? super E> comparer) {
    updateList(origList, updateList, add, replace, remove, comparer,
            (List<E> list, Collection<? extends E> itemsToAdd) -> origList.addAll(itemsToAdd));
}

From source file:org.jetbrains.webdemo.examples.ExamplesLoader.java

private static ExamplesFolder loadFolder(String path, String url, List<ObjectNode> parentCommonFiles,
        ExamplesFolder parentFolder) {/*w  w w  .  j av a2 s .co  m*/
    File manifestFile = new File(path + File.separator + "manifest.json");
    try (BufferedInputStream reader = new BufferedInputStream(new FileInputStream(manifestFile))) {
        ObjectNode manifest = (ObjectNode) JsonUtils.getObjectMapper().readTree(reader);
        String name = new File(path).getName();
        List<ObjectNode> commonFiles = new ArrayList<>();
        commonFiles.addAll(parentCommonFiles);
        boolean taskFolder = manifest.has("taskFolder") ? manifest.get("taskFolder").asBoolean() : false;

        List<LevelInfo> levels = null;
        if (manifest.has("levels")) {
            levels = new ArrayList<>();
            for (JsonNode level : manifest.get("levels")) {
                levels.add(new LevelInfo(level.get("projectsNeeded").asInt(), level.get("color").asText()));
            }
        }

        if (parentFolder != null && parentFolder.isTaskFolder())
            taskFolder = true;
        ExamplesFolder folder = new ExamplesFolder(name, url, taskFolder, levels);
        if (manifest.has("files")) {
            for (JsonNode node : manifest.get("files")) {
                ObjectNode fileManifest = (ObjectNode) node;
                fileManifest.put("path", path + File.separator + fileManifest.get("filename").asText());
                commonFiles.add(fileManifest);
            }
        }

        if (manifest.has("folders")) {
            for (JsonNode node : manifest.get("folders")) {
                String folderName = node.textValue();
                folder.addChildFolder(loadFolder(path + File.separator + folderName, url + folderName + "/",
                        commonFiles, folder));
            }
        }

        if (manifest.has("examples")) {
            for (JsonNode node : manifest.get("examples")) {
                String projectName = node.textValue();
                String projectPath = path + File.separator + projectName;
                folder.addExample(loadExample(projectPath, url,
                        ApplicationSettings.LOAD_TEST_VERSION_OF_EXAMPLES, commonFiles));
            }
        }

        return folder;
    } catch (IOException e) {
        System.err.println("Can't load folder: " + e.toString());
        return null;
    }
}

From source file:com.wavemaker.tools.apidocs.tools.parser.util.MethodUtils.java

/**
 * It will returns all Non static {@link Method}s of given {@link Class}.
 *
 * @param type {@link Class} to be scanned for methods.
 * @param predicates custom predicates to filter.
 * @return {@link Set} of filtered {@link Method}s.
 *//*from   ww w  .j  a va2 s . c o  m*/
public static Set<Method> getAllNonStaticMethods(Class<?> type, Predicate<? super Method>... predicates) {
    List<Predicate<? super Method>> predicateList = new LinkedList<>();

    predicateList.add(NonStaticMemberPredicate.getInstance());

    if (ArrayUtils.isNotEmpty(predicates)) {
        predicateList.addAll(Arrays.asList(predicates));
    }

    return getMethods(type, Predicates.and(predicateList));

}

From source file:com.activecq.api.utils.CookieUtil.java

/**
 * Remove the Cookies whose names match the provided Regex from Response
 *
 * @param request Request to get the Cookies to drop
 * @param response Response to expire the Cookies on
 * @param regexes Regex to find Cookies to drop
 * @return Number of Cookies dropped//w ww . j av  a 2  s .  co m
 */
public static int dropCookiesByRegexArray(HttpServletRequest request, HttpServletResponse response,
        String[] regexes) {
    int count = 0;
    if (regexes == null) {
        return count;
    }
    List<Cookie> cookies = new ArrayList<Cookie>();

    for (final String regex : regexes) {
        cookies.addAll(getCookies(request, regex));
        //cookies = CollectionUtils.union(cookies, getCookies(request, regex));
    }

    for (final Cookie cookie : cookies) {
        if (cookie == null) {
            continue;
        }

        cookie.setMaxAge(0);
        cookie.setPath(cookie.getPath());

        addCookie(cookie, response);
        count++;
    }

    return count;
}

From source file:com.adobe.acs.commons.util.CookieUtil.java

/**
 * Remove the Cookies whose names match the provided Regex from Response
 *
 * @param request  Request to get the Cookies to drop
 * @param response Response to expire the Cookies on
 * @param regexes  Regex to find Cookies to drop
 * @return Number of Cookies dropped//  www  . j  a  v a 2s .c  om
 */
public static int dropCookiesByRegexArray(final HttpServletRequest request, final HttpServletResponse response,
        final String cookiePath, final String[] regexes) {
    int count = 0;
    if (regexes == null) {
        return count;
    }
    final List<Cookie> cookies = new ArrayList<Cookie>();

    for (final String regex : regexes) {
        cookies.addAll(getCookies(request, regex));
    }

    return dropCookies(response, cookies.toArray(new Cookie[cookies.size()]), cookiePath);
}

From source file:com.googlecode.dex2jar.test.TestUtils.java

public static File dex(List<File> files, File distFile) throws Exception {
    String dxJar = "src/test/resources/dx.jar";
    File dxFile = new File(dxJar);
    if (!dxFile.exists()) {
        throw new RuntimeException("dx.jar?");
    }/*from   w w w  .j  a  v  a 2 s .  c  o m*/
    URLClassLoader cl = new URLClassLoader(new URL[] { dxFile.toURI().toURL() });
    Class<?> c = cl.loadClass("com.android.dx.command.Main");
    Method m = c.getMethod("main", String[].class);

    if (distFile == null) {
        distFile = File.createTempFile("dex", ".dex");
    }
    List<String> args = new ArrayList<String>();
    args.addAll(Arrays.asList("--dex", "--no-strict", "--output=" + distFile.getCanonicalPath()));
    for (File f : files) {
        args.add(f.getCanonicalPath());
    }
    m.invoke(null, new Object[] { args.toArray(new String[0]) });
    return distFile;
}

From source file:Main.java

/**
 * Gets a list of all views of a given type, rooted at the given parent.
 * <p>//from www  . ja  v  a  2s  .com
 * This method will recurse down through all {@link ViewGroup} instances looking for
 * {@link View} instances of the supplied class type. Specifically it will use the
 * {@link Class#isAssignableFrom(Class)} method as the test for which views to add to the list,
 * so if you provide {@code View.class} as your type, you will get every view. The parent itself
 * will be included also, should it be of the right type.
 * <p>
 * This call manipulates the ui, and as such should only be called from the application's main
 * thread.
 */
private static <T extends View> List<T> getAllViews(final Class<T> clazz, final View parent) {
    List<T> results = new ArrayList<T>();
    if (parent.getClass().equals(clazz)) {
        results.add(clazz.cast(parent));
    }
    if (parent instanceof ViewGroup) {
        ViewGroup viewGroup = (ViewGroup) parent;
        for (int i = 0; i < viewGroup.getChildCount(); ++i) {
            results.addAll(getAllViews(clazz, viewGroup.getChildAt(i)));
        }
    }
    return results;
}

From source file:ch.nydi.aop.interceptor.Interceptors.java

/**
 * Creates an interceptor that chains other interceptors.
 * //  w  w  w  .j  av  a  2s .co m
 * @param interceptors
 *            instances of {@link MethodInterceptor}.
 * @return interceptor that enclose other interceptors or Interceptors.EMPTY instance if interceptors argument is
 *         null or empty
 */
public static MethodInterceptor create(final MethodInterceptor... interceptors) {

    if (ArrayUtils.isEmpty(interceptors)) {
        return Interceptors.EMPTY;
    }

    final List<MethodInterceptor> flatlist = new ArrayList<>();
    for (final MethodInterceptor interceptor : interceptors) {
        assert (interceptor != null);

        if (interceptor instanceof Interceptors) {
            flatlist.addAll(Arrays.asList(((Interceptors) interceptor).interceptors));
        } else if (EMPTY != interceptor) {
            flatlist.add(interceptor);
        }
    }
    if (flatlist.isEmpty()) {
        return EMPTY;
    } else if (flatlist.size() == 1) {
        return flatlist.get(0);
    }
    return new Interceptors(flatlist.toArray(new MethodInterceptor[flatlist.size()]));
}

From source file:com.googlecode.jtiger.modules.ecside.util.ExtremeUtils.java

/**
 * Get a list of bean or map property names
 *///from  www.  j av a 2  s. c  o  m
public static List beanProperties(Object bean) throws Exception {
    List properties = new ArrayList();

    if (bean instanceof Map) {
        properties.addAll(((Map) bean).keySet());
    } else {
        properties.addAll(BeanUtils.describe(bean).keySet());
    }

    return properties;
}

From source file:org.opendatakit.tables.utils.WebViewUtil.java

/**
 * Retrieve a map of element key to value for each of the columns in the row
 * specified by rowId.//from  w  w w .ja  v  a  2  s.co m
 *
 * @param context
 * @param appName
 * @param tableId
 * @param orderedDefns
 * @param rowId
 * @return
 * @throws ServicesAvailabilityException
 */
public static Map<String, String> getMapOfElementKeyToValue(Context context, String appName, String tableId,
        OrderedColumns orderedDefns, String rowId) throws ServicesAvailabilityException {
    String[] adminColumns = null;
    UserTable userTable = null;

    {
        DbHandle db = null;
        try {
            db = Tables.getInstance().getDatabase().openDatabase(appName);

            adminColumns = Tables.getInstance().getDatabase().getAdminColumns();
            userTable = Tables.getInstance().getDatabase().getRowsWithId(appName, db, tableId, orderedDefns,
                    rowId);
        } finally {
            if (db != null) {
                Tables.getInstance().getDatabase().closeDatabase(appName, db);
            }
        }
    }
    if (userTable.getNumberOfRows() > 1) {
        WebLogger.getLogger(appName).e(TAG,
                "query returned > 1 rows for tableId: " + tableId + " and " + "rowId: " + rowId);
    } else if (userTable.getNumberOfRows() == 0) {
        WebLogger.getLogger(appName).e(TAG,
                "query returned no rows for tableId: " + tableId + " and rowId: " + rowId);
    }
    Map<String, String> elementKeyToValue = new HashMap<String, String>();
    Row requestedRow = userTable.getRowAtIndex(0);
    List<String> userDefinedElementKeys = orderedDefns.getRetentionColumnNames();
    List<String> adminElementKeys = Arrays.asList(adminColumns);
    List<String> allElementKeys = new ArrayList<String>();
    allElementKeys.addAll(userDefinedElementKeys);
    allElementKeys.addAll(adminElementKeys);
    for (String elementKey : allElementKeys) {
        elementKeyToValue.put(elementKey, requestedRow.getDataByKey(elementKey));
    }
    return elementKeyToValue;
}