Example usage for java.util ArrayList get

List of usage examples for java.util ArrayList get

Introduction

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

Prototype

public E get(int index) 

Source Link

Document

Returns the element at the specified position in this list.

Usage

From source file:Main.java

/**
 * Change the extension of specified file.<br>
 * Usage :<br>//w ww . ja  va  2 s  . c  om
 * f.renameTo(MyFileUtility.reExtension(f, "jpg")) ;<br>
 * As we know ,File class is a dummy File , <br>
 * thus , you must follow the usage to change extension.
 * @param fin File input
 * @param newExtension newExtension without '.'
 * @return File with new extension
 */
public static File reExtension(File fin, String newExtension) {
    //Usage: f.renameTo(MyFileUtility.reExtension(f, "jpg")) ;
    StringTokenizer strTokener = new StringTokenizer(fin.getName(), ".");
    //For a file may has many '.' in its file name , we use a collection to stroe it.
    ArrayList<String> strVec = new ArrayList<String>();
    while (strTokener.hasMoreTokens())
        strVec.add(strTokener.nextToken());

    String newName = "";
    //Give up the original extension
    for (int i = 0; i != strVec.size() - 1; ++i) {
        newName += strVec.get(i);
        newName += ".";
    }
    newName += newExtension;
    return new File(fin.getParent() + "\\" + newName);
}

From source file:br.com.ifpb.models.Grafico.java

/**
 * //w w w.  j a va2 s.  c o m
 * @param nome
 * @param valor
 * @param tituloGrafico
 * @param transparencia
 * @param tipo
 * @return 
 */
private static javax.swing.JPanel pizza3D(ArrayList nome, ArrayList valor, String tituloGrafico,
        float transparencia, String tipo) {

    DefaultPieDataset data = new DefaultPieDataset();

    for (int i = 0; i < nome.toArray().length; i++) {
        data.setValue("" + nome.get(i).toString(), new Double(valor.get(i).toString()));
    }

    JFreeChart chart = ChartFactory.createPieChart3D(tituloGrafico, data, true, true, true);
    java.awt.Color cor = new java.awt.Color(200, 200, 200);
    chart.setBackgroundPaint(cor);
    PiePlot3D plot = (PiePlot3D) chart.getPlot();
    plot.setLabelLinksVisible(true);
    plot.setNoDataMessage("No existem dados para serem exibidos ");

    plot.setStartAngle(90);
    plot.setDirection(Rotation.CLOCKWISE);
    plot.setForegroundAlpha(transparencia);
    plot.setInteriorGap(0.20);

    ChartPanel chartPanel = new ChartPanel(chart);

    return chartPanel;
}

From source file:Main.java

public static void split(String[] items, ArrayList<String> res, int number) {
    // split items to res1 and res2, where res2 has number items
    res.clear();/*from   w ww .  j  a va  2  s.c om*/
    String res1 = "";
    String res2 = "";
    ArrayList<String> newList = new ArrayList<String>();
    for (int i = 0; i < items.length; i++) {
        newList.add(items[i]);
    }
    Collections.shuffle(newList);
    for (int i = 0; i < newList.size(); i++) {
        if (i < number) {
            res1 += newList.get(i) + "\t";
        } else {
            res2 += newList.get(i) + "\t";
        }
    }
    res.add(res1);
    res.add(res2);
}

From source file:Main.java

public static void addToFacebookContact(Context mContext, ArrayList<String> contactDatas) {

    /**//  w  ww.j a  va 2 s  .co m
     * ArrayList elements:
     * 
     * 1. Name 2. Userid 3.Username
     */

    Intent i = new Intent(Intent.ACTION_INSERT_OR_EDIT);
    i.setType(ContactsContract.Contacts.CONTENT_ITEM_TYPE);

    if (contactDatas.get(2) == null) {
        contactDatas.set(2, "Facebook name");
    }

    ArrayList<ContentValues> data = new ArrayList<ContentValues>();
    ContentValues row1 = new ContentValues();
    row1.put(ContactsContract.Data.MIMETYPE, ContactsContract.CommonDataKinds.Im.CONTENT_ITEM_TYPE);
    row1.put(ContactsContract.Data.DATA1, contactDatas.get(2));
    row1.put(ContactsContract.Data.DATA2, ContactsContract.CommonDataKinds.Im.TYPE_OTHER);
    row1.put(ContactsContract.Data.DATA5, ContactsContract.CommonDataKinds.Im.PROTOCOL_CUSTOM);
    row1.put(ContactsContract.Data.DATA6, "Facebook");
    row1.put(ContactsContract.Data.DATA10, contactDatas.get(1));
    data.add(row1);

    i.putExtra(Insert.NAME, contactDatas.get(0));
    i.putParcelableArrayListExtra(ContactsContract.Intents.Insert.DATA, data);

    mContext.startActivity(i);
}

From source file:eu.eexcess.partnerdata.evaluation.enrichment.PartnerRecommenderEvaluationTestHelper.java

static public void testService(String serviceName) {
    ArrayList<String> keywords = PartnerRecommenderEvaluationTestHelper.readKeywords();
    for (int i = 0; i < keywords.size(); i++) {
        ArrayList<String> keyword = new ArrayList<String>();
        keyword.add(keywords.get(i));
        ResultList resultList = PartnerRecommenderEvaluationTestHelper.getRecommendations(
                "eexcess-partner-" + serviceName + "-1.0-SNAPSHOT", port,
                PartnerRecommenderEvaluationTestHelper.createParamsForPartnerRecommender(20, keyword));
        System.out.print(" " + i);
    }/*from   www.  jav a 2  s .  com*/

}

From source file:com.ettoremastrogiacomo.sktradingjava.starters.Temp.java

public static <T> java.util.Set<T> longestSet(ArrayList<TreeSet<T>> list) {
    if (list.isEmpty())
        return new java.util.TreeSet<>();
    java.util.TreeSet<T> best = list.get(0);
    for (TreeSet<T> s : list) {
        if (best.size() < s.size())
            best = s;//from w  ww . j  a v  a 2 s . c  o m
    }
    return best;
}

From source file:org.opendatakit.survey.android.provider.FileSet.java

public static final FileSet parse(Context context, String appName, InputStream src)
        throws JsonParseException, JsonMappingException, IOException {
    @SuppressWarnings("unchecked")
    ArrayList<Map<String, String>> str = ODKFileUtils.mapper.readValue(src, ArrayList.class);

    FileSet fs = new FileSet(appName);
    Map<String, String> map;
    map = (Map<String, String>) str.get(0);
    fs.instanceFile = ODKFileUtils.getAsFile(appName, map.get(URI_FRAGMENT));
    for (int i = 1; i < str.size(); ++i) {
        map = (Map<String, String>) str.get(i);
        MimeFile f = new MimeFile();
        f.file = ODKFileUtils.getAsFile(appName, map.get(URI_FRAGMENT));
        f.contentType = map.get(CONTENT_TYPE);
        fs.attachmentFiles.add(f);// ww w.  j  a  v  a 2 s  .  c om
    }
    return fs;
}

From source file:com.tmobile.TMobileParsing.java

protected static List<Profile> parseProfiles(JsonObject jsonProfiles) {
    List<Profile> profiles = new ArrayList<>();

    Set<Map.Entry<String, JsonElement>> keys = jsonProfiles.entrySet();
    ArrayList<Map.Entry<String, JsonElement>> profileIds = new ArrayList<>(keys);

    for (int i = 0; i < profileIds.size(); i++) {
        String profileId = profileIds.get(i).getKey();
        JsonObject jsonProfile = jsonProfiles.get(profileId).getAsJsonObject();
        String roleName = jsonProfile.get("roleName").getAsString();

        Profile profile = new Profile();
        profile.setId(profileId);/*from w w  w .j av a  2s .c  o  m*/
        profile.setRoleName(roleName);

        //Process billing account
        BillingAccount billingAccount = extractBillingAccount(jsonProfile);
        profile.setBillingAccount(billingAccount);
        //End of billing account

        //Process balance
        JsonObject jsonBillingAccount = jsonProfile.getAsJsonObject("billingAccount");

        Balance balance = extractBalance(jsonBillingAccount);
        billingAccount.setBalance(balance); //Set it in the billing account
        //End of balance

        //Process subscriptions
        List<Subscription> subscriptions = parseSubscriptions(
                jsonBillingAccount.getAsJsonObject("subscriptions"));
        billingAccount.setSubscriptions(subscriptions);
        //End of subscriptions

        profiles.add(profile);
    }

    return profiles;
}

From source file:Main.java

@SuppressWarnings("unchecked")
private static void putArray(String key, ArrayList arrayList, Bundle bundle) {
    if (arrayList.size() == 0) {
        bundle.putBooleanArray(key, new boolean[] {});
    } else {/*from ww  w .  jav  a 2s. co  m*/
        verifyArrayListIsSingleType(arrayList);
        if (arrayList.get(0) instanceof String) {
            bundle.putStringArray(key, toStringArray((ArrayList<String>) arrayList));
        } else if (arrayList.get(0) instanceof Integer) {
            bundle.putIntArray(key, toIntArray((ArrayList<Integer>) arrayList));
        } else if (arrayList.get(0) instanceof Float) {
            bundle.putFloatArray(key, toFloatArray((ArrayList<Float>) arrayList));
        } else if (arrayList.get(0) instanceof Double) {
            bundle.putDoubleArray(key, toDoubleArray((ArrayList<Double>) arrayList));
        } else if (arrayList.get(0) instanceof Boolean) {
            bundle.putBooleanArray(key, toBooleanArray((ArrayList<Boolean>) arrayList));
        } else if (arrayList.get(0) instanceof HashMap) {
            bundle.putParcelableArray(key, toBundleArray((ArrayList<HashMap>) arrayList));
        } else if (arrayList.get(0) instanceof ArrayList) {
            Log.w("RNNavigation",
                    "Arrays of arrays passed in props are converted to dictionaries with indexes as keys");
            Bundle innerArray = new Bundle();
            for (int i = 0; i < arrayList.size(); i++) {
                putArray(String.valueOf(i), (ArrayList) arrayList.get(i), innerArray);
            }
            bundle.putParcelable(key, innerArray);
        }
    }
}

From source file:adept.utilities.Grapher.java

/**
 * Make heap usage graph.//from w  w  w.ja  v  a 2s .c o  m
 *
 * @param values the values
 * @param filename the filename
 */
public static void makeHeapUsageGraph(ArrayList<Double> values, File filename) {
    try {
        DefaultCategoryDataset line_chart_dataset = new DefaultCategoryDataset();
        for (int i = 1; i <= values.size(); i++) {
            line_chart_dataset.addValue(values.get(i - 1), "MB", "" + i);
        }

        /* Step -2:Define the JFreeChart object to create line chart */
        JFreeChart lineChartObject = ChartFactory.createLineChart("Heap Memory Usage", "Run Number",
                "Heap Memory Used", line_chart_dataset, PlotOrientation.VERTICAL, true, true, false);

        /* Step -3 : Write line chart to a file */
        int width = 640; /* Width of the image */
        int height = 480; /* Height of the image */
        ChartUtilities.saveChartAsPNG(filename, lineChartObject, width, height);
    }

    catch (Exception e) {
        e.printStackTrace();
    }

}