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:se.inera.axel.shs.broker.messagestore.internal.MongoMessageLogAdminServiceIT.java

@Test
public void findMessagesByState() throws Exception {

    MessageState STATE_TERM = MessageState.RECEIVED;
    MessageLogAdminService.Filter filter = new MessageLogAdminService.Filter();
    filter.setState(STATE_TERM);//from  w  w w .  j a  v a 2s . c  o  m

    Iterable<ShsMessageEntry> results = messageLogAdminService.findMessages(filter);
    Assert.assertNotNull(results);
    Assert.assertTrue(results.iterator().hasNext(), "Result has no entries");

    for (ShsMessageEntry result : results) {
        if (!(result.getState().equals(STATE_TERM))) {
            Assert.fail("Result contains messages that don't match criteria");
        }
    }
}

From source file:se.inera.axel.shs.broker.messagestore.internal.MongoMessageLogAdminServiceIT.java

@Test
public void findMessagesByAck() throws Exception {

    Boolean ACK_TERM = true;/* w  ww .  j  av  a2  s.  c om*/
    MessageLogAdminService.Filter filter = new MessageLogAdminService.Filter();
    filter.setAcknowledged(ACK_TERM);

    Iterable<ShsMessageEntry> results = messageLogAdminService.findMessages(filter);
    Assert.assertNotNull(results);
    Assert.assertTrue(results.iterator().hasNext(), "Result has no entries");

    for (ShsMessageEntry result : results) {
        if (!(result.isAcknowledged() == ACK_TERM)) {
            Assert.fail("Result contains messages that don't match criteria");
        }
    }
}

From source file:ch.rgw.tools.StringTool.java

public static String join(final Iterable<String> i, final String tren) {
    StringBuilder ret = new StringBuilder();
    Iterator<String> it = i.iterator();
    while (it.hasNext()) {
        ret.append(it.next());/*from ww w. j  av a 2  s  .  c o m*/
        if (it.hasNext()) {
            ret.append(tren);
        }
    }
    return ret.toString();
}

From source file:se.inera.axel.shs.broker.messagestore.internal.MongoMessageLogAdminServiceIT.java

@Test
public void findMessagesByFrom() throws Exception {

    String FROM_TERM = "0000";
    MessageLogAdminService.Filter filter = new MessageLogAdminService.Filter();
    filter.setFrom(FROM_TERM);/*from w w w .ja  va2 s .co m*/

    Iterable<ShsMessageEntry> results = messageLogAdminService.findMessages(filter);
    Assert.assertNotNull(results);
    Assert.assertTrue(results.iterator().hasNext(), "Result has no entries");

    for (ShsMessageEntry result : results) {
        if (!(StringUtils.containsIgnoreCase(result.getLabel().getFrom().getValue(), FROM_TERM)
                || StringUtils.containsIgnoreCase(result.getLabel().getFrom().getCommonName(), FROM_TERM))) {
            Assert.fail("Result contains messages that don't match criteria");
        }
    }
}

From source file:se.inera.axel.shs.broker.messagestore.internal.MongoMessageLogAdminServiceIT.java

@Test
public void findMessagesByTo() throws Exception {

    String TO_TERM = "0000";
    MessageLogAdminService.Filter filter = new MessageLogAdminService.Filter();
    filter.setTo(TO_TERM);/*from w w  w.j a va 2  s  .c o  m*/

    Iterable<ShsMessageEntry> results = messageLogAdminService.findMessages(filter);
    Assert.assertNotNull(results);
    Assert.assertTrue(results.iterator().hasNext(), "Result has no entries");

    for (ShsMessageEntry result : results) {
        if (!(StringUtils.containsIgnoreCase(result.getLabel().getTo().getValue(), TO_TERM)
                || StringUtils.containsIgnoreCase(result.getLabel().getTo().getCommonName(), TO_TERM))) {
            Assert.fail("Result contains messages that don't match criteria");
        }
    }
}

From source file:se.inera.axel.shs.broker.messagestore.internal.MongoMessageLogAdminServiceIT.java

@Test
public void findMessagesByProduct() throws Exception {
    String PRODUCT_TERM = "00000";
    MessageLogAdminService.Filter filter = new MessageLogAdminService.Filter();
    filter.setProduct(PRODUCT_TERM);/*from w ww  .  ja v a 2s.  c  om*/

    Iterable<ShsMessageEntry> results = messageLogAdminService.findMessages(filter);
    Assert.assertNotNull(results);
    Assert.assertTrue(results.iterator().hasNext(), "Result has no entries");

    for (ShsMessageEntry result : results) {

        if (!(StringUtils.containsIgnoreCase(result.getLabel().getProduct().getValue(), PRODUCT_TERM)
                || StringUtils.containsIgnoreCase(result.getLabel().getProduct().getCommonName(),
                        PRODUCT_TERM))) {
            Assert.fail("Result contains messages that don't match criteria");
        }
    }
}

From source file:se.inera.axel.shs.broker.messagestore.internal.MongoMessageLogAdminServiceIT.java

@Test
public void findMessagesByFilename() throws Exception {

    String FILE_TERM = "test";
    MessageLogAdminService.Filter filter = new MessageLogAdminService.Filter();
    filter.setFilename(FILE_TERM);/*from   www.j a  v  a 2 s.c  om*/

    Iterable<ShsMessageEntry> results = messageLogAdminService.findMessages(filter);
    Assert.assertNotNull(results);
    Assert.assertTrue(results.iterator().hasNext(), "Result has no entries");

    for (ShsMessageEntry result : results) {
        Data data = (Data) result.getLabel().getContent().getDataOrCompound().get(0);
        if (!(StringUtils.containsIgnoreCase(data.getFilename(), FILE_TERM))) {
            Assert.fail("Result contains messages that don't match criteria: data=" + data.getFilename()
                    + " criteria: " + FILE_TERM);
        }
    }
}

From source file:com.github.rvesse.airline.model.ArgumentsMetadata.java

public ArgumentsMetadata(Iterable<String> titles, String description,
        Iterable<ArgumentsRestriction> restrictions, Iterable<Field> path) {
    //@formatter:on
    if (titles == null)
        throw new NullPointerException("title cannot be null");
    if (path == null)
        throw new NullPointerException("path cannot be null");
    if (!path.iterator().hasNext())
        throw new IllegalArgumentException("path cannot be empty");

    this.titles = ListUtils.unmodifiableList(IteratorUtils.toList(titles.iterator()));
    this.description = description;
    this.restrictions = restrictions != null ? AirlineUtils.unmodifiableListCopy(restrictions)
            : Collections.<ArgumentsRestriction>emptyList();
    this.accessors = SetUtils.unmodifiableSet(AirlineUtils.singletonSet(new Accessor(path)));
}

From source file:se.inera.axel.shs.broker.messagestore.internal.MongoMessageLogAdminServiceIT.java

@Test
public void findMessagesByCorrIdAndAck() throws Exception {

    MessageLogAdminService.Filter filter = new MessageLogAdminService.Filter();
    filter.setCorrId("testing-corrid");

    Boolean ACK_TERM = false;/*from w w w. j  av a  2 s  . com*/
    filter.setAcknowledged(ACK_TERM);

    Iterable<ShsMessageEntry> results = messageLogAdminService.findMessages(filter);
    Assert.assertNotNull(results);
    Assert.assertTrue(results.iterator().hasNext(), "Result has no entries");

    for (ShsMessageEntry result : results) {
        if (!"testing-corrid".equals(result.getLabel().getCorrId())) {
            Assert.fail("Result contains messages that don't match criteria");
        }

        if (!(result.isAcknowledged() == ACK_TERM)) {
            Assert.fail("Result contains messages that don't match criteria");
        }
    }
}

From source file:net.orpiske.tcs.wc.reduce.CountReducerTable.java

@Override
protected void reduce(OccurrenceWritable key, Iterable<IntWritable> values, Context context)
        throws IOException, InterruptedException {
    int sum = 0;//from ww w .  j  a  v a2 s . c o  m

    // First, iterate over the KV to calculate the count of references
    Iterator<IntWritable> it = values.iterator();
    while (it.hasNext()) {
        sum += it.next().get();

        String word = key.getText();

        if (logger.isTraceEnabled()) {
            logger.trace("Total occurrences of " + word + " for CSP " + key + " so far: " + sum);
        }
    }

    logger.info("Iterated over " + sum + " records for domain '" + key.toString() + "'");

    // Then, create the mutation objects so that we can save them on the DB
    Mutation domain = getMutation("domain", key.getDomain());
    Mutation word = getMutation("word", key.getText());
    Mutation occurrences = getMutation("occurrences", sum);
    Mutation date = getMutation("reference_date", (new Date()).getTime());

    // ... and put them in an array
    ArrayList<Mutation> list = new ArrayList<Mutation>();
    list.add(domain);
    list.add(word);
    list.add(occurrences);
    list.add(date);

    // ... since we cannot use composite keys very easily, calculates the
    // a SHA-1 hash to serve as the index. At the moment there's no need to
    // be fancy here, so we use a simple SHA-1 hash (index)
    String hashKey = DigestUtils.shaHex(key.getDomain() + key.getText());
    ByteBuffer b = ByteBufferUtil.bytes(hashKey);

    // ... and, finally, put it in the context
    context.write(b, list);
}