Example usage for java.util ArrayList size

List of usage examples for java.util ArrayList size

Introduction

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

Prototype

int size

To view the source code for java.util ArrayList size.

Click Source Link

Document

The size of the ArrayList (the number of elements it contains).

Usage

From source file:Main.java

@SuppressWarnings("unchecked")
public static <E> E[] toArray(Enumeration<E> enumeration, Class<E> type) {
    ArrayList<E> elements = new ArrayList<E>();
    while (enumeration.hasMoreElements()) {
        elements.add(enumeration.nextElement());
    }/*from   w  ww.  ja v  a 2 s. c o  m*/
    E[] array = (E[]) Array.newInstance(type, elements.size());
    elements.toArray(array);
    return array;
}

From source file:Main.java

public static Node[] getChildrenNamed(Node node, String name) {
    ArrayList v = new ArrayList();

    NodeList nList = node.getChildNodes();
    for (int i = 0; i < nList.getLength(); i++) {
        Node n = nList.item(i);//  w  ww.  ja  v a2 s  .c  om
        if (n.getNodeName().equalsIgnoreCase(name)) {
            v.add(n);
        }
    }

    Node[] nodeArray = new Node[v.size()];
    nodeArray = (Node[]) v.toArray(nodeArray);
    return nodeArray;
}

From source file:fr.bmartel.android.tictactoe.request.ResponseParser.java

public static List<DeviceItem> parseDeviceList(Intent intent, String excludedDeviceId) {

    ArrayList<String> actionsStr = intent.getStringArrayListExtra("");

    List<DeviceItem> deviceList = new ArrayList<>();

    if (actionsStr.size() > 0) {
        try {//from  www .  j av a2  s . c  o m
            JSONObject mainObject = new JSONObject(actionsStr.get(0));
            if (mainObject.has(RequestConstants.DEVICE_ITEMS)) {

                JSONArray devices = mainObject.getJSONArray(RequestConstants.DEVICE_ITEMS);

                for (int i = 0; i < devices.length(); i++) {

                    JSONObject item = (JSONObject) devices.get(i);

                    JSONObject docItem = item.getJSONObject("doc");

                    if (docItem.has("_id") && docItem.has(RequestConstants.DEVICE_NAME)
                            && docItem.has(RequestConstants.DEVICE_STATE)) {

                        if (!docItem.getString("_id").equals(excludedDeviceId)) {

                            deviceList.add(new DeviceItem(docItem.getString("_id"),
                                    docItem.getString(RequestConstants.DEVICE_NAME),
                                    GameStates.getState(docItem.getInt(RequestConstants.DEVICE_STATE))));
                        }
                        /*
                        deviceList.add(new DeviceItem(docItem.getString("_id"),
                            docItem.getString(RequestConstants.DEVICE_NAME),
                            GameStates.getState(docItem.getInt(RequestConstants.DEVICE_STATE))));
                            */
                    }
                }
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }
    }
    return deviceList;
}

From source file:Main.java

public static String[] getStringIdArray(String serializedTree) {
    ArrayList<String> ids = new ArrayList<>();
    String[] values = serializedTree.split("[\\[\\],\"\\s]"); // Split on [ ] , or whitespace chars
    for (String idString : values) {
        if (!TextUtils.isEmpty(idString)) {
            ids.add(idString);//from  w ww . j  a va 2 s.  c  o  m
        }
    }
    return ids.toArray(new String[ids.size()]);
}

From source file:RMOS.PieChart.java

/**
 * Creates a sample dataset./*from  ww  w . j av  a  2s .c o m*/
 * 
 * Source: http://www.bbc.co.uk/news/business-15489523
 *
 * @return A sample dataset.
 */
private static PieDataset createDataset() {
    DefaultPieDataset dataset = new DefaultPieDataset();
    ArrayList<String> s1 = new ArrayList<String>();
    s1 = f1.getStationInGroup();
    for (int i = 0; i < s1.size(); i++) {
        //System.out.println(f1.getStationInGroup().get(i));
        //System.out.println(u.getInCapacity().get(i));
        dataset.setValue(f1.getStationInGroup().get(i), new Double(u.getInCapacity().get(i)));

    }

    /* dataset.setValue("Samsung", new Double(27.8));
     dataset.setValue("Others", new Double(55.3));
     dataset.setValue("Nokia", new Double(16.8));
     dataset.setValue("Apple", new Double(17.1));*/
    return dataset;
}

From source file:TokenizerUtil.java

public static String[] convertCSVStringToArray(String s) {
    ArrayList<String> list = new ArrayList<String>();
    StringTokenizer st = new StringTokenizer(s, "|");
    while (st.hasMoreTokens()) {
        String token = st.nextToken();
        list.add(token);/*from  w  w w  .ja  v a  2  s .  c  o  m*/
    }
    return (String[]) list.toArray(new String[list.size()]);
}

From source file:ch.unil.genescore.vegas.LinkageDisequilibrium.java

/** Compute rectangular 'cross'-correlation (LD) r values for the two given snp lists( */
static public RealMatrix computeCrossCorrelationMatrix(ArrayList<Snp> geneSnps1, ArrayList<Snp> geneSnps2) {

    // The correlation matrix for the given set of snps
    RealMatrix corr = MatrixUtils.createRealMatrix(geneSnps1.size(), geneSnps2.size());
    // For each snp pair
    for (int i = 0; i < geneSnps1.size(); i++) {
        for (int j = 0; j < geneSnps2.size(); j++) {
            Snp snp_i = geneSnps1.get(i);
            Snp snp_j = geneSnps2.get(j);
            double r = computeCorrelation(snp_i, snp_j);
            corr.setEntry(i, j, r);/*from w  w  w  . j  a va 2  s  .c  om*/
        }
    }
    return corr;
}

From source file:com.extrahardmode.module.UtilityModule.java

private static boolean isSameShape(ArrayList<ItemStack> recipe1, ArrayList<ItemStack> recipe2) {
    //compare recipes
    boolean isSame = true;
    for (int i = 0; i < recipe1.size(); i++) {
        if (!recipe1.get(i).getType().equals(recipe2.get(i).getType()))
            isSame = false;/*  ww  w. jav  a 2s.  c o  m*/
    }
    return isSame;
}

From source file:com.ilearnrw.reader.utils.HttpHelper.java

public static boolean refreshTokens(Context context) {
    SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
    String refreshToken = preferences.getString(context.getString(R.string.sp_refreshToken), "");

    if (refreshToken.isEmpty())
        return false;

    HttpResponse refreshResponse = HttpHelper
            .get("https://ssl.ilearnrw.eu/ilearnrw/user/newtokens?refresh=" + refreshToken);
    ArrayList<String> refreshData = HttpHelper.handleResponse(refreshResponse);

    if (refreshData == null)
        return false;

    if (refreshData.size() > 1) {
        try {/* w ww  . ja  v a  2s. c  o  m*/
            TokenResult lr = new Gson().fromJson(refreshData.get(1), TokenResult.class);
            SharedPreferences.Editor editor = preferences.edit();
            editor.putString(context.getString(R.string.sp_authToken), lr.authToken);
            editor.putString(context.getString(R.string.sp_refreshToken), lr.refreshToken);
            editor.apply();
            return true;
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }
    } else {
        Log.e("Error", refreshData.get(0));
    }

    return false;
}

From source file:com.clutch.ClutchAB.java

private static void sendABLogs() {
    ArrayList<ABRow> logs = stats.getABLogs();
    if (logs.size() == 0) {
        return;/*from   www. j a v a2s  . co  m*/
    }
    final ABRow lastRow = logs.get(logs.size() - 1);
    JSONArray jsonLogs = new JSONArray();
    for (ABRow row : logs) {
        JSONObject rowObj = new JSONObject();
        try {
            rowObj.put("uuid", row.uuid);
            rowObj.put("ts", row.ts);
            rowObj.put("data", row.data);
        } catch (JSONException e1) {
            Log.e(TAG,
                    "Could not properly encode the AB logs into JSON for upload to Clutch. Discarding the row."); // TODO: Don't discard the row.
            continue;
        }
        jsonLogs.put(rowObj);
    }
    HashMap<String, Object> params = new HashMap<String, Object>();
    params.put("logs", jsonLogs);
    params.put("guid", ClutchAPIClient.getFakeGUID());
    ClutchAPIClient.callMethod("send_ab_logs", params, new ClutchAPIResponseHandler() {
        @Override
        public void onSuccess(JSONObject response) {
            if ("ok".equals(response.optString("status"))) {
                stats.deleteABLogs(lastRow.ts);
            } else {
                Log.e(TAG, "Failed to send the Clutch AB logs to the server.");
            }
        }

        @Override
        public void onFailure(Throwable e, JSONObject errorResponse) {
            Log.e(TAG, "Failed to send AB logs to Clutch: " + errorResponse);
        }
    });
}