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

public Object[] toArray() 

Source Link

Document

Returns an array containing all of the elements in this list in proper sequence (from first to last element).

Usage

From source file:edu.duke.cabig.c3pr.utils.StringUtils.java

public static String[] convertArrayListToStringArray(ArrayList al) {
    Object obj[] = (Object[]) al.toArray();
    String[] ar;/*from   ww w .jav a 2  s  .  c  o  m*/
    if (obj.length > 0) {
        ar = new String[obj.length];
        for (int j = 0; j < obj.length; j++) {
            ar[j] = obj[j].toString();
        }
    } else {
        ar = null;
    }
    return ar;
}

From source file:com.google.acre.script.JSFile.java

public static Scriptable jsStaticFunction_files(Context cx, Scriptable thisObj, Object[] args,
        Function funObj) {//from   w  w  w.j  av a2 s.  c  om
    String[] files;
    Scriptable scope = ScriptableObject.getTopLevelScope(funObj);

    class ArgLadenFilenameFilter implements FilenameFilter {
        private Object _matcher;
        private Scriptable _scope;
        private Scriptable _this;
        private Context _cx;

        public ArgLadenFilenameFilter(Context cx, Scriptable scope, Scriptable thisObj, Object matcher) {
            _cx = cx;
            _scope = scope;
            _this = thisObj;
            _matcher = matcher;
        }

        public boolean accept(File dir, String fn) {
            if (_matcher instanceof Function) {
                Object[] fnargs = new Object[] { fn };
                return (Boolean) ((Function) _matcher).call(_cx, _scope, _this, fnargs);
            } else if (_matcher instanceof String) {
                return fn.matches((String) _matcher);
            } else {
                return false;
            }
        }
    }

    // This is our own copy of the CostCollector.
    CostCollector __costCollector = CostCollector.getInstance();
    __costCollector.collect("aidc");
    final long start_time = System.currentTimeMillis();

    if (args.length == 1) {
        File dir = new File((String) args[0]);
        files = dir.list();
    } else if (args.length == 2) {
        File dir = new File((String) args[0]);
        FilenameFilter fnfilter = new ArgLadenFilenameFilter(cx, scope, thisObj, args[1]);
        files = dir.list(fnfilter);
    } else {
        return null;
    }
    __costCollector.collect("aidw", System.currentTimeMillis() - start_time);

    if (files == null) {
        return null;
    } else {
        ArrayList<Object> files_list = new ArrayList<Object>();
        for (String f : files) {
            files_list.add(f);
        }

        Scriptable res = cx.newArray(scope, files_list.toArray());
        return res;
    }
}

From source file:com.shenit.commons.utils.DataUtils.java

@SuppressWarnings("unchecked")
public static <T> Collection<T> parseNumbers(Collection<?> vals, Function<String, T> func) {
    if (vals == null || vals.isEmpty())
        return null;
    ArrayList<T> results = new ArrayList<T>();
    String str;/*w  w w. j  av  a 2s  . co m*/
    for (Object val : vals) {
        str = DataUtils.toString(val);
        if (StringUtils.isNumeric(str))
            results.add(func.apply(str));
    }
    return (Collection<T>) Arrays.asList(results.toArray());
}

From source file:com.sixsq.slipstream.factory.DeploymentFactory.java

private static void initNodesRuntimeParameters(Run run) throws ValidationException, NotFoundException {

    DeploymentModule deployment = (DeploymentModule) run.getModule();
    for (Node node : deployment.getNodes().values()) {

        String nodeName = node.getName();
        int multiplicity = getNodeMultiplicity(run, node);
        int multStartIndex = RuntimeParameter.MULTIPLICITY_NODE_START_INDEX;

        String nodeRunParameterKeyName = constructParamName(nodeName, RuntimeParameter.IDS_PARAMETER_NAME);
        ArrayList<String> ids = new ArrayList<String>();
        int maxIndex = multStartIndex == 0 ? (multiplicity - 1) : multiplicity;
        for (int i = multStartIndex; i <= maxIndex; i++) {
            ids.add(String.valueOf(i));
        }/*from  w  w w.j  a va 2  s  .c  o m*/
        run.assignRuntimeParameter(nodeRunParameterKeyName, StringUtils.join(ids.toArray(), ","),
                RuntimeParameter.IDS_PARAMETER_DESCRIPTION);

        run.assignRuntimeParameter(constructParamName(nodeName, RuntimeParameter.MULTIPLICITY_PARAMETER_NAME),
                String.valueOf(multiplicity), RuntimeParameter.MULTIPLICITY_PARAMETER_DESCRIPTION);

        run.assignRuntimeParameter(constructParamName(nodeName, RuntimeParameter.MAX_PROVISIONING_FAILURES),
                getMaxProvisioningFailures(run, node), RuntimeParameter.MAX_PROVISIONING_FAILURES_DESCRIPTION);
    }
}

From source file:edu.umass.cs.gnsclient.client.http.GNSHTTPProxy.java

/**
 * Converts a JSONObject to an array of key-value pairs wherein every
 * odd element is a key and the successive even element is the
 * corresponding value./*from  w w w  . j  ava 2s . c  o m*/
 *
 * @param json
 * @return
 * @throws JSONException
 */
public static Object[] getKeysAndValuesAsArray(JSONObject json) throws JSONException {
    ArrayList<Object> arrayList = new ArrayList<Object>();
    JSONArray jsonArray = json.names();
    for (int i = 0; i < jsonArray.length(); i++) {
        String key = (String) jsonArray.get(i);
        arrayList.add(key);
        arrayList.add(json.get(key));
    }
    return arrayList.toArray();
}

From source file:CountedList.java

private void compare(ArrayList lst, String[] strs) {
    Object[] array = lst.toArray();
    assertTrue("Arrays not the same length", array.length == strs.length);
    for (int i = 0; i < array.length; i++)
        assertEquals(strs[i], (String) array[i]);
}

From source file:Main.java

Main() {
    Container cp = getContentPane();
    cp.setLayout(new FlowLayout());
    ArrayList data = new ArrayList();
    data.add("Hi");
    data.add("Hello");
    data.add("Goodbye");
    list = new JList(data.toArray());
    list.addListSelectionListener(new ListSelectionListener() {
        public void valueChanged(ListSelectionEvent evt) {
            if (evt.getValueIsAdjusting())
                return;
            System.out.println("Selected from " + evt.getFirstIndex() + " to " + evt.getLastIndex());
        }/*from   w  ww  . jav  a  2  s  .  c  om*/
    });
    cp.add(new JScrollPane(list), BorderLayout.CENTER);
}

From source file:fr.simon.marquis.preferencesmanager.util.Utils.java

public static ArrayList<String> findXmlFiles(final String packageName) {
    Log.d(TAG, String.format("findXmlFiles(%s)", packageName));
    final ArrayList<String> files = new ArrayList<String>();
    CommandCapture cmd = new CommandCapture(CMD_FIND_XML_FILES.hashCode(), false,
            String.format(CMD_FIND_XML_FILES, packageName)) {
        @Override/*from  ww  w  . j a va2  s .c  o m*/
        public void commandOutput(int i, String s) {
            if (!files.contains(s)) {
                files.add(s);
            }
        }
    };

    synchronized (cmd) {
        try {
            RootTools.getShell(true).add(cmd).wait();
        } catch (Exception e) {
            Log.e(TAG, "Error in findXmlFiles", e);
        }
    }
    Log.d(TAG, "files: " + Arrays.toString(files.toArray()));
    return files;
}

From source file:MainClass.java

MainClass() {
    Container cp = getContentPane();
    cp.setLayout(new FlowLayout());
    ArrayList data = new ArrayList();
    data.add("Hi");
    data.add("Hello");
    data.add("Goodbye");
    list = new JList(data.toArray());
    list.addListSelectionListener(new ListSelectionListener() {
        public void valueChanged(ListSelectionEvent evt) {
            if (evt.getValueIsAdjusting())
                return;
            System.out.println("Selected from " + evt.getFirstIndex() + " to " + evt.getLastIndex());
        }/*from ww  w.j ava  2s.  com*/
    });
    cp.add(new JScrollPane(list), BorderLayout.CENTER);
}

From source file:com.espertech.esper.support.util.ArrayAssertionUtil.java

public static Object[] iteratorToArrayUnderlying(Iterator<EventBean> iterator) {
    ArrayList<Object> events = new ArrayList<Object>();
    for (; iterator.hasNext();) {
        events.add(iterator.next().getUnderlying());
    }//from   w w  w . ja  v  a  2s.  co  m
    return events.toArray();
}