Example usage for java.util List clear

List of usage examples for java.util List clear

Introduction

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

Prototype

void clear();

Source Link

Document

Removes all of the elements from this list (optional operation).

Usage

From source file:cz.muni.fi.mir.tools.Tools.java

/**
 * Method removes element from given List at specified position.
 * @param <T> type of list//from  w w  w .ja  v a 2 s  . c o m
 * @param list from which we would like to remove element
 * @param position of element to be deleted
 */
@Deprecated
public <T> void removeElementFromList(List<T> list, int position) { // iba mna mohla napadnut niekedy takato blbost a nepouzit sublist... 
    List<T> result = new ArrayList<>();
    int i = 0;
    for (T t : list) {
        if (i != position) {
            result.add(t);
        }
        i++;
    }

    list.clear();
    list.addAll(result);
}

From source file:convert.ConvertStrata.java

@Test
public void convert() throws IOException {
    System.out.println("Convert strata test");
    LineIterator it = FileUtils.lineIterator(
            new File("\\\\delphi\\felles\\alle\\smund\\stox\\strata_norskehavstoktet\\stratum1-6 2014.txt"));
    it.nextLine(); // skip header
    List<Coordinate> coords = new ArrayList<>();
    String strata = null;/*from   w w w .  j av  a  2  s . c om*/
    while (it.hasNext()) {
        String line = it.nextLine().trim();
        String elms[] = line.split("\t");
        String s = elms[2];
        if (strata != null && !s.equals(strata)) {
            MultiPolygon mp = JTSUtils.createMultiPolygon(Arrays.asList(JTSUtils.createLineString(coords)));
            System.out.println(strata + "\t" + mp);
            coords.clear();
        }
        coords.add(new Coordinate(Conversion.safeStringtoDoubleNULL(elms[1]),
                Conversion.safeStringtoDoubleNULL(elms[0])));
        strata = s;
    }
    MultiPolygon mp = JTSUtils.createMultiPolygon(Arrays.asList(JTSUtils.createLineString(coords)));
    System.out.println(strata + "\t" + mp);
}

From source file:Main.java

private static <E> void updateList(List<E> origList, Collection<? extends E> updateList, boolean add,
        boolean replace, boolean remove, BiPredicate<? super E, ? super E> equalTester,
        BiConsumer<List<E>, Collection<? extends E>> adder) {
    List<E> itemsToRemove = null;
    List<E> itemsToAdd = null;
    for (E update : updateList) {
        boolean origListContainsUpdate = false;
        ListIterator<E> origIter = origList.listIterator();
        while (origIter.hasNext()) {
            E orig = origIter.next();//from   w w  w .  j  a va  2s .  c o m
            if (equalTester.test(orig, update)) {
                origListContainsUpdate = true;
                if (remove) {
                    if (itemsToRemove == null) {
                        itemsToRemove = new ArrayList<>(origList);
                    }
                    itemsToRemove.remove(orig);
                }
                if (replace) {
                    origIter.set(update);
                }
                break;
            }
        }
        if (!origListContainsUpdate && add) {
            if (itemsToAdd == null) {
                itemsToAdd = new ArrayList<>();
            }
            itemsToAdd.add(update);
        }
    }
    if (remove) {
        if (itemsToRemove != null) {
            origList.removeAll(itemsToRemove);
        } else {
            origList.clear();
        }
    }
    if (itemsToAdd != null) {
        adder.accept(origList, itemsToAdd);
    }
}

From source file:com.google.api.ads.dfp.appengine.util.Channels.java

/**
 * Sends a list of objects via the channel API. Objects are broken up into batches because the
 * size of each message is capped./*from   ww  w . j a v  a  2s .c  o m*/
 *
 * @param channelKey the key to send a message via the Channel API
 * @param objects a list of objects to send via the channel
 * @param tag the name of the content panel to send objects
 * @param requestId the ID of the incoming data request to respond to
 */
public void sendObjects(String channelKey, List<?> objects, String tag, String requestId) {
    checkPreconditions(channelKey, tag, requestId);
    List<Object> list = Lists.newArrayList();
    int count = 0;
    for (Object object : objects) {
        count += 1;
        list.add(object);
        if (count % BATCH_SIZE == 0) {
            sendMessage(channelKey, ImmutableList.copyOf(list), tag, requestId);
            list.clear();
        }
    }
    if (!list.isEmpty()) {
        sendMessage(channelKey, list, tag, requestId);
    }
    if (count == 0) {
        sendNoResultMessage(channelKey, tag, requestId);
    }
}

From source file:com.koda.integ.hbase.test.BlockCacheSimpleRegionTests.java

/**
 * Test region scanner.// w  w w . j a va 2 s. c  o m
 *
 * @throws IOException Signals that an I/O exception has occurred.
 */
public void testRegionScanner() throws IOException {
    LOG.info("Test Region scanner");
    Scan scan = new Scan();
    scan.setStartRow(region.getStartKey());
    scan.setStopRow(region.getEndKey());
    RegionScanner scanner = region.getScanner(scan);
    //Store store = region.getStore(CF);
    //StoreScanner scanner = new StoreScanner(store,  store.getScanInfo(), scan,  null);
    long start = System.currentTimeMillis();
    int total = 0;
    List<Cell> result = new ArrayList<Cell>();
    while (scanner.next(result)) {
        total++;
        result.clear();
    }

    LOG.info("Test Region scanner finished. Found " + total + " in " + (System.currentTimeMillis() - start)
            + "ms");
    LOG.info("cache hits =" + cache.getStats().getHitCount() + " miss=" + cache.getStats().getMissCount());

}

From source file:com.healthmarketscience.jackcess.util.ImportUtil.java

/**
 * Copy a delimited text file into a new (or optionally exixsting) table in
 * this database.//  w w w . j ava2 s  . c  om
 * 
 * @param name Name of the new table to create
 * @param in Source reader to import
 * @param delim Regular expression representing the delimiter string.
 * @param quote the quote character
 * @param filter valid import filter
 * @param useExistingTable if {@code true} use current table if it already
 *                         exists, otherwise, create new table with unique
 *                         name
 * @param header if {@code false} the first line is not a header row, only
 *               valid if useExistingTable is {@code true}
 *
 * @return the name of the imported table
 * 
 * @see Builder
 */
public static String importReader(BufferedReader in, Database db, String name, String delim, char quote,
        ImportFilter filter, boolean useExistingTable, boolean header) throws IOException {
    String line = in.readLine();
    if (line == null || line.trim().length() == 0) {
        return null;
    }

    Pattern delimPat = Pattern.compile(delim);

    try {
        name = TableBuilder.escapeIdentifier(name);
        Table table = null;
        if (!useExistingTable || ((table = db.getTable(name)) == null)) {

            List<ColumnBuilder> columns = new LinkedList<ColumnBuilder>();
            Object[] columnNames = splitLine(line, delimPat, quote, in, 0);

            for (int i = 0; i < columnNames.length; i++) {
                columns.add(new ColumnBuilder((String) columnNames[i], DataType.TEXT).escapeName()
                        .setLength((short) DataType.TEXT.getMaxSize()).toColumn());
            }

            table = createUniqueTable(db, name, columns, null, filter);

            // the first row was a header row
            header = true;
        }

        List<Object[]> rows = new ArrayList<Object[]>(COPY_TABLE_BATCH_SIZE);
        int numColumns = table.getColumnCount();

        if (!header) {
            // first line is _not_ a header line
            Object[] data = splitLine(line, delimPat, quote, in, numColumns);
            data = filter.filterRow(data);
            if (data != null) {
                rows.add(data);
            }
        }

        while ((line = in.readLine()) != null) {
            Object[] data = splitLine(line, delimPat, quote, in, numColumns);
            data = filter.filterRow(data);
            if (data == null) {
                continue;
            }
            rows.add(data);
            if (rows.size() == COPY_TABLE_BATCH_SIZE) {
                table.addRows(rows);
                rows.clear();
            }
        }
        if (rows.size() > 0) {
            table.addRows(rows);
        }

        return table.getName();

    } catch (SQLException e) {
        throw (IOException) new IOException(e.getMessage()).initCause(e);
    }
}

From source file:com.mozilla.bagheera.hazelcast.persistence.ElasticSearchIndexMapStore.java

@Override
public void storeAll(Map<String, String> pairs) {
    LOG.info("mapstore: received something in queue for storeAll:" + pairs.size());
    LOG.debug("calling storeAll method");
    List<String> rowIds = new ArrayList<String>();
    for (String row : pairs.keySet()) {
        if (StringUtils.isNotBlank(row)) {
            rowIds.add(row);//from   w  w  w .j a  v a2 s.c  o m
            if (rowIds.size() % 100 == 0) {
                LOG.info("map size: " + pairs.size());
                indexJsons(rowIds);
                rowIds.clear();
            }
        }
    }
    if (rowIds.size() > 0) {
        LOG.info("map size: " + pairs.size());
        indexJsons(rowIds);
    }

}

From source file:com.exploringspatial.dao.impl.ConflictDaoImpl.java

@Override
public int reloadTableFromCsv(final String csvAbsoluteFilePath) {
    try {//from   www . ja v  a 2 s  .c  om
        assert (!csvAbsoluteFilePath.isEmpty());
        jdbcTemplate.update("TRUNCATE TABLE CONFLICT");
        final int batchSize = 1000;
        final List<Conflict> conflicts = jdbcTemplate.query(
                "SELECT * FROM CSVREAD('".concat(csvAbsoluteFilePath).concat("')"), new ConflictRowMapper());
        final List<Conflict> batch = new ArrayList<Conflict>(batchSize);
        for (Conflict conflict : conflicts) {
            batch.add(conflict);
            if (batch.size() == batchSize) {
                batchUpdate(batch);
                batch.clear();
            }
        }
        if (!batch.isEmpty()) {
            batchUpdate(batch);
            batch.clear();
        }
        return conflicts.size();
    } catch (Exception e) {
        throw new RuntimeException("Could not load " + csvAbsoluteFilePath, e);
    }
}

From source file:com.jaspersoft.studio.server.wizard.find.FindResourcePage.java

private void setTypes() {
    List<String> tps = finderUI.getTypes();
    tps.clear();
    for (Button b : typesMap.values())
        if (b.getSelection())
            tps.add(typesMap.inverse().get(b));
}

From source file:hoot.services.osm.OsmTestUtils.java

public static Set<Long> createTestRelationsNoWays(final long changesetId, final Set<Long> nodeIds)
        throws Exception {
    Set<Long> relationIds = new LinkedHashSet<Long>();
    final Long[] nodeIdsArr = nodeIds.toArray(new Long[] {});
    Map<String, String> tags = new HashMap<String, String>();
    List<RelationMember> members = new ArrayList<RelationMember>();

    members.add(new RelationMember(nodeIdsArr[0], ElementType.Node, "role1"));
    members.add(new RelationMember(nodeIdsArr[2], ElementType.Node));
    tags.put("key 1", "val 1");
    final long firstRelationId = Relation.insertNew(changesetId, mapId, members, tags, conn);
    relationIds.add(firstRelationId);//from   ww w.j  a v a 2s  .  c o m
    tags.clear();
    members.clear();

    tags.put("key 2", "val 2");
    tags.put("key 3", "val 3");
    members.add(new RelationMember(nodeIdsArr[4], ElementType.Node, "role1"));
    members.add(new RelationMember(firstRelationId, ElementType.Relation, "role1"));
    relationIds.add(Relation.insertNew(changesetId, mapId, members, tags, conn));
    tags.clear();
    members.clear();

    tags.put("key 4", "val 4");
    members.add(new RelationMember(nodeIdsArr[2], ElementType.Node, "role1"));
    relationIds.add(Relation.insertNew(changesetId, mapId, members, tags, conn));
    tags.clear();
    members.clear();

    return relationIds;
}