Example usage for java.util ArrayList set

List of usage examples for java.util ArrayList set

Introduction

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

Prototype

public E set(int index, E element) 

Source Link

Document

Replaces the element at the specified position in this list with the specified element.

Usage

From source file:Main.java

public static void permute(Random random, ArrayList array) {
    for (int i = 0; i < array.size(); i++) {
        int j = i + random.nextInt(array.size() - i);
        Object tmp = array.get(i);
        array.set(i, array.get(j));
        array.set(j, tmp);/*w w  w  .j  a v  a  2 s .c om*/
    }
}

From source file:Main.java

public static void uniqe(int[] words, ArrayList<Integer> tempUniqueWords, ArrayList<Integer> tempCounts) {
    for (int i = 0; i < words.length; i++) {
        if (tempUniqueWords.contains(words[i])) {
            int index = tempUniqueWords.indexOf(words[i]);
            tempCounts.set(index, tempCounts.get(index) + 1);
        } else {/* w  ww  . ja  v  a2 s .  co m*/
            tempUniqueWords.add(words[i]);
            tempCounts.add(1);
        }
    }
}

From source file:Main.java

public static void sortAsDouble(ArrayList<String> mylist) {
    String min = new String();
    int len = mylist.size();
    for (int i = 0; i < len; i++) {
        min = mylist.get(i);/*from  ww  w. ja v  a2 s . co  m*/
        for (int j = i + 1; j < len; j++) {
            if (compareAsDouble(min, mylist.get(j)) == 1) {
                mylist.set(i, mylist.get(j));
                mylist.set(j, min);
                min = mylist.get(i);
            }
        }
    }
}

From source file:Main.java

public static ArrayList<Integer> shuffleArray(int size) {
    ArrayList<Integer> shuffled = new ArrayList<>();
    for (int i = 0; i < size; i++) {
        shuffled.add(i);//from   w  ww .  j a v a  2s  . c o m
    }

    Random rnd = new Random();
    for (int i = size - 1; i > 0; i--) {
        int index = rnd.nextInt(i + 1);
        // Simple swap
        int a = shuffled.get(index);
        shuffled.set(index, shuffled.get(i));
        shuffled.set(i, a);
    }

    return shuffled;
}

From source file:Main.java

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

    /**//from   w w  w.  j a v a 2s .c  o  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:gov.va.vinci.leo.cr.BaseDatabaseCollectionReader.java

/**
 * Sets columns to "".//from w  ww  . j  a  v  a 2 s  . c o m
 * @param rows  The rows to process.
 * @param skipColumns  The columns in each row to set to "". Zero based.
 * @return   the rows with specified columns set to "".
 */
protected static ArrayList<String> removeUnneededColumns(ArrayList<String> rows, int... skipColumns) {
    // See of this one needs skipped.
    for (int toSkip : skipColumns) {
        rows.set(toSkip, "");
    }
    return rows;
}

From source file:mlflex.helper.MathUtilities.java

/** Rounds each of a list of numeric values to the specified number of decimal places.
 *
 * @param numbers List of numeric values to round
 * @param decimalPlaces Number of decimal places to use
 * @return List of rounded values/* w  ww. ja  va 2s  .co m*/
 */
public static ArrayList<Double> Round(ArrayList<Double> numbers, int decimalPlaces) {
    for (int i = 0; i < numbers.size(); i++)
        numbers.set(i, Round(numbers.get(i), decimalPlaces));
    return numbers;
}

From source file:nl.systemsgenetics.eqtlannotation.EncodeTfbsOverlap.java

private static ArrayList<EncodeNarrowPeak> processPeaks(ArrayList<EncodeNarrowPeak> value) {
    ArrayList<EncodeNarrowPeak> peaked = new ArrayList<>();

    for (EncodeNarrowPeak e : value) {
        if (peaked.size() == 0) {
            peaked.add(e);//from   www.java  2s .c o m
        } else {
            if (peaked.get((peaked.size() - 1)).getChromEnd() <= e.getChromStart()) {
                peaked.set((peaked.size() - 1),
                        EncodeNarrowPeak.mergeTwoEntries(peaked.get((peaked.size() - 1)), e));
            } else {
                peaked.add(e);
            }
        }
    }

    return peaked;
}

From source file:org.nines.RdfDocumentParser.java

public static HashMap<String, HashMap<String, ArrayList<String>>> parse(final File file,
        ErrorReport errorReport, LinkCollector linkCollector, RDFIndexerConfig config) throws IOException {

    largestTextSize = 0;/*  w  ww. ja va2 s  .c o m*/
    RDFXMLParser parser = new RDFXMLParser();
    NinesStatementHandler statementHandler = new NinesStatementHandler(errorReport, linkCollector, config);
    statementHandler.setFile(file);

    parser.setRDFHandler(statementHandler);
    parser.setParseErrorListener(new ParseListener(file, errorReport));
    parser.setVerifyData(true);
    parser.setStopAtFirstError(false);

    // parse file
    try {

        String content = validateContent(file, errorReport);
        parser.parse(new StringReader(content), "http://foo/" + file.getName());

    } catch (RDFParseException e) {
        errorReport.addError(new IndexerError(file.getName(), "",
                "Parse Error on Line " + e.getLineNumber() + ": " + e.getMessage()));
    } catch (RDFHandlerException e) {
        errorReport.addError(
                new IndexerError(file.getName(), "", "StatementHandler Exception: " + e.getMessage()));
    } catch (Exception e) {
        errorReport.addError(new IndexerError(file.getName(), "", "RDF Parser Error: " + e.getMessage()));
        e.printStackTrace();
    }

    // retrieve parsed data
    HashMap<String, HashMap<String, ArrayList<String>>> docHash = statementHandler
            .getDocuments(config.isPagesArchive());

    // process tags
    Collection<HashMap<String, ArrayList<String>>> documents = docHash.values();
    for (HashMap<String, ArrayList<String>> document : documents) {

        // normalize tags, replace spaces with dashes, lowercase
        ArrayList<String> tags = document.remove("tag");
        if (tags != null) {
            for (int i = 0; i < tags.size(); i++) {
                String tag = tags.get(i);
                tag = tag.toLowerCase();
                tag = tag.replaceAll(" ", "-");
                tags.set(i, tag);
            }
            // username is archive name
            String archive = document.get("archive").get(0);
            ArrayList<String> nameList = new ArrayList<String>();
            nameList.add(archive);
            document.put("username", nameList);
            document.put(archive + "_tag", tags);
        }
    }

    largestTextSize = statementHandler.getLargestTextSize();
    return docHash;
}

From source file:Main.java

public static int getFrequentElement(int[] bcp) {
    HashMap<Integer, Integer> map = new HashMap<Integer, Integer>();
    ArrayList<Integer> count = new ArrayList<Integer>();
    ArrayList<Integer> uniId = new ArrayList<Integer>();
    int id = 0;// ww  w . j av a  2  s.c  o m

    for (int col = 0; col < bcp.length; col++) {
        //System.out.print(bcp[col] + "\t");
        int no = 0;
        if (!map.containsKey(bcp[col])) {
            map.put(bcp[col], id++);
            count.add(1);
            uniId.add(bcp[col]);
        } else {
            no = map.get(bcp[col]);
            count.set(no, count.get(no) + 1);
        }
    }

    int maximum = Integer.MIN_VALUE;
    int maxId = Integer.MIN_VALUE;
    for (int i = 0; i < count.size(); i++) {
        //System.out.print(uniId.get(i) + ":" + count.get(i) + ",\t");
        if (maximum < count.get(i)) {
            maximum = count.get(i);
            maxId = uniId.get(i);
        }
    }
    //System.out.println();

    map.clear();
    uniId.clear();
    count.clear();
    return maxId;
}