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.jongo.AggregateTest.java

@Test
public void canAggregateWithDefaultOptions() throws Exception {
    AggregationOptions options = AggregationOptions.builder().build();
    Iterable<Article> articles = collection.aggregate("{$match:{}}").options(options).as(Article.class);

    assertThat(articles.iterator().hasNext()).isTrue();
    for (Article article : articles) {
        assertThat(article.title).isIn("Zombie Panic", "Apocalypse Zombie", "World War Z");
    }//from  ww  w .  j  a v a  2  s .com
}

From source file:org.killbill.billing.plugin.adyen.dao.AdyenDao.java

private String getString(@Nullable final Iterable iterable) {
    if (iterable == null || !iterable.iterator().hasNext()) {
        return null;
    } else {//  ww w  . ja v  a2s  .co  m
        return JOINER.join(Iterables.transform(iterable, Functions.toStringFunction()));
    }
}

From source file:com.github.rvesse.airline.Accessor.java

public void addValues(Object commandInstance, Iterable<?> values) {
    if (!values.iterator().hasNext()) {
        return;/*from  w ww  . j  a  v a 2s.co  m*/
    }

    // get the actual instance
    Object instance = getValue(commandInstance);

    Field field = path.get(path.size() - 1);
    field.setAccessible(true);
    if (Collection.class.isAssignableFrom(field.getType())) {
        Collection<Object> collection = getOrCreateCollectionField(name, instance, field);
        CollectionUtils.addAll(collection, values);
    } else {
        try {
            field.set(instance, AirlineUtils.last(values));
        } catch (Exception e) {
            throw new ParseException(e, "Error setting %s for argument %s", field.getName(), name);
        }
    }

}

From source file:com.infinities.nova.servers.api.DaseinComputeTaskApi.java

@Override
public List<Server> buildInstances(OpenstackRequestContext context, CreateVmBaseOptions options, int num,
        Image bootMeta, String adminPassword, List<Entry<String, String>> injectedFiles,
        List<ServerForCreate.NetworkForCreate> requestedNetworks, List<String> securityGroups)
        throws CloudException, InternalException, ConcurrentException, InterruptedException,
        ExecutionException {//ww  w  .  jav a 2 s .  c  o m
    VMLaunchOptions withLaunchOptions = VMLaunchOptions.getInstance(options.getInstanceTypeId(),
            bootMeta.getId(), options.getDisplayName(), options.getDisplayDescription());
    String[] firewallIds = new String[securityGroups.size()];
    try {
        AsyncFirewallSupport firewallSupport = getNetworkSupport(context.getProjectId());
        Iterable<Firewall> iterable = firewallSupport.list().get();
        Iterator<Firewall> iterator = iterable.iterator();
        int i = 0;
        while (iterator.hasNext()) {
            Firewall firewall = iterator.next();
            if (securityGroups.contains(firewall.getName())) {
                firewallIds[i++] = firewall.getProviderFirewallId();
            }
        }
    } catch (UnsupportedOperationException e) {
        // ignore
    }

    withLaunchOptions.behindFirewalls(firewallIds);
    withLaunchOptions.withUserData(options.getUserData());
    withLaunchOptions.withBootstrapKey(options.getKeyName());
    Map<String, Object> metadata = new HashMap<String, Object>();
    for (String key : options.getMetadata().keySet()) {
        metadata.put(key, options.getMetadata().get(key));
    }
    withLaunchOptions.withMetaData(metadata);
    if (requestedNetworks != null && !requestedNetworks.isEmpty()) {
        withLaunchOptions.inSubnet(null, null, requestedNetworks.get(0).getId(), null);
    }
    Iterable<String> ids = getSupport(context.getProjectId()).launchMany(withLaunchOptions, num).get();
    return provisionInstances(context, options, ids);
}

From source file:corner.orm.hibernate.impl.PaginatedEntityService.java

License:asdf

public long count(final Class<?> persistClass, final Object conditions) {
    return (Long) this.template.execute(new HibernateCallback() {
        /**/*w  w  w  .  j  av  a 2 s.  c  o  m*/
         * @see org.springframework.orm.hibernate3.HibernateCallback#doInHibernate(org.hibernate.Session)
         */
        @Override
        public Object doInHibernate(Session session) throws HibernateException, SQLException {
            Iterable con = typeCoercer.coerce(conditions, Iterable.class);
            final Iterator it = con == null ? null : con.iterator();
            final StringBuffer sb = buildConditionHQL(persistClass, it);
            sb.insert(0, "select count(*) ");
            Query query = session.createQuery(sb.toString());
            if (it != null) {
                int i = 0;
                while (it.hasNext()) {
                    query.setParameter(i++, it.next());
                }
            }
            return query.iterate().next();
        }
    });
}

From source file:org.jongo.AggregateTest.java

@Test
public void canAggregateWithOptions() throws Exception {

    AggregationOptions options = spy(AggregationOptions.builder()
            .outputMode(AggregationOptions.OutputMode.CURSOR).allowDiskUse(true).build());

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

    assertThat(articles.iterator().hasNext()).isTrue();
    for (Article article : articles) {
        assertThat(article.title).isIn("Zombie Panic", "Apocalypse Zombie", "World War Z");
    }/*from www  .java 2  s.co m*/
    verify(options, atLeastOnce()).getAllowDiskUse();
    verify(options, atLeastOnce()).getMaxTime(any(TimeUnit.class));
    verify(options, atLeastOnce()).getBatchSize();
    verify(options, atLeastOnce()).getOutputMode();
}

From source file:com.infinities.nova.servers.api.DaseinComputeTaskApi.java

private List<Server> provisionInstances(OpenstackRequestContext context, CreateVmBaseOptions baseOptions,
        Iterable<String> ids) {
    List<Server> instances = new ArrayList<Server>();
    Iterator<String> iterator = ids.iterator();
    while (iterator.hasNext()) {
        String id = iterator.next();
        Server instance = new Server();
        // instance.setReservationId(baseOptions.getReservationId().toString());
        instance.setId(id);//  w  w w .  jav  a  2 s  . com
        com.infinities.nova.servers.model.Server.Image image = new com.infinities.nova.servers.model.Server.Image();
        image.setId(baseOptions.getImageRef());
        instance.setImage(image);
        instance.setConfigDrive(String.valueOf(baseOptions.isConfigDrive()));
        instance.setUserId(baseOptions.getUserId());
        instance.setTenantId(baseOptions.getProjectId());
        Flavor flavor = new Flavor();
        flavor.setId(baseOptions.getInstanceTypeId());
        instance.setFlavor(flavor);
        instance.setName(baseOptions.getDisplayName());
        instance.setKeyName(baseOptions.getKeyName());
        instance.setMetadata(baseOptions.getMetadata());
        instance.setAccessIPv4(baseOptions.getAccessIpV4());
        instance.setAccessIPv6(baseOptions.getAccessIpV6());
        instance.setAvailabilityZone(baseOptions.getAvailabilityZone());
        instances.add(instance);
    }
    return instances;
}

From source file:org.neo4j.ogm.drivers.http.driver.HttpDriver.java

@Override
public Transaction newTransaction(Transaction.Type type, Iterable<String> bookmarks) {
    if (bookmarks != null && bookmarks.iterator().hasNext()) {
        LOGGER.warn("Passing bookmarks {} to HttpDriver. This is not currently supported.", bookmarks);
    }//from  w w w .  jav  a2s. c  o m
    return new HttpTransaction(transactionManager, this, newTransactionUrl(type), type);
}

From source file:hudson.widgets.HistoryWidget.java

private List<HistoryPageEntry<T>> toPageEntries(Iterable<T> historyItemList) {
    Iterator<T> iterator = historyItemList.iterator();

    if (!iterator.hasNext()) {
        return Collections.EMPTY_LIST;
    }/*from   ww w  .  ja  va2 s  .c  o m*/

    List<HistoryPageEntry<T>> pageEntries = new ArrayList<HistoryPageEntry<T>>();
    while (iterator.hasNext()) {
        pageEntries.add(new HistoryPageEntry<T>(iterator.next()));
    }

    return pageEntries;
}