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:edu.isistan.carcha.util.PluginUtil.java

/**
 * Removes the duplicates./*from   w  w  w  . j a va  2  s  .c  o  m*/
 *
 * @param concerns the concerns
 */
public static void removeDuplicates(List<Entity> concerns) {
    ArrayList<Entity> ret = new ArrayList<Entity>();
    HashSet<Entity> hash = new HashSet<Entity>();
    hash.addAll(concerns);
    ret.clear();
    ret.addAll(hash);
}

From source file:Main.java

private static String generateSignature(String base, String type, String nonce, String timestamp, String token,
        String tokenSecret, String verifier, ArrayList<String> parameters)
        throws NoSuchAlgorithmException, InvalidKeyException {
    String encodedBase = Uri.encode(base);

    StringBuilder builder = new StringBuilder();

    //Create an array of all the parameters
    //So that we can sort them
    //OAuth requires that we sort all parameters
    ArrayList<String> sortingArray = new ArrayList<String>();

    sortingArray.add("oauth_consumer_key=" + oauthConsumerKey);
    sortingArray.add("oauth_nonce=" + nonce);
    sortingArray.add("oauth_signature_method=HMAC-SHA1");
    sortingArray.add("oauth_timestamp=" + timestamp);
    sortingArray.add("oauth_version=1.0");

    if (parameters != null) {
        sortingArray.addAll(parameters);
    }//ww  w  .  j a  v  a 2  s  . c om

    if (token != "" && token != null) {
        sortingArray.add("oauth_token=" + token);
    }
    if (verifier != "" && verifier != null) {
        sortingArray.add("oauth_verifier=" + verifier);
    }

    Collections.sort(sortingArray);

    //Append all parameters to the builder in the right order
    for (int i = 0; i < sortingArray.size(); i++) {
        if (i > 0)
            builder.append("&" + sortingArray.get(i));
        else
            builder.append(sortingArray.get(i));

    }

    String params = builder.toString();
    //Percent encoded the whole url
    String encodedParams = Uri.encode(params);

    String completeUrl = type + "&" + encodedBase + "&" + encodedParams;

    String completeSecret = oauthSecretKey;

    if (tokenSecret != null && tokenSecret != "") {
        completeSecret = completeSecret + "&" + tokenSecret;
    } else {
        completeSecret = completeSecret + "&";
    }

    Log.v("Complete URL: ", completeUrl);
    Log.v("Complete Key: ", completeSecret);

    Mac mac = Mac.getInstance("HmacSHA1");
    SecretKeySpec secret = new SecretKeySpec(completeSecret.getBytes(), mac.getAlgorithm());
    mac.init(secret);
    byte[] sig = mac.doFinal(completeUrl.getBytes());

    String signature = Base64.encodeToString(sig, 0);
    signature = signature.replace("+", "%2b"); //Specifically encode all +s to %2b

    return signature;
}

From source file:fredboat.FredBoat.java

public static List<Guild> getAllGuilds() {
    ArrayList<Guild> list = new ArrayList<>();

    for (FredBoat fb : shards) {
        list.addAll(fb.getJda().getGuilds());
    }/*ww  w  .  j ava 2s .  co  m*/

    return list;
}

From source file:Main.java

private static List<Object> recursiveAggregateTree(List<Object> items, int maxPerList) {
    if (items.size() > maxPerList) {
        ArrayList<Object> aggregateList = new ArrayList<Object>(maxPerList);
        ArrayList<Object> childList = null;

        for (Object item : items) {
            if (childList == null || childList.size() == maxPerList) {
                childList = new ArrayList<Object>(maxPerList);
                aggregateList.add(childList);
            }/*from w w  w . j  a  v  a2s .c om*/
            childList.add(item);
        }
        childList.trimToSize();

        aggregateList.addAll(recursiveAggregateTree(aggregateList, maxPerList));

        aggregateList.trimToSize();

        return aggregateList;
    } else {
        // This is a safe blind cast since only subsequent calls of this method will end up here
        // and this method always uses ArrayList<Object>
        return items;
    }
}

From source file:com.fanfou.app.opensource.api.ApiParser.java

public static <T> ContentValues[] toContentValuesArray(final Set<? extends Storable<T>> t) {
    if ((t == null) || (t.size() == 0)) {
        return null;
    }/* w  w w .  ja v  a 2s.  com*/

    final ArrayList<Storable<T>> s = new ArrayList<Storable<T>>();
    s.addAll(t);
    return ApiParser.toContentValuesArray(s);

    // ArrayList<ContentValues> values=new ArrayList<ContentValues>();
    // Iterator<? extends Storable<T>> i=t.iterator();
    // while (i.hasNext()) {
    // Storable<T> st=i.next();
    // values.add(st.toContentValues());
    // }
    // return (ContentValues[]) values.toArray(new
    // ContentValues[values.size()]);

}

From source file:com.clustercontrol.custom.factory.SelectCustom.java

public static void refreshCache() {
    m_log.info("refresh cache");

    long startTime = HinemosTime.currentTimeMillis();
    try {// ww w. j a  v  a  2  s . c o m
        _lock.writeLock();

        new JpaTransactionManager().getEntityManager().clear();
        ArrayList<MonitorInfo> customCache = new SelectCustom()
                .getMonitorListObjectPrivilegeModeNONE(HinemosModuleConstant.MONITOR_CUSTOM_N);
        customCache.addAll(new SelectCustom()
                .getMonitorListObjectPrivilegeModeNONE(HinemosModuleConstant.MONITOR_CUSTOM_S));
        storeCache(customCache);
        m_log.info("refresh customCache " + (HinemosTime.currentTimeMillis() - startTime) + "ms. size="
                + customCache.size());
    } catch (Exception e) {
        m_log.warn("failed refreshing cache.", e);
    } finally {
        _lock.writeUnlock();
    }
}

From source file:Main.java

/**
 * Gets all of the values in a sequence set per RFC 3501.
 *
 * <p>// w  ww. j  av  a  2 s. c  om
 * Any ranges are expanded into a list of individual numbers.
 * </p>
 *
 * <pre>
 * sequence-number = nz-number / "*"
 * sequence-range  = sequence-number ":" sequence-number
 * sequence-set    = (sequence-number / sequence-range) *("," sequence-set)
 * </pre>
 *
 * @param set
 *         The sequence set string as received by the server.
 *
 * @return The list of IDs as strings in this sequence set. If the set is invalid, an empty
 *         list is returned.
 */
public static List<String> getImapSequenceValues(String set) {
    ArrayList<String> list = new ArrayList<String>();
    if (set != null) {
        String[] setItems = set.split(",");
        for (String item : setItems) {
            if (item.indexOf(':') == -1) {
                // simple item
                if (isNumberValid(item)) {
                    list.add(item);
                }
            } else {
                // range
                list.addAll(getImapRangeValues(item));
            }
        }
    }

    return list;
}

From source file:Main.java

/**
 * List all child nodes with name sName/*www.j a v a2 s .c  om*/
 * NOTE: we assume no same name nodes are nested.
 * @param node
 * @param sName
 * @return Element
 */
public static ArrayList<Element> listChildElementsByName(Node node, String sName) {
    ArrayList<Element> aNodes = new ArrayList<Element>();
    NodeList nl = node.getChildNodes();
    for (int i = 0; i < nl.getLength(); i++) {
        Node n = nl.item(i);
        if (n.getNodeType() == Node.ELEMENT_NODE) {
            if (sName.equals(n.getNodeName())) {
                aNodes.add((Element) n);
            } else {
                ArrayList<Element> nextNodes = listChildElementsByName(n, sName);
                if (nextNodes != null)
                    aNodes.addAll(nextNodes);
            }
        }
        // Don't search anything but elements
    }
    return aNodes;
}

From source file:Main.java

private static List<Object> recursiveAggregateTree(List<Object> items, int maxPerList) {
    if (items.size() > maxPerList) {
        ArrayList<Object> aggregateList = new ArrayList<Object>(maxPerList);
        ArrayList<Object> childList = null;

        for (Object item : items) {
            if (childList == null || childList.size() == maxPerList) {
                childList = new ArrayList<Object>(maxPerList);
                aggregateList.add(childList);
            }//from w  w  w  . j  a va2s.c  o m
            childList.add(item);
        }
        if (childList != null) {
            childList.trimToSize();
        }

        aggregateList.addAll(recursiveAggregateTree(aggregateList, maxPerList));

        aggregateList.trimToSize();

        return aggregateList;
    } else {
        // This is a safe blind cast since only subsequent calls of this method will end up here
        // and this method always uses ArrayList<Object>
        return items;
    }
}

From source file:azkaban.reportal.util.ReportalHelper.java

/**
 * Updates the email notifications saved in the project's flow.
 * @param project// w w w  .ja v  a  2 s  .  c  om
 * @param pm
 * @throws ProjectManagerException
 */
public static void updateProjectNotifications(Project project, ProjectManager pm)
        throws ProjectManagerException {
    Flow flow = project.getFlows().get(0);

    // Get all success emails.
    ArrayList<String> successEmails = new ArrayList<String>();
    String successNotifications = (String) project.getMetadata().get("notifications");
    String[] successEmailSplit = successNotifications.split("\\s*,\\s*|\\s*;\\s*|\\s+");
    successEmails.addAll(Arrays.asList(successEmailSplit));

    // Get all failure emails.
    ArrayList<String> failureEmails = new ArrayList<String>();
    String failureNotifications = (String) project.getMetadata().get("failureNotifications");
    String[] failureEmailSplit = failureNotifications.split("\\s*,\\s*|\\s*;\\s*|\\s+");
    failureEmails.addAll(Arrays.asList(failureEmailSplit));

    // Add subscription emails to success emails list.
    @SuppressWarnings("unchecked")
    Map<String, String> subscription = (Map<String, String>) project.getMetadata().get("subscription");
    if (subscription != null) {
        successEmails.addAll(subscription.values());
    }

    ArrayList<String> successEmailList = new ArrayList<String>();
    for (String email : successEmails) {
        if (!email.trim().isEmpty()) {
            successEmailList.add(email);
        }
    }

    ArrayList<String> failureEmailList = new ArrayList<String>();
    for (String email : failureEmails) {
        if (!email.trim().isEmpty()) {
            failureEmailList.add(email);
        }
    }

    // Save notifications in the flow.
    flow.getSuccessEmails().clear();
    flow.getFailureEmails().clear();
    flow.addSuccessEmails(successEmailList);
    flow.addFailureEmails(failureEmailList);
    pm.updateFlow(project, flow);
}