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.openbaton.vnfm.core.MediaServerManagement.java

public void delete(String mediaServerId) throws NotFoundException {
    log.debug("Removing MediaServer with id: " + mediaServerId);
    MediaServer mediaServer = mediaServerRepository.findOne(mediaServerId);
    if (mediaServer == null) {
        throw new NotFoundException("Not found MediaServer with id: " + mediaServerId);
    }//from www  .  j  a v  a 2s.  c  om
    Iterable<Application> appsIterable = applicationRepository.findAppByMediaServerId(mediaServerId);
    if (appsIterable.iterator().hasNext()) {
        log.warn("Removing MediaServer with id: " + mediaServerId
                + " but there are still running Applications: " + fromIterbaleToSet(appsIterable));
        applicationRepository.delete(appsIterable);
    }
    mediaServerRepository.delete(mediaServer);
    log.debug("Removed MediaServer with id: " + mediaServerId);
}

From source file:fr.landel.utils.commons.StringUtils.java

/**
 * <p>// w ww  .j  ava2  s.  c  o  m
 * Joins the elements of the provided {@code Iterable} into a single String
 * containing the provided elements.
 * </p>
 *
 * <p>
 * No delimiter is added before or after the list. The comma followed by a
 * space is used as separator (", ").
 * </p>
 *
 * <p>
 * See the examples here: {@link #join(Iterable, String)}.
 * </p>
 *
 * @param iterable
 *            the {@link Iterable} providing the values to join together,
 *            may be null
 * @param <T>
 *            the type of each element
 * @return the joined String, {@code null} if null iterator input
 */
public static <T> String joinComma(final Iterable<T> iterable) {
    if (iterable == null) {
        return null;
    }
    return joinComma(iterable.iterator());
}

From source file:corner.orm.gae.impl.PaginatedJapEntityService.java

License:asdf

public Iterator find(final Class<?> persistClass, final Object conditions, final String order, final int start,
        final int offset) {
    return (Iterator) this.template.execute(new JpaCallback() {
        @Override//from   www  .  ja  v a2  s  .  co  m
        public Object doInJpa(EntityManager entityManager) throws PersistenceException {
            Iterable con = typeCoercer.coerce(conditions, Iterable.class);
            final Iterator it = con == null ? null : con.iterator();
            final StringBuffer sb = buildConditionJPQL(persistClass, it);
            appendOrder(sb, order);
            sb.insert(0, "select root." + EntityConstants.ID_PROPERTY_NAME);
            Query query = entityManager.createQuery(sb.toString());
            if (it != null) {
                int i = 0;
                while (it.hasNext()) {
                    query.setParameter(String.valueOf(++i), it.next());
                }
            }
            query.setFirstResult(start);
            query.setMaxResults(offset);
            return query.getResultList().iterator();
        }
    });
}

From source file:com.shigengyu.hyperion.core.WorkflowStateSet.java

public WorkflowStateSet merge(final Iterable<WorkflowState> workflowStates) {
    if (workflowStates == null || !workflowStates.iterator().hasNext()) {
        return this;
    }//from   w  ww .  j  a va  2s  .c  om

    Set<WorkflowState> states = Sets.newHashSet(workflowStates);
    for (final WorkflowState workflowState : workflowStates) {
        if (workflowState != null) {
            states.add(workflowState);
        }
    }
    return new WorkflowStateSet(states);
}

From source file:edu.indiana.d2i.htrc.io.dataapi.IDRecorderReader.java

private Iterator<Entry<String, String>> generateID2ContentIterator() throws Exception {
    StringBuilder strBuilder = new StringBuilder();
    int count = 0;
    while (iditerator.hasNext() && count < maxIdRetrieved) {
        strBuilder.append(iditerator.next() + delimitor);
        count++;/*from   w w w  .j  a v a  2  s  .co  m*/
    }

    if (strBuilder.length() > 0) {
        Iterable<Entry<String, String>> content = dataClient.getID2Content(strBuilder.toString());
        if (content != null) {
            return content.iterator();
        } else {
            logger.info("content is null!!! " + strBuilder.toString());
            logger.info("numIdProcessed: " + numIdProcessed + ", remained: "
                    + (split.getLength() - numIdProcessed));
            return null;
        }

    } else {
        logger.info("strBuilder.length() " + strBuilder.length());
        logger.info(
                "numIdProcessed: " + numIdProcessed + ", remained: " + (split.getLength() - numIdProcessed));
        return null;
    }
}

From source file:org.openbaton.vnfm.core.MediaServerManagement.java

public void delete(String vnfrId, String hostname) throws NotFoundException {
    log.debug("Removing MediaServer with hostname: " + hostname);
    MediaServer mediaServer = mediaServerRepository.findByHostName(vnfrId, hostname);
    if (mediaServer == null) {
        throw new NotFoundException(
                "Not found MediaServer with hostname: " + hostname + " on VNFR with id: " + vnfrId);
    }/*from w ww .  jav  a  2s.  c om*/
    Iterable<Application> appsIterable = applicationRepository.findAppByMediaServerId(mediaServer.getId());
    if (appsIterable.iterator().hasNext()) {
        log.warn("Removing MediaServer with hostname: " + hostname
                + " but there are still running Applications: " + fromIterbaleToSet(appsIterable));
        applicationRepository.delete(appsIterable);
    }
    mediaServerRepository.delete(mediaServer);
    log.debug("Removed MediaServer with hostname: " + hostname);
}

From source file:com.google.code.polymate.CRUDTests.java

@Test
public void testFindCustomerWithOrder() {
    int numberOfOrders = 1;

    Customer customer = new Customer();
    customer.setName("Test Customer");

    Order order = new Order();
    order.setOrderNumber("Order_1337");

    customer.getOrders().add(order);//from   w w w. j  a v  a  2 s.  c o  m

    assertNotNull(polymate.save(customer));

    Iterable<Customer> customers = polymate.find(Customer.class);
    assertNotNull(customers);
    Customer currCustomer = customers.iterator().next();
    List<Order> orders = currCustomer.getOrders();
    assertNotNull(orders);
    Long start = System.currentTimeMillis();
    assertEquals(numberOfOrders, orders.size());
    System.out.println("Took: " + (System.currentTimeMillis() - start));
    Order actualOrder = orders.get(0);
    assertNotNull(actualOrder);
    assertEquals(order.getOrderNumber(), actualOrder.getOrderNumber());
}

From source file:com.infinities.nova.servers.volumes.api.DaseinVolumeAttachmentsApi.java

@Override
public List<VolumeAttachment> getVolumeAttachments(OpenstackRequestContext context, String projectId,
        String serverId) throws Exception {
    if (context == null) {
        context = Context.getAdminContext("no");
    }//w  w  w .  j a v a 2 s  .  c  om

    AsyncResult<Iterable<Volume>> result = this.getSupport(context.getProjectId())
            .listVolumes(VolumeFilterOptions.getInstance().attachedTo(serverId));
    Iterable<Volume> iterable = result.get();
    List<VolumeAttachment> volumeAttachments = new ArrayList<VolumeAttachment>();
    Iterator<Volume> iterator = iterable.iterator();
    while (iterator.hasNext()) {
        Volume volume = iterator.next();
        volumeAttachments.add(toVolumeAttachments(volume));
    }
    return volumeAttachments;
}

From source file:com.github.helenusdriver.commons.collections.iterators.SnapshotIterator.java

/**
 * Instantiates a new <code>SnapshotIterator</code> object.
 *
 * @author paouelle/* w  w  w  .  j  a v  a  2 s .  c om*/
 *
 * @param  i the iterable object to snapshot it's iterator
 * @throws NullPointerException if <code>i</code> is <code>null</code>
 */
public SnapshotIterator(Iterable<T> i) {
    this(i.iterator());
}

From source file:org.jongo.AggregateTest.java

@Test
public void canAggregateWithMultipleDocuments() throws Exception {

    Iterable<Article> articles = collection.aggregate("{$match:{tags:'virus'}}").as(Article.class);

    assertThat(articles.iterator().hasNext()).isTrue();
    int size = 0;
    for (Article article : articles) {
        assertThat(article.tags).contains("virus");
        size++;// w  w w.j  a  va2  s.c  o m
    }
    assertThat(size).isEqualTo(2);
}