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:com.github.lucapino.jira.ReleaseVersionMojo.java

/**
 * Returns the latest unreleased version
 *
 * @return the new version to release.//from   ww w.java  2  s  . c  om
 */
private VersionHolder calculateReleaseVersion() {
    Project jiraProject = jiraClient.getRestClient().getProjectClient().getProject(jiraProjectKey).claim();
    Iterable<Version> versions = jiraProject.getVersions();

    List<Version> versionList = IteratorUtils.toList(versions.iterator());
    Collections.sort(versionList, remoteVersionComparator);

    VersionHolder holder = null;
    VersionInput version;
    for (Version remoteVersion : versions) {
        // if we don't want auto discover -> we use provided releaseVersion
        if (!autoDiscoverLatestRelease && !remoteVersion.isReleased()
                && remoteVersion.getName().equals(releaseVersion)) {
            version = new VersionInput(jiraProjectKey, releaseVersion, null, new DateTime(), false, true);
            holder = new VersionHolder(version, remoteVersion.getSelf());
            break;
        } else {
            // else get first unreleased version ??
            if (autoDiscoverLatestRelease && !remoteVersion.isReleased()) {
                version = new VersionInput(jiraProjectKey, remoteVersion.getName(), null, new DateTime(), false,
                        true);
                holder = new VersionHolder(version, remoteVersion.getSelf());
                break;
            }
        }
    }
    return holder;
}

From source file:com.infinities.nova.networks.api.DaseinNetworksApi.java

@Override
public List<Network> getNetworks(OpenstackRequestContext context, String projectId) throws Exception {
    if (context == null) {
        context = Context.getAdminContext("no");
    }/*  w  ww  .  j a  v a 2  s  .com*/
    AsyncResult<Iterable<VLAN>> result = getSupport(context.getProjectId()).listVlans();
    Iterable<VLAN> iterable = result.get();
    Iterator<VLAN> iterator = iterable.iterator();

    List<Network> networks = new ArrayList<Network>();
    while (iterator.hasNext()) {
        VLAN vlan = iterator.next();
        networks.add(toNetwork(vlan));
    }

    return networks;
}

From source file:de.msg.repository.RouteRepositoryImplJpaTest.java

@Test
public void findByDestination() throws Exception {
    Iterable<Route> actual = repository.findByDestination("IAH");
    Assert.assertEquals("IAH", actual.iterator().next().getDestination());
}

From source file:edu.pitt.dbmi.ccd.anno.vocabulary.VocabularyResourceAssembler.java

/**
 * convert Vocabularies to VocabularyResources
 *
 * @param vocabularies entities//w  w w.j  a  va 2s . com
 * @return List of resources
 */
@Override
public List<VocabularyResource> toResources(Iterable<? extends Vocabulary> vocabularies)
        throws IllegalArgumentException {
    // Assert vocabularies is not empty
    Assert.isTrue(vocabularies.iterator().hasNext());
    return StreamSupport.stream(vocabularies.spliterator(), false).map(this::toResource)
            .collect(Collectors.toList());
}

From source file:edu.pitt.dbmi.ccd.anno.data.AnnotationTargetResourceAssembler.java

/**
 * convert AnnotationTargets to AnnotationTargetResources
 *
 * @param targets entities/*from   w w w .  j a  v a2  s .  c om*/
 * @return List of resources
 */
@Override
public List<AnnotationTargetResource> toResources(Iterable<? extends AnnotationTarget> targets)
        throws IllegalArgumentException {
    // Assert targets is not empty
    Assert.isTrue(targets.iterator().hasNext());
    return StreamSupport.stream(targets.spliterator(), false).map(this::toResource)
            .collect(Collectors.toList());
}

From source file:thingynet.workflow.WorkflowLatencyTest.java

@Test
public void excuteShouldRecordCorrectLatency() throws WorkflowException {
    long count = workflowLogCollection.count();
    assertThat(count, is(0l));// www  .  ja v  a 2  s  .com

    Workflow workflow = new Workflow(null, null, null, currentTimeMillis(), null);
    workflow.setUpdated(workflow.getStart() + EXPECTED_LATENCY);

    command.execute(workflow);

    Iterable<WorkflowLatency> loads = workflowLogCollection.find().as(WorkflowLatency.class);
    assertThat(loads, notNullValue());
    WorkflowLatency workflowLatency = loads.iterator().next();
    assertThat(workflowLatency, notNullValue());
    assertThat(workflowLatency.getLatency(), is(EXPECTED_LATENCY));
}

From source file:de.msg.repository.RouteRepositoryImplJpaTest.java

@Test
public void queryFindByDeparture() throws Exception {
    Iterable<Route> actual = repository.queryFindByDeparture("MUC");
    Assert.assertEquals("MUC", actual.iterator().next().getDeparture());
}

From source file:com.spectralogic.ds3cli.command.VerifyBulkJob.java

@Override
public VerifyBulkJobResult call() throws Exception {
    try {//from ww w.  j  a v a 2s.c  o m
        // Generate the list of Ds3Objects to verify
        final Ds3ClientHelpers helper = getClientHelpers();
        final Iterable<Contents> bulkContents = helper.listObjects(this.bucketName, this.prefix);
        if (bulkContents == null || !bulkContents.iterator().hasNext()) {
            throw new CommandException(
                    "No objects in bucket '" + this.bucketName + "' with prefix '" + this.prefix + "'");
        }

        // copy Contents list into a Ds3Objects list
        final List<Ds3Object> objectList = new ArrayList<>();
        for (final Contents contents : bulkContents) {
            objectList.add(new Ds3Object(contents.getKey(), contents.getSize()));
        }

        // Make verify call to API
        final VerifyBulkJobSpectraS3Request request = new VerifyBulkJobSpectraS3Request(this.bucketName,
                objectList);
        if (this.priority != null) {
            request.withPriority(priority);
        }

        final VerifyBulkJobSpectraS3Response verifyResponse = getClient().verifyBulkJobSpectraS3(request);

        return new VerifyBulkJobResult(this.bucketName,
                verifyResponse.getMasterObjectListResult().getObjects().iterator());
    } catch (final FailedRequestException e) {
        if (e.getStatusCode() == 404) {
            throw new CommandException("Cannot locate bucket: " + this.bucketName, e);
        }
        throw e;
    }
}

From source file:gemfire.practice.service.DefaultCustomerService.java

/**
 * Return all customers//from w w  w .  j  ava  2  s. com
 * 
 * @return
 */
@Override
public List<Customer> findAllCustomers() {
    Iterable<Customer> customersIterable = customerRepository.findAll();
    Iterator<Customer> iterator = customersIterable.iterator();
    List<Customer> customersList = new ArrayList<>();
    while (iterator.hasNext()) {
        customersList.add(iterator.next());
    }
    return customersList;
}

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

/**
 * Test that, once a valid Poiuyt is saved, method findAllPoiuyts() will return a 
 * not null and not empty list of Poiuyts.
 *//*from  ww  w. j a  v a  2s .c om*/
@Test
public void testFindAllPoiuyts() {
    poiuytRepository.save(createMockPoiuyt());
    Iterable<Poiuyt> poiuyts = poiuytService.findAllPoiuyts();
    Assert.assertNotNull(poiuyts);
    Assert.assertTrue(poiuyts.iterator().hasNext());
}