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:HashNMap.java

/**
 * Inserts a new key/value pair into the map. If such a pair already exists,
 * it gets replaced with the given values.
 * //from   w  w w .j  a v a 2s. com
 * @param key
 *          the key.
 * @param val
 *          the value.
 * @return A boolean.
 */
public boolean put(final Object key, final Object val) {
    final List v = (List) this.table.get(key);
    if (v == null) {
        final List newList = createList();
        newList.add(val);
        this.table.put(key, newList);
        return true;
    } else {
        v.clear();
        return v.add(val);
    }
}

From source file:com.microsoft.office.core.AbstractPrimitiveTest.java

private void checkPoligon(final Polygon polygon, final List<Point> checkInterior,
        final List<Point> checkExterior) {

    final List<Point> points = new ArrayList<Point>();

    for (Point point : polygon.getInterior()) {
        points.add(point);//from  ww w .  j  a  v  a2 s . c  o m
    }

    assertEquals(checkInterior.size(), points.size());

    for (int i = 0; i < points.size(); i++) {
        checkPoint(checkInterior.get(i), points.get(i));
    }

    points.clear();

    for (Point point : polygon.getExterior()) {
        points.add(point);
    }

    assertEquals(checkExterior.size(), points.size());

    for (int i = 0; i < points.size(); i++) {
        checkPoint(checkExterior.get(i), points.get(i));
    }

}

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

public static Set<Long> createTestRelations(final long changesetId, final Set<Long> nodeIds,
        final Set<Long> wayIds) throws Exception {
    Set<Long> relationIds = new LinkedHashSet<Long>();
    final Long[] nodeIdsArr = nodeIds.toArray(new Long[] {});
    final Long[] wayIdsArr = wayIds.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(wayIdsArr[1], ElementType.Way, "role3"));
    members.add(new RelationMember(wayIdsArr[0], ElementType.Way, "role2"));
    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  w  w w .java  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(wayIdsArr[1], ElementType.Way));
    relationIds.add(Relation.insertNew(changesetId, mapId, members, tags, conn));
    tags.clear();
    members.clear();

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

    return relationIds;
}

From source file:io.cloudslang.engine.queue.repositories.ExecutionQueueRepositoryTest.java

@Test
public void testCountMessagesWithoutAckWithVersionForWorker() {
    List<ExecutionMessage> msg = new ArrayList<>();
    msg.add(generateMessageForWorker(1, "group1", "msg1", ExecutionMessage.EMPTY_WORKER, 1));
    msg.add(generateMessageForWorker(2, "group2", "msg2", "uuid2", 1));
    msg.add(generateMessageForWorker(3, "group3", "msg3", ExecutionMessage.EMPTY_WORKER, 1));
    executionQueueRepository.insertExecutionQueue(msg, 1L);

    msg.clear();
    msg.add(generateMessageForWorker(4, "group2", "msg2", ExecutionMessage.EMPTY_WORKER, 1));

    executionQueueRepository.insertExecutionQueue(msg, 4L);

    Integer result = executionQueueRepository.countMessagesWithoutAckForWorker(100, 3,
            ExecutionMessage.EMPTY_WORKER);
    Assert.assertEquals(result.intValue(), 2);

    result = executionQueueRepository.countMessagesWithoutAckForWorker(100, 3, "uuid2");
    Assert.assertEquals(result.intValue(), 1);
    result = executionQueueRepository.countMessagesWithoutAckForWorker(100, 3, "uuid3");
    Assert.assertEquals(result.intValue(), 0);
}

From source file:com.jhh.hdb.sqlparser.QBParseInfo.java

public void clearDistinctFuncExprsForClause(String clause) {
    List<ASTNode> l = destToDistinctFuncExprs.get(clause);
    if (l != null) {
        l.clear();
    }/* ww  w  .ja  v  a 2s.c o m*/
}

From source file:io.hops.erasure_coding.StripeReader.java

/**
 * Builds (codec.stripeLength + codec.parityLength) inputs given some erased
 * locations./*ww  w .  j a va2 s .  c  o m*/
 * Outputs:
 * - the array of input streams @param inputs
 * - the list of erased locations @param erasedLocations.
 * - the list of locations that are not read @param locationsToNotRead.
 */
public InputStream[] buildInputs(FileSystem srcFs, Path srcFile, FileStatus srcStat, FileSystem parityFs,
        Path parityFile, FileStatus parityStat, int stripeIdx, long offsetInBlock,
        List<Integer> erasedLocations, List<Integer> locationsToRead, ErasureCode code) throws IOException {
    InputStream[] inputs = new InputStream[codec.stripeLength + codec.parityLength];
    boolean redo = false;
    do {
        /*
         * In the first iteration locationsToRead is empty.
         * It is populated according to locationsToReadForDecode.
         * In consecutive iterations (if a stream failed to open)
         * the list is cleared and re-populated.
         */
        locationsToRead.clear();
        locationsToRead.addAll(code.locationsToReadForDecode(erasedLocations));

        for (int i = 0; i < inputs.length; i++) {
            boolean isErased = (erasedLocations.indexOf(i) != -1);
            boolean shouldRead = (locationsToRead.indexOf(i) != -1);
            try {
                InputStream stm = null;
                if (isErased || !shouldRead) {
                    if (isErased) {
                        LOG.info("Location " + i + " is erased, using zeros");
                    } else {
                        LOG.info("Location " + i + " need not be read, using zeros");
                    }

                    stm = new RaidUtils.ZeroInputStream(srcStat.getBlockSize()
                            * ((i < codec.parityLength) ? stripeIdx * codec.parityLength + i
                                    : stripeIdx * codec.stripeLength + i - codec.parityLength));
                } else {
                    stm = buildOneInput(i, offsetInBlock, srcFs, srcFile, srcStat, parityFs, parityFile,
                            parityStat);
                }
                inputs[i] = stm;
            } catch (IOException e) {
                if (e instanceof BlockMissingException || e instanceof ChecksumException) {
                    erasedLocations.add(i);
                    redo = true;
                    RaidUtils.closeStreams(inputs);
                    break;
                } else {
                    throw e;
                }
            }
        }
    } while (redo);
    return inputs;
}

From source file:com.liato.bankdroid.banking.banks.CSN.java

@Override
protected LoginPackage preLogin() throws BankException, ClientProtocolException, IOException {
    urlopen = new Urllib(context, CertificateReader.getCertificates(context, R.raw.cert_csn));
    urlopen.setAllowCircularRedirects(true);
    urlopen.setContentCharset(HTTP.ISO_8859_1);
    urlopen.addHeader("Referer", "https://www.csn.se/bas/");
    response = urlopen.open("https://www.csn.se/bas/inloggning/pinkod.do");
    List<NameValuePair> postData = new ArrayList<NameValuePair>();
    postData.add(new BasicNameValuePair("javascript", "on"));
    try {/*from   w ww.  j  av a 2  s . co  m*/
        response = urlopen.open("https://www.csn.se/bas/javascript", postData);
    } catch (ClientProtocolException e) {
        throw new BankException("pl:CPE:" + e.getMessage());
    } catch (IOException e) {
        throw new BankException("pl:IOE:" + e.getMessage());
    }
    postData.clear();

    postData.add(new BasicNameValuePair("metod", "validerapinkod"));
    postData.add(new BasicNameValuePair("pnr", username));
    postData.add(new BasicNameValuePair("pinkod", password));
    return new LoginPackage(urlopen, postData, response, "https://www.csn.se/bas/inloggning/Pinkod.do");
}

From source file:io.cloudslang.engine.queue.services.ExecutionQueueServiceTest.java

@Test
public void pollWithoutAckTestMixMsg() throws Exception {
    Multimap<String, String> groupWorkerMap = ArrayListMultimap.create();
    groupWorkerMap.put("group1", "worker1");
    groupWorkerMap.put("group1", "worker2");
    when(workerNodeService.readGroupWorkersMapActiveAndRunningAndVersion("")).thenReturn(groupWorkerMap);
    when(busyWorkersService.isWorkerBusy("worker1")).thenReturn(true);
    when(busyWorkersService.isWorkerBusy("worker1")).thenReturn(true);
    List<ExecutionMessage> msgInQueue = executionQueueService.pollMessagesWithoutAck(100, 0);
    Assert.assertEquals(0, msgInQueue.size());

    ExecutionMessage message1 = generateMessage("group1", "5"); //this msg will get 0 version
    message1.setWorkerId("worker1");
    message1.setStatus(ExecStatus.SENT);

    msgInQueue.clear();
    msgInQueue.add(message1);//from  ww  w.j  av  a 2s  .  c om

    when(versionService.getCurrentVersion(anyString())).thenReturn(0L);

    executionQueueService.enqueue(msgInQueue);

    ExecutionMessage message2 = generateMessage("group1", "5"); //this msg will get 100 version
    message2.setWorkerId("worker2");
    message2.setStatus(ExecStatus.SENT);

    msgInQueue.clear();
    msgInQueue.add(message2);
    when(versionService.getCurrentVersion(anyString())).thenReturn(100L);

    executionQueueService.enqueue(msgInQueue);

    msgInQueue = executionQueueService.pollMessagesWithoutAck(100, 100);
    Assert.assertEquals("only one msg should be with version to far from system version", 1, msgInQueue.size());
    Assert.assertEquals("worker1", msgInQueue.get(0).getWorkerId());
}

From source file:fi.vm.sade.organisaatio.service.search.OrganisaatioSearchService.java

private SolrQuery createOrgQuery(final SearchCriteria searchCriteria, final List<String> kunta,
        final List<String> restrictionList, final String organisaatioTyyppi, final List<String> kieli,
        String searchStr, String oid) {
    SolrQuery q = new SolrQuery("*:*");
    final List<String> queryParts = Lists.newArrayList();

    if (oid != null && !oid.isEmpty()) {
        q.addFilterQuery(String.format("%s:%s", OID, oid));
    } else if (searchStr != null && searchStr.length() > 0) {
        // nimi/* w  ww .j av a 2s  .c  o  m*/
        searchStr = escape(searchStr);
        // nimi search
        queryParts.clear();
        addQuery(searchStr, queryParts, "%s:*%s*", NIMISEARCH, searchStr);
        q.addFilterQuery(Joiner.on(" ").join(queryParts));

    }

    addDateFilters(searchCriteria, q);

    if (searchCriteria.getOppilaitosTyyppi() != null && searchCriteria.getOppilaitosTyyppi().size() > 0) {
        // filter based on oppilaitosTyyppi list
        q.addFilterQuery(String.format("%s:(%s)", OPPILAITOSTYYPPI,
                Joiner.on(" ").join(searchCriteria.getOppilaitosTyyppi())));
    }

    // kunta
    if (kunta != null && kunta.size() > 0) {
        // filter based on kunta list
        q.addFilterQuery(String.format("+%s:(%s)", KUNTA, Joiner.on(" ").join(kunta)));
    }
    // organisaatiotyyppi
    queryParts.clear();
    addQuery(organisaatioTyyppi, queryParts, "{!term f=%s}%s", ORGANISAATIOTYYPPI, organisaatioTyyppi);
    if (queryParts.size() > 0) {
        q.addFilterQuery(Joiner.on(" ").join(queryParts));
    }
    // kieli
    if (kieli != null && kieli.size() > 0) {
        // filter based on kieli list
        q.addFilterQuery(String.format("%s:(%s)", KIELI, Joiner.on(" ").join(kieli)));
    }

    if (restrictionList.size() > 0) {
        // filter based on restriction list
        q.addFilterQuery(String.format("%s:(%s)", PATH, Joiner.on(" ").join(restrictionList)));
    }
    // also filter out oph (TODO do not index oph)
    q.addFilterQuery(String.format("-%s:%s", OID, rootOrganisaatioOid));
    return q;
}

From source file:com.google.cloud.bigtable.hbase.TestBatch.java

/**
 * Requirement 8.1//from  w  w  w .j  ava2  s . c o m
 */
@Test
public void testBatchAppend() throws IOException, InterruptedException {
    // Initialize data
    Table table = getConnection().getTable(TABLE_NAME);
    byte[] rowKey1 = dataHelper.randomData("testrow-");
    byte[] qual1 = dataHelper.randomData("qual-");
    byte[] value1_1 = dataHelper.randomData("value-");
    byte[] value1_2 = dataHelper.randomData("value-");
    byte[] rowKey2 = dataHelper.randomData("testrow-");
    byte[] qual2 = dataHelper.randomData("qual-");
    byte[] value2_1 = dataHelper.randomData("value-");
    byte[] value2_2 = dataHelper.randomData("value-");

    // Put
    Put put1 = new Put(rowKey1).addColumn(COLUMN_FAMILY, qual1, value1_1);
    Put put2 = new Put(rowKey2).addColumn(COLUMN_FAMILY, qual2, value2_1);
    List<Row> batch = new ArrayList<Row>(2);
    batch.add(put1);
    batch.add(put2);
    table.batch(batch, null);

    // Increment
    Append append1 = new Append(rowKey1).add(COLUMN_FAMILY, qual1, value1_2);
    Append append2 = new Append(rowKey2).add(COLUMN_FAMILY, qual2, value2_2);
    batch.clear();
    batch.add(append1);
    batch.add(append2);
    Object[] results = new Object[2];
    table.batch(batch, results);
    Assert.assertArrayEquals("Should be value1_1 + value1_2", ArrayUtils.addAll(value1_1, value1_2),
            CellUtil.cloneValue(((Result) results[0]).getColumnLatestCell(COLUMN_FAMILY, qual1)));
    Assert.assertArrayEquals("Should be value1_1 + value1_2", ArrayUtils.addAll(value2_1, value2_2),
            CellUtil.cloneValue(((Result) results[1]).getColumnLatestCell(COLUMN_FAMILY, qual2)));

    table.close();
}