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:com.inclouds.hbase.utils.TableLocality.java

private static Map<String, List<Path>> optimizeLocality(Map<String, List<Path>> serverMap)
        throws FileNotFoundException, IOException {
    LOG.info("Optimize locality starts");
    Set<String> servers = serverMap.keySet();
    Collection<List<Path>> regions = serverMap.values();
    ArrayList<Path> allRegions = new ArrayList<Path>();
    for (List<Path> rr : regions) {
        allRegions.addAll(rr);
    }//ww  w.j a  v a  2  s.c o  m

    // For all regions find server with max locality index
    int max = 0;
    Map<String, List<Path>> opt = new HashMap<String, List<Path>>();
    for (Path r : allRegions) {

        max = 0;
        String h = null;
        List<BlockLocation> blocks = getAllBlockLocations(r);
        for (String host : servers) {
            int locality = localityForServerBlocks(host, blocks);
            if (locality > max) {
                max = locality;
                h = host;
            }

        }

        LOG.info(r + " s=" + h + " locality=" + max);

        List<Path> pp = opt.get(h);
        if (pp == null) {
            pp = new ArrayList<Path>();
            opt.put(h, pp);
        }
        pp.add(r);
    }

    for (String s : opt.keySet()) {
        LOG.info(s + " r=" + opt.get(s).size() + " locality=" + localityForServer(s, opt.get(s)));

    }

    return opt;
}

From source file:com.galenframework.speclang2.pagespec.ForLoop.java

private static Object[] readSequenceForSimpleLoop(String sequenceStatement, Place place) {
    sequenceStatement = sequenceStatement.replace(" ", "");
    sequenceStatement = sequenceStatement.replace("\t", "");
    Pattern sequencePattern = Pattern.compile(".*\\-.*");
    try {//from  www .j av a2s .  c o  m
        String[] values = sequenceStatement.split(",");

        ArrayList<Object> sequence = new ArrayList<>();

        for (String stringValue : values) {
            if (sequencePattern.matcher(stringValue).matches()) {
                sequence.addAll(createSequence(stringValue));
            } else {
                sequence.add(convertValueToIndex(stringValue));
            }
        }

        return sequence.toArray(new Object[sequence.size()]);
    } catch (Exception ex) {
        throw new SyntaxException(place, "Incorrect sequence syntax: " + sequenceStatement, ex);
    }
}

From source file:com.galenframework.speclang2.reader.pagespec.ForLoop.java

private static Object[] readSequenceForSimpleLoop(String sequenceStatement) {
    sequenceStatement = sequenceStatement.replace(" ", "");
    sequenceStatement = sequenceStatement.replace("\t", "");
    Pattern sequencePattern = Pattern.compile(".*\\-.*");
    try {//from ww  w.j  a  va  2  s. c  o  m
        String[] values = sequenceStatement.split(",");

        ArrayList<Object> sequence = new ArrayList<>();

        for (String stringValue : values) {
            if (sequencePattern.matcher(stringValue).matches()) {
                sequence.addAll(createSequence(stringValue));
            } else {
                sequence.add(convertValueToIndex(stringValue));
            }
        }

        return sequence.toArray(new Object[] {});
    } catch (Exception ex) {
        throw new SyntaxException(UNKNOWN_LINE, "Incorrect sequence syntax: " + sequenceStatement, ex);
    }
}

From source file:com.termmed.utils.ResourceUtils.java

/**
 * Gets the resources from directory./*ww w .  jav a 2 s  . co m*/
 *
 * @param directory the directory
 * @param pattern the pattern
 * @return the resources from directory
 */
private static Collection<String> getResourcesFromDirectory(final File directory, final Pattern pattern) {
    final ArrayList<String> retval = new ArrayList<String>();
    final File[] fileList = directory.listFiles();
    for (final File file : fileList) {
        if (file.isDirectory()) {
            retval.addAll(getResourcesFromDirectory(file, pattern));
        } else {
            try {
                final String fileName = file.getCanonicalPath();
                final boolean accept = pattern.matcher(fileName).matches();
                if (accept) {
                    retval.add(fileName);
                }
            } catch (final IOException e) {
                throw new Error(e);
            }
        }
    }
    return retval;
}

From source file:net.pms.util.ProcessUtil.java

public static void reboot(ArrayList<String> cmd, Map<String, String> env, String startdir,
        String... UMSOptions) {/*  w ww  . j  av a2 s  .co  m*/
    final ArrayList<String> reboot = getUMSCommand();
    if (UMSOptions.length > 0) {
        reboot.addAll(Arrays.asList(UMSOptions));
    }
    if (cmd == null) {
        // We're doing a straight reboot
        cmd = reboot;
    } else {
        // We're running a script that will eventually restart UMS
        if (env == null) {
            env = new HashMap<>();
        }
        // Tell the script how to restart UMS
        env.put("RESTART_CMD", StringUtils.join(reboot, " "));
        env.put("RESTART_DIR", System.getProperty("user.dir"));
    }
    if (startdir == null) {
        startdir = System.getProperty("user.dir");
    }

    System.out.println("starting: " + StringUtils.join(cmd, " "));

    final ProcessBuilder pb = new ProcessBuilder(cmd);
    if (env != null) {
        pb.environment().putAll(env);
    }
    pb.directory(new File(startdir));
    System.out.println("in directory: " + pb.directory());
    try {
        pb.start();
    } catch (Exception e) {
        e.printStackTrace();
        return;
    }
    System.exit(0);
}

From source file:com.dtolabs.rundeck.core.cli.CLIUtils.java

/**
 * Create an appropriately quoted argline to use given the command (script path) and argument strings.
 *
 * @param scriptpath path to command or script
 * @param args       arguments to pass to the command
 * @param separator  character to use to separate arguments
 * @param unsafe     whether to use backwards-compatible, known-insecure quoting
 *
 * @return a String of the command followed by the arguments, where each item which has spaces is appropriately
 *         quoted.  Pre-quoted items are not changed during "unsafe" quoting.
 *///from  w ww  . ja  v  a2 s. c  o  m
public static String generateArgline(final String scriptpath, final String[] args, final String separator,
        final Boolean unsafe) {
    final StringBuilder sb = new StringBuilder();
    final ArrayList<String> list = new ArrayList<String>();
    if (null != scriptpath) {
        list.add(scriptpath);
    }
    if (null != args) {
        list.addAll(Arrays.asList(args));
    }
    for (final String arg : list) {
        if (null == arg) {
            continue;
        }
        if (sb.length() > 0) {
            sb.append(separator);
        }
        if (unsafe) {
            /* DEPRECATED SECURITY RISK: Exists for backwards compatibility only. */
            if (arg.indexOf(" ") >= 0
                    && !(0 == arg.indexOf("'") && (arg.length() - 1) == arg.lastIndexOf("'"))) {
                sb.append("'").append(arg).append("'");
            } else {
                sb.append(arg);
            }
        } else {
            quoteUnixShellArg(sb, arg);
        }
    }
    return sb.toString();
}

From source file:com.validation.manager.core.tool.Tool.java

public static List<Requirement> extractRequirements(RequirementSpec rs) {
    ArrayList<Requirement> result = new ArrayList<>();
    rs.getRequirementSpecNodeList().forEach(rsn -> {
        result.addAll(extractRequirements(rsn));
    });// w  ww .  ja  va2 s  . c o  m
    return result;
}

From source file:de.netallied.functionblock.converter.java2java.util.Directory.java

/**
 * /*w  w w  .j  a v a  2 s .  com*/
 * @param folder
 * @param recursive
 * @return ArrayList[File]
 */
public static ArrayList getAll(File folder, boolean recursive) {
    ArrayList list = new ArrayList();
    File[] files = folder.listFiles();
    // directory doesn't exists -> return empty set
    if (files == null)
        return list;
    //    String inhalt= FileUtils.readFileToString(file,"ISO-8859-1");
    for (int i = 0; i < files.length; i++) {
        if (files[i].isDirectory()) {
            if (recursive) {
                list.addAll(getAll(files[i], recursive));
            }
        } else {
            list.add(files[i]);
        }
    }
    return list;
}

From source file:com.validation.manager.core.tool.Tool.java

public static List<Requirement> extractRequirements(RequirementSpecNode rsn) {
    ArrayList<Requirement> result = new ArrayList<>();
    rsn.getRequirementSpecNodeList().forEach(rsn2 -> {
        result.addAll(extractRequirements(rsn2));
    });// ww  w .  j a va  2 s .c o m
    result.addAll(rsn.getRequirementList());
    return result;
}

From source file:org.soyatec.windowsazure.internal.MessageCanonicalizer2.java

/**
 * Create the canonicalized resource with the url address and resourceUriComponents.
 * @param address/*from   w w w . j a v  a 2  s .  com*/
 *          The uri address of the HTTP request.
 * @param uriComponents
 *          Components of the Uri extracted out of the request.
 * @return canonicalized resource
 */
private static String getCanonicalizedResource(URI address, ResourceUriComponents uriComponents) {
    //      Beginning with an empty string (""), append a forward slash (/), followed by the name of the account that owns the resource being accessed.
    //      Append the resource's encoded URI path, without any query parameters.
    //      Retrieve all query parameters on the resource URI, including the comp parameter if it exists.
    //      Convert all parameter names to lowercase.
    //      Sort the query parameters lexicographically by parameter name, in ascending order.
    //      URL-decode each query parameter name and value.
    //      Append each query parameter name and value to the string in the following format, making sure to include the colon (:) between the name and the value:
    //      parameter-name:parameter-value
    //      If a query parameter has more than one value, sort all values lexicographically, then include them in a comma-separated list:
    //      parameter-name:parameter-value-1,parameter-value-2,parameter-value-n
    //      Append a new line character (\n) after each name-value pair. 

    //      Get Container Metadata
    //         GET http://myaccount.blob.core.windows.net/mycontainer?restype=container&comp=metadata 
    //      CanonicalizedResource:
    //          /myaccount/mycontainer\ncomp:metadata\nrestype:container
    //
    //      List Blobs operation:
    //          GET http://myaccount.blob.core.windows.net/container?restype=container&comp=list&include=snapshots&include=metadata&include=uncommittedblobs
    //      CanonicalizedResource:
    //          /myaccount/mycontainer\ncomp:list\ninclude:metadata,snapshots,uncommittedblobs\nrestype:container

    StringBuilder canonicalizedResource = new StringBuilder(ConstChars.Slash);
    canonicalizedResource.append(uriComponents.getAccountName());

    // Note that AbsolutePath starts with a '/'.

    String path = address.getRawPath();
    //      path = path.replaceAll(" ", "%20");
    //      path = java.net.URLEncoder.encode(path);
    canonicalizedResource.append(path);

    NameValueCollection query = HttpUtilities.parseQueryString(address.getQuery());

    ArrayList<String> paramNames = new ArrayList<String>();
    paramNames.addAll(query.keySet());
    Collections.sort(paramNames, new Comparator<String>() {
        public int compare(String o1, String o2) {
            return o1.compareToIgnoreCase(o2);
        }
    });

    for (String key : paramNames) {
        StringBuilder canonicalizedElement = new StringBuilder(URLDecoder.decode(key));
        canonicalizedElement.append(ConstChars.Colon);
        String value = query.getMultipleValuesAsString(key);
        canonicalizedElement.append(URLDecoder.decode(value));

        canonicalizedResource.append(ConstChars.Linefeed);
        canonicalizedResource.append(canonicalizedElement.toString());
    }

    return canonicalizedResource.toString();
}