Example usage for java.lang Iterable iterator

List of usage examples for java.lang Iterable iterator

Introduction

In this page you can find the example usage for java.lang Iterable iterator.

Prototype

Iterator<T> iterator();

Source Link

Document

Returns an iterator over elements of type T .

Usage

From source file:org.vincibean.salestaxes.service.PoiuytServiceTest.java

/**
 * Test that, if no Poiuyt is saved, method findAllPoiuyts() will return a 
 * not null and empty list of Poiuyts./*from  w  ww  . ja  va  2s. c  o m*/
 */
@Test
public void testFindAllPoiuytsNoPoiuyt() {
    poiuytRepository.deleteAll();
    Iterable<Poiuyt> poiuyts = poiuytService.findAllPoiuyts();
    Assert.assertNotNull(poiuyts);
    Assert.assertFalse(poiuyts.iterator().hasNext());
}

From source file:com.splicemachine.orc.OrcTester.java

private static void assertFileContents(ObjectInspector objectInspector, TempFile tempFile,
        Iterable<?> expectedValues, boolean skipFirstBatch, boolean skipStripe, MetadataReader metadataReader,
        DataType type) throws IOException {
    OrcRecordReader recordReader = createCustomOrcRecordReader(tempFile, metadataReader, OrcPredicate.TRUE,
            type);// w w w  .  j  ava  2 s. c  o  m
    assertEquals(recordReader.getReaderPosition(), 0);
    assertEquals(recordReader.getFilePosition(), 0);

    boolean isFirst = true;
    int rowsProcessed = 0;
    Iterator<?> iterator = expectedValues.iterator();
    for (int batchSize = toIntExact(recordReader.nextBatch()); batchSize >= 0; batchSize = toIntExact(
            recordReader.nextBatch())) {
        if (skipStripe && rowsProcessed < 10000) {
            assertEquals(advance(iterator, batchSize), batchSize);
        } else if (skipFirstBatch && isFirst) {
            assertEquals(advance(iterator, batchSize), batchSize);
            isFirst = false;
        } else {
            ColumnVector vector = recordReader.readBlock(type, 0);
            ColumnBlock block = BlockFactory.getColumnBlock(vector, type);
            List<Object> data = new ArrayList<>(vector.getElementsAppended());
            for (int position = 0; position < vector.getElementsAppended(); position++) {
                data.add(block.getTestObject(position));
            }
            for (int i = 0; i < batchSize; i++) {
                assertTrue(iterator.hasNext());
                Object expected = iterator.next();
                Object actual = data.get(i);
                assertColumnValueEquals(type, actual, expected);
            }
        }
        assertEquals(recordReader.getReaderPosition(), rowsProcessed);
        assertEquals(recordReader.getFilePosition(), rowsProcessed);
        rowsProcessed += batchSize;
    }
    assertFalse(iterator.hasNext());

    assertEquals(recordReader.getReaderPosition(), rowsProcessed);
    assertEquals(recordReader.getFilePosition(), rowsProcessed);
    recordReader.close();
}

From source file:com.lyncode.jtwig.functions.builtin.ListFunctions.java

@JtwigFunction(name = "length")
public int length(@Parameter Iterable input) {
    Iterator iterator = input.iterator();
    int count = 0;
    while (iterator.hasNext()) {
        iterator.next();// ww w  . j  a va2s  .c  o m
        count++;
    }
    return count;
}

From source file:org.qi4j.library.http.JettyServiceTest.java

@Test
public final void testInstantiation() throws Throwable {
    Iterable<ServiceReference<JettyService>> services = module.findServices(JettyService.class);
    assertNotNull(services);//  ww w.ja  v a 2s  .c o  m

    Iterator<ServiceReference<JettyService>> iterator = services.iterator();
    assertTrue(iterator.hasNext());

    ServiceReference<JettyService> serviceRef = iterator.next();
    assertNotNull(serviceRef);

    JettyService jettyService = serviceRef.get();
    assertNotNull(jettyService);

    String output = defaultHttpClient.execute(new HttpGet("http://127.0.0.1:8041/helloWorld"),
            stringResponseHandler);
    assertEquals("Hello World", output);
}

From source file:com.magnet.android.mms.request.GenericRequestBodyMarshaller.java

protected void writeJsonFromPojoCollection(GsonStreamWriter gw, Object collObj, Class<?> bclass,
        String fieldName) throws MarshallingException {
    if (fieldName != null) {
        gw.writeFieldName(fieldName);/* w  ww .j  av  a  2 s  . co  m*/
    }
    if (collObj == null) { // write null
        gw.writeNullValue();
        return;
    }
    Iterable iterObj = Iterable.class.cast(collObj);
    final Iterator iter = iterObj.iterator();

    gw.beginArray();
    while (iter.hasNext()) {
        Object item = iter.next();
        if (item != null) {
            writeJsonFromPojo(gw, item, bclass);
        } else {
            gw.writeNullValue();
        }
    }
    gw.endArray();
}

From source file:com.veera.secondarysort.demo2.SsReducer.java

@Override
public void reduce(StockKey key, Iterable<DoubleWritable> values, Context context)
        throws IOException, InterruptedException {
    Text k = new Text(key.toString());
    int count = 0;

    Iterator<DoubleWritable> it = values.iterator();
    while (it.hasNext()) {
        Text v = new Text(it.next().toString());
        context.write(k, v);//from www . j ava 2  s  .  c  o m
        _log.debug(k.toString() + " => " + v.toString());
        count++;
    }

    _log.debug("count = " + count);
}

From source file:com.boundlessgeo.geoserver.json.JSONObj.java

@Override
void write(Writer out) throws IOException {
    //this.raw().writeJSONString(out);
    if (raw == null) {
        out.write("null");
    } else {/*from  w w  w.j av  a  2s  .c om*/
        boolean first = true;
        Iterable<String> keys = keys();
        Iterator<String> iter = keys.iterator();

        out.write('{');
        while (iter.hasNext()) {
            if (first) {
                first = false;
            } else {
                out.write(',');
            }
            String key = iter.next();
            Object value = raw.get(key);

            out.write('\"');
            out.write(JSONObject.escape(key));
            out.write('\"');
            out.write(':');
            JSONWrapper.write(value, out);
        }
        out.write('}');
    }
    out.flush();
}

From source file:org.openlmis.fulfillment.web.TemplateControllerIntegrationTest.java

@Test
public void shouldGetAllTemplates() {
    TemplateDto[] response = restAssured.given().header(HttpHeaders.AUTHORIZATION, getTokenHeader())
            .contentType(MediaType.APPLICATION_JSON_VALUE).when().get(RESOURCE_URL).then().statusCode(200)
            .extract().as(TemplateDto[].class);

    Iterable<TemplateDto> templates = Arrays.asList(response);
    assertTrue(templates.iterator().hasNext());
    assertThat(RAML_ASSERT_MESSAGE, restAssured.getLastReport(), RamlMatchers.hasNoViolations());
}

From source file:com.infinities.nova.keypairs.api.DaseinKeyPairsApi.java

@Override
public List<KeyPair> getKeyPairs(OpenstackRequestContext context, String userId) throws Exception {
    if (context == null) {
        context = Context.getAdminContext("no");
    }/*  w w  w.  j a  v  a  2 s . c  o m*/
    AsyncResult<Iterable<SSHKeypair>> result = getSupport(context.getProjectId()).list();
    Iterable<SSHKeypair> iterable = result.get();
    Iterator<SSHKeypair> iterator = iterable.iterator();

    List<KeyPair> keyPairs = new ArrayList<KeyPair>();
    while (iterator.hasNext()) {
        SSHKeypair sshKeyPair = iterator.next();
        keyPairs.add(toKeyPair(sshKeyPair));
    }

    return keyPairs;
}

From source file:thingynet.workflow.commands.WorkflowLoadTest.java

@Test
public void monitorLoadShouldRecordCorrectWorkflowCounts() throws WorkflowException {
    long start = currentTimeMillis();

    long count = workflowLoadCollection.count();
    assertThat(count, is(0l));//from w  ww .j  a v a  2 s  .c  om

    Workflow dependency = workflowService.createOnHoldNow(null, null, null);
    Workflow workflow = workflowService.createWorkflow(null, null, start, null, WAITING);
    workflow.getDependencies().add(dependency.getId());
    workflowService.saveChanges(workflow);
    workflowService.createWorkflow(null, null, start, null, WAITING);
    workflowService.createWorkflow(null, null, start + TEN_SECONDS, null, WAITING);
    workflowService.createWorkflow(null, null, start, null, PROCESSING);

    command.execute(null);

    Iterable<WorkflowLoad> loads = workflowLoadCollection.find().as(WorkflowLoad.class);
    assertThat(loads, notNullValue());
    WorkflowLoad workflowLoad = loads.iterator().next();
    assertThat(workflowLoad, notNullValue());

    assertThat(workflowLoad.getCreated(), greaterThanOrEqualTo(start));
    assertThat(workflowLoad.getCreated(), lessThanOrEqualTo(currentTimeMillis()));
    assertThat(workflowLoad.getInitialising(), is(1l));
    assertThat(workflowLoad.getProcessing(), is(1l));
    assertThat(workflowLoad.getWaitingFutureStart(), is(1l));
    assertThat(workflowLoad.getWaitingNoDependencies(), is(1l));
    assertThat(workflowLoad.getWaitingWithDependencies(), is(1l));
}