Example usage for java.util ArrayList toArray

List of usage examples for java.util ArrayList toArray

Introduction

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

Prototype

@SuppressWarnings("unchecked")
public <T> T[] toArray(T[] a) 

Source Link

Document

Returns an array containing all of the elements in this list in proper sequence (from first to last element); the runtime type of the returned array is that of the specified array.

Usage

From source file:com.github.ljtfreitas.restify.http.spring.contract.metadata.reflection.SpringWebRequestMappingMetadata.java

public String[] headers() {
    ArrayList<String> headers = new ArrayList<>();

    Collections.addAll(headers, mappedHeaders());

    consumes().ifPresent(c -> headers.add(c));
    produces().ifPresent(p -> headers.add(p));

    return headers.toArray(new String[0]);
}

From source file:com.taobao.diamond.server.interceptor.SelectedAnnotationHandlerMapping.java

public String[] getFiltered(String as[]) {
    if (as == null)
        return null;
    ArrayList arraylist = new ArrayList();
    String as1[] = as;//from  w w w  .  j  ava  2  s. c  om
    int i = as1.length;
    for (int j = 0; j < i; j++) {
        String s = as1[j];
        if (a.contains(s))
            arraylist.add(s);
    }

    return (String[]) arraylist.toArray(new String[arraylist.size()]);
}

From source file:com.taobao.diamond.server.interceptor.IgnoreSelectedAnnotationHandlerMapping.java

public String[] getFiltered(String as[]) {
    if (as == null)
        return null;
    ArrayList arraylist = new ArrayList();
    String as1[] = as;/*from w w  w.  j  a v  a  2s.  com*/
    int i = as1.length;
    for (int j = 0; j < i; j++) {
        String s = as1[j];
        if (!a.contains(s))
            arraylist.add(s);
    }

    return (String[]) arraylist.toArray(new String[arraylist.size()]);
}

From source file:canreg.client.analysis.Tools.java

public static LinkedList<String> callR(String rScript, String rpath, String reportFileName)
        throws TableErrorException {
    LinkedList<String> filesCreated = new LinkedList<String>();
    Runtime rt = Runtime.getRuntime();
    ArrayList<String> commandList = new ArrayList<String>();
    commandList.add(rpath);/*from  w w w  . j  av  a  2 s. c  o m*/
    commandList.add("CMD");
    commandList.add("BATCH");
    commandList.add("--vanilla");
    commandList.add("--slave");
    commandList.add(rScript);
    commandList.add(reportFileName);

    //String command = canreg.common.Tools.encapsulateIfNeeded(rpath)
    //        + " CMD BATCH --vanilla --slave "
    //        + canreg.common.Tools.encapsulateIfNeeded(rScript) + " "
    //        + canreg.common.Tools.encapsulateIfNeeded(reportFileName);
    System.out.println(commandList);
    Process pr = null;
    try {
        pr = rt.exec(commandList.toArray(new String[] {}));
        // collect the output from the R program in a stream
        // BufferedInputStream is = new BufferedInputStream(pr.getInputStream());
        pr.waitFor();
        BufferedInputStream is = new BufferedInputStream(new FileInputStream(reportFileName));
        // convert the output to a string
        String theString = convertStreamToString(is);
        Logger.getLogger(RTableBuilderGrouped.class.getName()).log(Level.INFO, "Messages from R: \n{0}",
                theString);
        // System.out.println(theString);
        // and add all to the list of files to return
        for (String fileName : theString.split("\n")) {
            if (fileName.startsWith("-outFile:")) {
                fileName = fileName.replaceFirst("-outFile:", "");
                if (new File(fileName).exists()) {
                    filesCreated.add(fileName);
                }
            }
        }
    } catch (InterruptedException ex) {
        Logger.getLogger(RTableBuilder.class.getName()).log(Level.SEVERE, null, ex);
    } catch (java.util.NoSuchElementException ex) {
        Logger.getLogger(RTableBuilder.class.getName()).log(Level.SEVERE, null, ex);
        if (pr != null) {
            BufferedInputStream errorStream = new BufferedInputStream(pr.getErrorStream());
            String errorMessage = convertStreamToString(errorStream);
            System.out.println(errorMessage);
            throw new TableErrorException("R says:\n \"" + errorMessage + "\"");
        }
    } catch (IOException ex) {
        Logger.getLogger(Tools.class.getName()).log(Level.SEVERE, null, ex);
    } finally {
        if (pr != null) {
            System.out.println(pr.exitValue());
        }
    }
    return filesCreated;
}

From source file:com.cloudera.sqoop.manager.DirectPostgreSQLExportManualTest.java

@Override
protected String[] getCodeGenArgv(String... extraArgs) {
    ArrayList<String> args = new ArrayList<String>(Arrays.asList(extraArgs));
    args.add("--username");
    args.add(getUserName());/*w w  w  .ja  va  2s  . c om*/
    return super.getCodeGenArgv(args.toArray(new String[0]));
}

From source file:net.opentsdb.tree.TreeRule.java

/**
 * Attempts to delete all rules belonging to the given tree.
 * @param tsdb The TSDB to use for storage access
 * @param tree_id ID of the tree the rules belongs to
 * @return A deferred to wait on for completion. The value has no meaning and
 * may be null.//from w  w  w.j ava 2  s  . co m
 * @throws HBaseException if there was an issue
 * @throws IllegalArgumentException if the one of the required parameters was
 * missing
 */
public static Deferred<Object> deleteAllRules(final TSDB tsdb, final int tree_id) {
    if (tree_id < 1 || tree_id > 65535) {
        throw new IllegalArgumentException("Invalid Tree ID");
    }

    // fetch the whole row
    final GetRequest get = new GetRequest(tsdb.treeTable(), Tree.idToBytes(tree_id));
    get.family(Tree.TREE_FAMILY());

    /**
     * Called after fetching the requested row. If the row is empty, we just
     * return, otherwise we compile a list of qualifiers to delete and submit
     * a single delete request to storage.
     */
    final class GetCB implements Callback<Deferred<Object>, ArrayList<KeyValue>> {

        @Override
        public Deferred<Object> call(final ArrayList<KeyValue> row) throws Exception {
            if (row == null || row.isEmpty()) {
                return Deferred.fromResult(null);
            }

            final ArrayList<byte[]> qualifiers = new ArrayList<byte[]>(row.size());

            for (KeyValue column : row) {
                if (column.qualifier().length > RULE_PREFIX.length
                        && Bytes.memcmp(RULE_PREFIX, column.qualifier(), 0, RULE_PREFIX.length) == 0) {
                    qualifiers.add(column.qualifier());
                }
            }

            final DeleteRequest delete = new DeleteRequest(tsdb.treeTable(), Tree.idToBytes(tree_id),
                    Tree.TREE_FAMILY(), qualifiers.toArray(new byte[qualifiers.size()][]));
            return tsdb.getClient().delete(delete);
        }

    }

    return tsdb.getClient().get(get).addCallbackDeferring(new GetCB());
}

From source file:com.github.chenxiaolong.dualbootpatcher.switcher.InAppFlashingFragment.java

@Nullable
private static String[] getDirectories(Context context, Uri uri) {
    final ArrayList<String> filenames = new ArrayList<>();
    DocumentFile directory = FileUtils.getDocumentFile(context, uri);
    DocumentFile[] files = directory.listFiles();

    if (files == null) {
        return null;
    }/*from  w w  w . ja va  2s .co m*/

    for (DocumentFile file : files) {
        if (file.isDirectory()) {
            filenames.add(file.getName());
        }
    }

    Collections.sort(filenames);

    return filenames.toArray(new String[filenames.size()]);
}

From source file:io.github.agentsoz.abmjadex.super_central.ABMSimStarter.java

private static String[] packageOptionSpecific(String[] oldOption) {
    String[] specificOption = null;
    ArrayList<String> specificOptionList = new ArrayList<String>();

    for (int i = 0; i < oldOption.length; i++) {
        if (oldOption[i].equals("-" + LOG_CONSOLE) || oldOption[i].equals("-" + HELP)
                || oldOption[i].equals("--" + HELP_LONG) || oldOption[i].equals("-" + FORCED)
                || oldOption[i].equals("--" + FORCED_LONG)) {
            specificOptionList.add(oldOption[i]);
        } else if (oldOption[i].equals("-" + GUI) || oldOption[i].equals("-" + LOG_LVL)
                || oldOption[i].equals("-" + GUI) || oldOption[i].equals("-" + MODE)
                || oldOption[i].equals("-" + PROP) || oldOption[i].equals("--" + PROP_LONG)) {
            specificOptionList.add(oldOption[i]);
            i++;/*from  ww  w .j  a v a2  s.  c  o  m*/
            specificOptionList.add(oldOption[i]);
        }
    }
    specificOption = new String[specificOptionList.size()];
    specificOptionList.toArray(specificOption);
    return specificOption;
}

From source file:com.github.ljtfreitas.restify.http.spring.contract.metadata.reflection.SpringWebJavaTypeMetadata.java

public String[] paths() {
    ArrayList<String> paths = new ArrayList<>();

    Optional.ofNullable(parent).map(p -> p.paths()).ifPresent(array -> Collections.addAll(paths, array));

    mapping.flatMap(m -> m.path()).ifPresent(p -> paths.add(p));

    return paths.toArray(new String[0]);
}

From source file:CommandLineSupport.java

/**
 * Sets the properties of an object given the command line args.
 * /*from   w w w  . j a  v  a2 s  .c o  m*/
 * if args contains: --ack-mode=AUTO --url=tcp://localhost:61616 --persistent 
 * 
 * then it will try to call the following setters on the target object.
 * 
 * target.setAckMode("AUTO");
 * target.setURL(new URI("tcp://localhost:61616") );
 * target.setPersistent(true);
 * 
 * Notice the the proper conversion for the argument is determined by examining the 
 * setter arguement type.  
 * 
 * @param target the object that will have it's properties set
 * @param args the commline options
 * @return any arguments that are not valid options for the target
 */
public static String[] setOptions(Object target, String[] args) {
    ArrayList<String> rc = new ArrayList<String>();

    for (int i = 0; i < args.length; i++) {
        if (args[i] == null) {
            continue;
        }

        if (args[i].startsWith("--")) {

            // --options without a specified value are considered boolean
            // flags that are enabled.
            String value = "true";
            String name = args[i].substring(2);

            // if --option=value case
            int p = name.indexOf("=");
            if (p > 0) {
                value = name.substring(p + 1);
                name = name.substring(0, p);
            }

            // name not set, then it's an unrecognized option
            if (name.length() == 0) {
                rc.add(args[i]);
                continue;
            }

            String propName = convertOptionToPropertyName(name);
            if (!IntrospectionSupport.setProperty(target, propName, value)) {
                rc.add(args[i]);
                continue;
            }
        }

    }

    String r[] = new String[rc.size()];
    rc.toArray(r);
    return r;
}