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.dominion.salud.mpr.negocio.service.admin.impl.UsuariosServiceImpl.java

@Override
public <S extends Usuarios> List<S> save(Iterable<S> usuarioss) {
    Iterator<S> iterador = usuarioss.iterator();
    while (iterador.hasNext()) {
        Usuarios usuarios = iterador.next();
        if (usuarios.getIdUsuario() != null && usuariosRepository.exists(usuarios.getIdUsuario())) {
            Usuarios existe = findOne(usuarios.getIdUsuario());
            if (!StringUtils.equals(existe.getTxtPassword(), usuarios.getTxtPassword())) {
                usuarios.setTxtPassword(DigestUtils.md5Hex(usuarios.getTxtPassword()));
            }/*from   ww w  .jav  a  2 s  . c  o m*/
        } else {
            usuarios.setTxtPassword(DigestUtils.md5Hex(usuarios.getTxtPassword()));
        }
    }
    return usuariosRepository.save(usuarioss);
}

From source file:example.ApplicationIntegrationTests.java

@Test
public void initializesRepositoryWithSampleData() {

    Iterable<Customer> result = repository.findAll();

    assertThat(result, is(iterableWithSize(1)));
    assertThat(result.iterator().next().getLastModifiedDate(), is(notNullValue()));
}

From source file:org.openlmis.fulfillment.service.OrderFileTemplateService.java

/**
 * Get orderFileTemplate.//from ww  w .  j  a  va2  s . co m
 *
 * @return OrderFileTemplate.
 */
public OrderFileTemplate getOrderFileTemplate() {
    Iterable<OrderFileTemplate> orderFileTemplates = orderFileTemplateRepository.findAll();

    if (orderFileTemplates != null && orderFileTemplates.iterator().hasNext()) {
        return orderFileTemplates.iterator().next();
    }

    return null;
}

From source file:demo.controllers.TestController.java

@RequestMapping(value = "/customers/all")
List<Customer> getAll() {//from   ww  w .  ja  v a  2 s  .  c  o  m
    Iterable<Customer> it = repository.findAll();
    if (it != null) {
        return IteratorUtils.toList(it.iterator());
    } else {
        return new ArrayList<>();
    }
}

From source file:uk.gov.nationalarchives.discovery.taxonomy.common.repository.mongo.CategoryRepositoryTest.java

@Test
public void testMongoDbIsUpAndRunning() {
    mongoTestDataSet.initCategoryCollectionWith1element();

    Iterable<Category> iterable = repository.findAll();
    assertThat(iterable, is(notNullValue()));
    assertThat(iterable.iterator().hasNext(), is(true));

}

From source file:uk.gov.nationalarchives.discovery.taxonomy.common.repository.mongo.TrainingDocumentRepositoryTest.java

@Test
public void testCollectionCount() {

    Iterable<TrainingDocument> iterable = repository.findAll();
    assertThat(iterable, is(notNullValue()));
    assertThat(iterable.iterator().hasNext(), is(true));
}

From source file:org.nubomedia.marketplace.ApplicationManagement.java

private Set fromIterbaleToSet(Iterable iterable) {
    Set set = new HashSet();
    Iterator iterator = iterable.iterator();
    while (iterator.hasNext()) {
        set.add(iterator.next());/*from   w w w  . j av  a2s.c  o m*/
    }
    return set;
}

From source file:com.rationaldevelopers.oss.service.SimpleItemTest.java

@Test
public void testInsert() {
    Assert.assertNotNull("Simple Item Service is Null", simpleItemService);
    SimpleItem s1 = new SimpleItem("Test 01", "Test 01");
    simpleItemService.saveOrUpdate(s1);//from  www .j a v a 2 s.  c om
    Assert.assertNotNull(s1.getId());

    Iterable<SimpleItem> all = simpleItemService.findAll();
    Assert.assertNotNull(all);
    SimpleItem s1a = all.iterator().next();
    Assert.assertNotNull(s1a);

    simpleItemService.delete(s1a);
}

From source file:org.springframework.ldap.samples.useradmin.rest.RestUserController.java

@RequestMapping(value = { "/", "/users" }, method = GET)
public List<User> index(@RequestParam(required = false) String name) {
    if (StringUtils.hasText(name)) {
        return userService.searchByNameName(name);
    } else {/*from  w  w  w. j a  va 2s.  c o m*/
        List<User> userList = new ArrayList<User>();
        Iterable<User> all = userService.findAll();
        Iterator<User> iterator = all.iterator();
        while (iterator.hasNext()) {
            User user = iterator.next();
            userList.add(user);
        }
        return userList;
    }
}

From source file:fr.landel.utils.assertor.utils.AssertorIterable.java

private static <I extends Iterable<T>, T> boolean hasInOrder(final I iterable1, final Iterable<T> iterable2,
        final boolean not, final EnumAnalysisMode analysisMode) {

    long found = 0;
    final int size1 = IterableUtils.size(iterable1);
    final int size2 = IterableUtils.size(iterable2);

    if (size1 < size2) {
        return not;
    } else if (size1 == size2) {
        return not ^ iterable1.equals(iterable2);
    }/*from  w  w w  .  j a va 2  s. c  o  m*/

    if (EnumAnalysisMode.STANDARD.equals(analysisMode)) {
        final Iterator<T> iterator1 = iterable1.iterator();
        Iterator<T> iterator2 = iterable2.iterator();

        // not empty pre-check, so we call next directly
        T value2 = iterator2.next();
        while (iterator1.hasNext() && found < size2) {
            if (Objects.equals(iterator1.next(), value2)) {
                ++found;
                if (iterator2.hasNext()) {
                    value2 = iterator2.next();
                }
            } else if (found > 0) {
                found = 0;
                iterator2 = iterable2.iterator();
                value2 = iterator2.next();
            }
        }
    } else {
        final AtomicInteger count = new AtomicInteger(0);

        final List<T> list2 = IterableUtils.toList(iterable2);

        StreamSupport.stream(iterable1.spliterator(), EnumAnalysisMode.PARALLEL.equals(analysisMode))
                .forEachOrdered(o -> {
                    int inc = count.get();
                    if (inc < size2) {
                        if (Objects.equals(o, list2.get(inc))) {
                            count.incrementAndGet();
                        } else if (inc > 0) {
                            count.set(0);
                        }
                    }
                });

        found = count.get();
    }

    return not ^ (found == size2);
}