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:co.cask.tigon.cli.DistributedFlowOperations.java

@Override
public void addLogHandler(String flowName, PrintStream out) {
    try {//from  ww w.j  a va 2s  .co  m
        Iterable<TwillController> iterable = lookupFlow(flowName);
        if (iterable.iterator().hasNext()) {
            TwillController controller = iterable.iterator().next();
            controller.addLogHandler(new PrinterLogHandler(new PrintWriter(out, true)));
        }
    } catch (Exception e) {
        LOG.warn(e.getMessage(), e);
    }
}

From source file:com.infinities.nova.snapshots.api.DaseinSnapshotsApi.java

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

    AsyncResult<Iterable<org.dasein.cloud.compute.Snapshot>> result = this.getSupport(context.getProjectId())
            .listSnapshots();

    Iterable<org.dasein.cloud.compute.Snapshot> iterable = result.get();
    List<Snapshot> snapshots = new ArrayList<Snapshot>();
    Iterator<org.dasein.cloud.compute.Snapshot> iterator = iterable.iterator();
    while (iterator.hasNext()) {
        org.dasein.cloud.compute.Snapshot snapshot = iterator.next();
        snapshots.add(toSnapshot(snapshot));
    }
    return snapshots;
}

From source file:com.jameswolfeoliver.pigeon.Server.ChatServer.java

private void send(final String body, final String address, final long messageDate) {
    helperThread.submit(() -> {/*  w  w w.  j ava 2  s.  c om*/
        try {
            Contact contact = ContactCacheManager.getInstance().updateNow().getContact(Long.parseLong(address));
            Message message = new Message();
            message.setAddress(Long.parseLong(address));
            message.setContact(contact);
            message.setBody(escapeHtml4(body));
            message.setDate(messageDate);

            int threadId = -1;
            Conversation conversation = null;

            try {
                Iterable<Integer> threadIterable = threadWrapper.find(() -> address).toBlocking().toIterable();
                Iterator<Integer> threadIds = threadIterable.iterator();
                while (threadIds.hasNext())
                    threadId = threadIds.next();

                final int finalThreadId = threadId;
                if (finalThreadId == -1)
                    throw new NoSuchElementException("threadId not found");

                Iterable<Conversation> conversationIterable = conversationWrapper
                        .find(() -> conversationWrapper.selectByThread(finalThreadId)).toBlocking()
                        .toIterable();
                Iterator<Conversation> conversations = conversationIterable.iterator();
                while (conversations.hasNext())
                    conversation = conversations.next();

                if (conversation == null)
                    throw new NoSuchElementException("conversation for threadId not found");
                message.setConversation(conversation);
            } catch (NoSuchElementException e) {
                Log.e(LOG_TAG, "Couldn't find conversation for address: " + address, e);
            }

            synchronized (chatWebSocket) {
                chatWebSocket.send(PigeonApplication.getGson().toJson(message));
            }
        } catch (Exception e) {
            Log.e(LOG_TAG, "ChatWebSocket failed to send: " + body, e);
        }
    });
}

From source file:com.github.rvesse.airline.parser.AbstractCommandParser.java

/**
 * Tries to parse the arguments//w w  w.jav a2  s  . co  m
 * 
 * @param parserConfig
 *            Parser Configuration
 * @param command
 *            Command meta-data
 * @param args
 *            Arguments
 * @return Parser State
 */
protected ParseState<T> tryParse(ParserMetadata<T> parserConfig, CommandMetadata command,
        Iterable<String> args) {
    PeekingIterator<String> tokens = new PeekingIterator<String>(args.iterator());
    //@formatter:off
    ParseState<T> state = ParseState.<T>newInstance().pushContext(Context.GLOBAL)
            .withConfiguration(parserConfig).withCommand(command).pushContext(Context.COMMAND);
    //@formatter:off

    state = parseCommandOptionsAndArguments(tokens, state, command);
    return state;
}

From source file:com.github.rvesse.airline.parser.command.SingleCommandParser.java

public T parse(ParserMetadata<T> parserConfig, CommandMetadata commandMetadata,
        Iterable<GlobalRestriction> restrictions, Iterable<String> args) {
    if (args == null)
        throw new NullPointerException("args is null");

    ParseState<T> state = tryParse(parserConfig, commandMetadata, args);
    validate(state, IteratorUtils.toList(restrictions.iterator()));

    CommandMetadata command = state.getCommand();

    //@formatter:off
    return createInstance(command.getType(), command.getAllOptions(), state.getParsedOptions(),
            command.getArguments(), state.getParsedArguments(), command.getMetadataInjections(),
            Collections.<Class<?>, Object>unmodifiableMap(
                    AirlineUtils.singletonMap(CommandMetadata.class, commandMetadata)),
            state.getParserConfiguration().getCommandFactory());
    //@formatter:on
}

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

@Test
public void testAddCustomer() {
    Long start = System.currentTimeMillis();
    Customer customer = new Customer();
    customer.setName("Test Customer");
    assertNotNull(polymate.save(customer));
    System.out.println("Took: " + (System.currentTimeMillis() - start));
    start = System.currentTimeMillis();
    Iterable<Customer> result = polymate.find(Customer.class);
    System.out.println("Took: " + (System.currentTimeMillis() - start));

    assertNotNull(result);//from w ww  . jav  a 2 s . c  o m
    assertTrue(result.iterator().hasNext());
    Customer customer2 = result.iterator().next();
    assertNotNull(customer2);
    assertEquals(customer.getName(), customer2.getName());
}

From source file:com.infinities.nova.servers.interfaces.api.DaseinInterfaceAttachmentsApi.java

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

    AsyncResult<Iterable<NetworkInterface>> result = this.getSupport(context.getProjectId())
            .listNetworkInterfacesForVM(serverId);
    Iterable<NetworkInterface> iterable = result.get();
    List<InterfaceAttachment> interfaceAttachments = new ArrayList<InterfaceAttachment>();
    Iterator<NetworkInterface> iterator = iterable.iterator();
    while (iterator.hasNext()) {
        NetworkInterface interfaceAttachment = iterator.next();
        interfaceAttachments.add(toInterfaceAttachment(interfaceAttachment));
    }
    return interfaceAttachments;
}

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

@Test
public void testAddAllCustomers() {
    List<Customer> customers = new ArrayList<Customer>();
    Long start = System.currentTimeMillis();
    for (int i = 1; i <= 10000; i++) {
        Customer customer = new Customer();
        customer.setName("Customer_" + i);
        customers.add(customer);// w ww  .  ja v  a2  s .  c  o m
    }
    polymate.saveAll(customers);
    System.out.println("Took: " + (System.currentTimeMillis() - start));
    start = System.currentTimeMillis();
    Iterable<Customer> result = polymate.find(Customer.class);
    System.out.println("Took: " + (System.currentTimeMillis() - start));

    assertNotNull(result);
    assertTrue(result.iterator().hasNext());
    Customer customer2 = result.iterator().next();
    assertNotNull(customer2);
}

From source file:com.simphony.managedbeans.AssociateBean.java

/**
 * Llenamos lista de agremiados//from  w ww. j  av a 2s  . c o  m
 */
private void fillAssociates() {
    list.clear();
    Iterable<Associate> c = this.service.getRepository().findAll(sortByKeyId());
    Iterator<Associate> cu = c.iterator();
    while (cu.hasNext()) {
        list.add(cu.next());
    }
    model = new AssociateModel(list);
}

From source file:com.github.rvesse.airline.parser.AbstractCommandParser.java

/**
 * Tries to parse the arguments//from   ww  w .  j  a  v a 2  s . c  o  m
 * 
 * @param metadata
 *            Global Metadata
 * @param args
 *            Arguments
 * @return Parser State
 */
protected ParseState<T> tryParse(GlobalMetadata<T> metadata, Iterable<String> args) {
    PeekingIterator<String> tokens = new PeekingIterator<String>(args.iterator());

    //@formatter:off
    ParseState<T> state = ParseState.<T>newInstance().pushContext(Context.GLOBAL).withGlobal(metadata);
    //@formatter:on

    // Parse global options
    state = parseOptions(tokens, state, metadata.getOptions());

    // Apply aliases
    tokens = applyAliases(tokens, state);

    // Parse group
    state = parseGroup(tokens, state);

    // parse command
    state = parseCommand(tokens, state);

    return state;
}