Example usage for java.util ArrayList clear

List of usage examples for java.util ArrayList clear

Introduction

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

Prototype

public void clear() 

Source Link

Document

Removes all of the elements from this list.

Usage

From source file:io.agi.framework.persistence.DataJsonSerializer.java

public static String FloatArrayToString(FloatArray fa, String encoding) {
    String s1 = "{ \"encoding\":\"" + encoding + "\",\"length\":";
    String s2 = ",\"elements\":["; // put elements last
    String s3 = "]}";

    String length = String.valueOf(fa._values.length);
    ArrayList<String> chunks = new ArrayList<String>();
    ArrayList<String> values = new ArrayList<String>();
    int chunkSize = 100;

    if ((encoding != null) && (encoding.equals(ENCODING_SPARSE_BINARY))) {
        for (int i = 0; i < fa._values.length; ++i) {
            float value = fa._values[i];
            if (value == 0.f) {
                continue; // only add the nonzero value indices.
            }//from   ww w .  ja va2 s.  c  o  m

            String s = String.valueOf(i); // Important! Serializing this as integer.
            values.add(s);
            if (values.size() >= chunkSize) {
                String chunk = StringUtils.join(values, ",");
                chunks.add(chunk);
                values.clear();
            }
        }
    } else if ((encoding != null) && (encoding.equals(ENCODING_SPARSE_REAL))) {
        for (int i = 0; i < fa._values.length; ++i) {
            float value = fa._values[i];
            if (value == 0.f) {
                continue; // only add the nonzero value indices.
            }

            String s = String.valueOf(i) + "," + String.valueOf(value); // index,value
            values.add(s);
            if (values.size() >= chunkSize) {
                String chunk = StringUtils.join(values, ",");
                chunks.add(chunk);
                values.clear();
            }
        }
        //System.err.println( " Sparse real encoding: Original size: " + fa._values.length + " encoded size: " + values.size() );
    } else {
        values.ensureCapacity(fa._values.length);
        for (int i = 0; i < fa._values.length; ++i) {
            float value = fa._values[i];
            String s = String.valueOf(value);
            values.add(s);
            if (values.size() >= chunkSize) {
                String chunk = StringUtils.join(values, ",");
                chunks.add(chunk);
                values.clear();
            }
        }
    }

    // clear last values into chunks
    if (values.size() > 0) {
        String chunk = StringUtils.join(values, ",");
        chunks.add(chunk);
        values.clear();
    }

    String elements = StringUtils.join(chunks, ",");
    String result = s1 + length + s2 + elements + s3;
    return result;
}

From source file:com.dmplayer.childfragment.MVDowningFragment.java

public ArrayList<String> getTitle() {
    ArrayList<String> messageInfos = new ArrayList<String>();
    messageInfos.clear();
    messageInfos.add("");
    messageInfos.add("");
    messageInfos.add("");
    messageInfos.add("");
    messageInfos.add("MV");
    messageInfos.add("?");
    messageInfos.add("");
    return messageInfos;
}

From source file:com.dmplayer.childfragment.MVDowningFragment.java

public ArrayList<Integer> getIcon() {
    ArrayList<Integer> messageInfos = new ArrayList<Integer>();
    messageInfos.clear();
    messageInfos.add(R.mipmap.musicthree);
    messageInfos.add(R.mipmap.musicone);
    messageInfos.add(R.mipmap.musicfour);
    messageInfos.add(R.mipmap.musicone);
    messageInfos.add(R.mipmap.musicfive);
    messageInfos.add(R.mipmap.musicsix);
    messageInfos.add(R.mipmap.musictwo);

    return messageInfos;
}

From source file:de.fhg.igd.mapviewer.server.wms.wizard.pages.BasicConfigurationWithWMSListPage.java

/**
 * Put all map entries into a given list
 * /* ww  w. ja v a2  s.c  om*/
 * @param list list to fill
 */
private void getListForUI(ArrayList<String> list) {

    list.clear();
    for (Map.Entry<String, String> entry : map.entrySet()) {
        list.add(entry.getKey());
    }
}

From source file:com.dmplayer.childfragment.MyMusicFragment.java

public ArrayList<Integer> getIcon() {
    ArrayList<Integer> messageInfos = new ArrayList<Integer>();
    messageInfos.clear();
    messageInfos.add(R.mipmap.music);//from w w w .j a v  a2 s  .c om
    messageInfos.add(R.mipmap.favorite);
    messageInfos.add(R.mipmap.music);
    messageInfos.add(R.mipmap.favorite);
    messageInfos.add(R.mipmap.music);
    messageInfos.add(R.mipmap.favorite);
    messageInfos.add(R.mipmap.music);

    return messageInfos;
}

From source file:com.android.calendar.Event.java

/**
 * Loads <i>days</i> days worth of instances starting at <i>startDay</i>.
 *//*from  w w w . j a v  a 2s  .c  o  m*/
public static void loadEvents(Context context, ArrayList<Event> events, int startDay, int days, int requestId,
        AtomicInteger sequenceNumber) {

    if (PROFILE) {
        Debug.startMethodTracing("loadEvents");
    }

    if (Build.VERSION.SDK_INT >= 23 && ContextCompat.checkSelfPermission(context,
            Manifest.permission.READ_CALENDAR) != PackageManager.PERMISSION_GRANTED) {
        //If permission is not granted then just return.
        return;
    }

    Cursor cEvents = null;
    Cursor cAllday = null;

    events.clear();
    try {
        int endDay = startDay + days - 1;

        // We use the byDay instances query to get a list of all events for
        // the days we're interested in.
        // The sort order is: events with an earlier start time occur
        // first and if the start times are the same, then events with
        // a later end time occur first. The later end time is ordered
        // first so that long rectangles in the calendar views appear on
        // the left side.  If the start and end times of two events are
        // the same then we sort alphabetically on the title.  This isn't
        // required for correctness, it just adds a nice touch.

        // Respect the preference to show/hide declined events
        SharedPreferences prefs = GeneralPreferences.getSharedPreferences(context);
        boolean hideDeclined = prefs.getBoolean(GeneralPreferences.KEY_HIDE_DECLINED, false);

        String where = EVENTS_WHERE;
        String whereAllday = ALLDAY_WHERE;
        if (hideDeclined) {
            String hideString = " AND " + Instances.SELF_ATTENDEE_STATUS + "!="
                    + Attendees.ATTENDEE_STATUS_DECLINED;
            where += hideString;
            whereAllday += hideString;
        }

        cEvents = instancesQuery(context.getContentResolver(), EVENT_PROJECTION, startDay, endDay, where, null,
                SORT_EVENTS_BY);
        cAllday = instancesQuery(context.getContentResolver(), EVENT_PROJECTION, startDay, endDay, whereAllday,
                null, SORT_ALLDAY_BY);

        // Check if we should return early because there are more recent
        // load requests waiting.
        if (requestId != sequenceNumber.get()) {
            return;
        }

        buildEventsFromCursor(events, cEvents, context, startDay, endDay);
        buildEventsFromCursor(events, cAllday, context, startDay, endDay);

    } finally {
        if (cEvents != null) {
            cEvents.close();
        }
        if (cAllday != null) {
            cAllday.close();
        }
        if (PROFILE) {
            Debug.stopMethodTracing();
        }
    }
}

From source file:android.support.design.widget.DirectedAcyclicGraph.java

private void poolList(@NonNull ArrayList<T> list) {
    list.clear();
    mListPool.release(list);
}

From source file:com.onpositive.semantic.words3.MultiHashMap.java

public void clear() {
    Set pairs = super.entrySet();
    Iterator pairsIterator = pairs.iterator();
    while (pairsIterator.hasNext()) {
        Map.Entry keyValuePair = (Map.Entry) (pairsIterator.next());
        ArrayList list = (ArrayList) (keyValuePair.getValue());
        list.clear();
    }/*w  ww .  ja  v a  2s .com*/
    super.clear();
}

From source file:cn.edu.zjnu.acm.judge.mapper.UserMapperTest.java

/**
 * Test of findAll method, of class UserMapper.
 */// www.j a v a 2 s  .c o m
@Test
public void testFindAll() {
    log.info("findAll");
    Pageable pageable = new PageRequest(0, 50);
    List<User> result = instance.findAll(pageable);
    log.debug("{}", result);

    pageable = new PageRequest(0, 50, new Sort(new Sort.Order(Sort.Direction.DESC, "solved"),
            new Sort.Order(Sort.Direction.ASC, "submit")));
    result = instance.findAll(pageable);
    log.debug("{}", result);

    Sort.Order order = new Sort.Order(Sort.Direction.DESC, "solved");
    ArrayList<Sort.Order> list = new ArrayList<>(1);
    list.add(order);
    pageable = new PageRequest(0, 50, new Sort(list));
    list.clear();
    result = instance.findAll(pageable);
    log.debug("{}", result);
}

From source file:net.tawacentral.roger.secrets.FileUtils.java

/**
 * Import secrets from a CSV file.  This function will first clear the secrets
 * list argument before adding anything read from the file. If there are no
 * errors while reading, true is returned.
 *
 * Note that its possible for this function to return false, and yet the
 * secrets list is not empty.  This means that some, but not all, secrets
 * were able to be read from the file./*from  w ww  . j av  a  2s .com*/
 *
 * For the moment, this function assumes that the first line is a description
 * so it is not imported.  At least 5 columns are assumed for each line:
 * description, username, password, email, and notes, in that order (this is
 * the default format as written by exportSecrets()).
 *
 * This function will attempt to detect OI Safe CSV files and import them
 * accordingly.  It does this by reading the first line of file, and looking
 * for column descriptions as exported by OI Safe 1.1.0.
 *
 * @param context Activity context for global services
 * @param file File to import
 * @param secrets List to append secrets read from the file
 * @return True if all secrets read successfully, and false otherwise
 */
public static boolean importSecrets(Context context, File file, ArrayList<Secret> secrets) {
    secrets.clear();

    boolean isOiSafeCsv = false;
    boolean isSecretsScv = false;
    boolean success = false;
    CSVReader reader = null;

    try {
        reader = new CSVReader(new FileReader(file));

        // Use the first line to determine the type of csv file.  Secrets will
        // output 5 columns, with the names as used in the exportSecrets()
        // function.  OI Safe 1.1.0 is also detected.
        String headers[] = reader.readNext();
        if (null != headers) {
            isSecretsScv = isSecretsCsv(headers);
            if (!isSecretsScv)
                isOiSafeCsv = isOiSafeCsv(headers);
        }

        // Read all the rest of the lines as secrets.
        for (;;) {
            String[] row = reader.readNext();
            if (null == row)
                break;

            Secret secret = new Secret();
            if (isOiSafeCsv) {
                secret.setDescription(row[1]);
                secret.setUsername(row[3]);
                secret.setPassword(row[4], false);
                secret.setEmail(EMPTY_STRING);

                // I will combine the category, website, and notes columns into
                // the notes field in secrets.
                int approxMaxLength = row[0].length() + row[2].length() + row[5].length() + 32;
                StringBuilder builder = new StringBuilder(approxMaxLength);
                builder.append(row[5]).append("\n\n");
                builder.append("Category: ").append(row[0]).append('\n');
                if (null != row[2] && row[2].length() > 0)
                    builder.append("Website: ").append(row[2]).append('\n');

                secret.setNote(builder.toString());
            } else {
                // If we get here, then this may be an unknown format.  For better
                // or for worse, this is a "best effort" to import that data.
                secret.setDescription(row[0]);
                secret.setUsername(row[1]);
                secret.setPassword(row[2], false);
                secret.setEmail(row[3]);
                secret.setNote(row[4]);
            }

            secrets.add(secret);
        }

        // We'll only return complete success if we get here, and we detected
        // that we knew the file format.  This will give the user an indication
        // do look at the secrets if the format was not automatically detected.
        success = isOiSafeCsv || isSecretsScv;
    } catch (Exception ex) {
        Log.e(LOG_TAG, "importSecrets", ex);
    } finally {
        try {
            if (null != reader)
                reader.close();
        } catch (IOException ex) {
        }
    }

    return success;
}