List of usage examples for java.lang Iterable iterator
Iterator<T> iterator();
From source file:com.link_intersystems.lang.reflect.criteria.MemberCriteriaTest.java
@Test public void usingFilterTest() { memberCriteria.membersOfType(Method.class); memberCriteria.add(new ToStringPredicate()); ClassCriteria classCriteria = new ClassCriteria(); Iterable<Class<?>> classIterable = classCriteria.getIterable(Object.class); Iterable<Member> memberIterable = memberCriteria.getIterable(classIterable); Iterator<Member> iterator = memberIterable.iterator(); assertTrue(iterator.hasNext());//ww w.j av a 2 s . c o m Member member = iterator.next(); int modifiers = member.getModifiers(); assertTrue(Modifier.isPublic(modifiers)); assertFalse(iterator.hasNext()); }
From source file:fr.mtlx.odm.TestSessionImpl.java
@Test public void testPagedSearch() throws InvalidNameException, MappingException { Name dn = new LdapName("ou=personnes"); int n = 0;/*from w w w .jav a 2s.com*/ FilterBuilder<Person> fb = sessionFactory.filterBuilder(Person.class); Iterable<List<Person>> results = session.getOperations(Person.class).search(dn) .add(fb.not(fb.objectClass("ENTPerson"))).pages(5); assertNotNull(results); Iterator<List<Person>> iterator = results.iterator(); assertNotNull(iterator); assertTrue(iterator.hasNext()); for (List<Person> page : results) { n += page.size(); assertTrue(Iterables.any(page, new Predicate<Person>() { @Override public boolean apply(Person entry) { return entry != null && session.isPersistent(entry); } })); } assertTrue(n > 0); }
From source file:corner.orm.gae.impl.PaginatedJapEntityService.java
License:asdf
/** * * magic paginate method.//from w ww.j a va 2 s. c o m * eg: * <code> * options.setPage(2); * * * paginate(Member.class,new Object[]{"email=?","asdf@asdf.net"},"userName desc",options) * paginate(Member.class,"email='asdf@asdf.net'","userName desc",options) * * List conditions = new ArrayList(); * conditions.add("userName=? and password=?"); * conditions.add(userName); * conditions.add(password); * paginate(Member.class,conditions,"userName desc",options) * * </code> * Magic conditions query criteria * @param persistClass persistence class * @param conditions query criteria * @param order order by sql * @param options pagination options. * @return include result and totalRecord. */ public PaginationList paginate(final Class<?> persistClass, final Object conditions, final String order, final PaginationOptions options) { final Iterable con = typeCoercer.coerce(conditions, Iterable.class); return (PaginationList) this.template.execute(new JpaCallback() { @Override public Object doInJpa(EntityManager entityManager) throws PersistenceException { final Iterator it = con == null ? null : con.iterator(); String conditionJPQL = buildConditionJPQL(persistClass, it).toString(); //query list final StringBuffer queryJPQL = new StringBuffer(conditionJPQL); appendOrder(queryJPQL, order); queryJPQL.insert(0, "select root." + EntityConstants.ID_PROPERTY_NAME); Query query = entityManager.createQuery(queryJPQL.toString()); //count query final StringBuffer countJPQL = new StringBuffer(conditionJPQL); countJPQL.insert(0, "select count(root) "); Query countQuery = entityManager.createQuery(countJPQL.toString()); if (it != null) { int i = 0; while (it.hasNext()) { i++; Object obj = it.next(); query.setParameter(String.valueOf(i), obj); countQuery.setParameter(String.valueOf(i), obj); } } //get perpage int perPage = options.getPerPage(); int page = options.getPage(); if (page < 1) { page = 1; } query.setFirstResult((page - 1) * perPage); query.setMaxResults(perPage); PaginationList list = new PaginationList(query.getResultList().iterator(), options); //query total record number //beacause jpa rowCount is integer type.so convert as long options.setTotalRecord(Long.parseLong(countQuery.getSingleResult().toString())); return list; } }); }
From source file:org.apereo.openlrs.storage.aws.elasticsearch.XApiOnlyAwsElasticsearchTierTwoStorage.java
private Page<OpenLRSEntity> createPage(Iterable<Statement> statements) { if (statements != null) { return new PageImpl<OpenLRSEntity>(IteratorUtils.toList(statements.iterator())); }/*from ww w .j ava 2s.c o m*/ return null; }
From source file:cn.guoyukun.spring.jpa.repository.support.SimpleBaseRepository.java
@Transactional @Override//from www .j a v a 2s. com public void deleteInBatch(final Iterable<M> entities) { Iterator<M> iter = entities.iterator(); if (entities == null || !iter.hasNext()) { return; } Set<M> models = Sets.newHashSet(iter); boolean logicDeleteableEntity = LogicDeleteable.class.isAssignableFrom(this.entityClass); if (logicDeleteableEntity) { String ql = String.format(LOGIC_DELETE_ALL_QUERY_STRING, entityName); repositoryHelper.batchUpdate(ql, models); } else { String ql = String.format(DELETE_ALL_QUERY_STRING, entityName); repositoryHelper.batchUpdate(ql, models); } }
From source file:com.vilt.minium.impl.BaseWebElementsImpl.java
@Override public final Iterator<WebElement> iterator() { Iterable<WebElement> elements = computeElements(); if (logger.isDebugEnabled()) { logger.debug("[WebElements size: {}] {}", Iterables.size(elements), this); }//from w w w. j av a 2 s . c o m return elements.iterator(); }
From source file:com.orientechnologies.orient.graph.blueprints.GraphTest.java
@Test public void testKebabCaseQuery() { OrientGraphFactory orientGraphFactory = new OrientGraphFactory("memory:testKebabCase"); final OrientGraphNoTx g = orientGraphFactory.getNoTx(); try {/*www . ja v a 2 s.c om*/ g.addVertex(null).setProperty("test-one", true); g.addVertex(null).setProperty("test-one", false); g.commit(); GraphQuery query = g.query(); query.has("test-one", true); Iterable<Vertex> vertices = query.vertices(); final Iterator<Vertex> it = vertices.iterator(); Assert.assertTrue(it.hasNext()); Assert.assertTrue((Boolean) it.next().getProperty("test-one")); Assert.assertFalse(it.hasNext()); } finally { g.shutdown(); orientGraphFactory.close(); } }
From source file:io.druid.query.timeboundary.TimeBoundaryQueryRunnerTest.java
@Test @SuppressWarnings("unchecked") public void testFilteredTimeBoundaryQuery() throws IOException { QueryRunner customRunner = getCustomRunner(); TimeBoundaryQuery timeBoundaryQuery = Druids.newTimeBoundaryQueryBuilder().dataSource("testing") .filters("quality", "automotive").build(); Assert.assertTrue(timeBoundaryQuery.hasFilters()); HashMap<String, Object> context = new HashMap<String, Object>(); Iterable<Result<TimeBoundaryResultValue>> results = Sequences.toList( customRunner.run(timeBoundaryQuery, context), Lists.<Result<TimeBoundaryResultValue>>newArrayList()); Assert.assertTrue(Iterables.size(results) > 0); TimeBoundaryResultValue val = results.iterator().next().getValue(); DateTime minTime = val.getMinTime(); DateTime maxTime = val.getMaxTime(); Assert.assertEquals(new DateTime("2011-01-13T00:00:00.000Z"), minTime); Assert.assertEquals(new DateTime("2011-01-16T00:00:00.000Z"), maxTime); }
From source file:com.link_intersystems.lang.reflect.criteria.MemberCriteriaTest.java
@Test public void getFirstMethodWithSameSignatureAsCollectionAddObject() throws SecurityException, NoSuchMethodException { memberCriteria.setResult(Result.FIRST); memberCriteria.membersOfType(Method.class); Method method = List.class.getDeclaredMethod("isEmpty"); memberCriteria.add(new SignaturePredicate(method)); ClassCriteria classCriteria = new ClassCriteria(); classCriteria.setTraverseStrategy(TraverseStrategy.DEPTH_FIRST); classCriteria.setSelection(ClassType.CLASSES); Iterable<Class<?>> classIterable = classCriteria.getIterable(ArrayList.class); Iterable<Member> memberIterable = memberCriteria.getIterable(classIterable); Iterator<Member> criteriaIterator = memberIterable.iterator(); Member member = criteriaIterator.next(); Method firstMatch = (Method) member; Method declaredMethod = ArrayList.class.getDeclaredMethod("isEmpty"); assertEquals(declaredMethod, firstMatch); assertFalse(criteriaIterator.hasNext()); }
From source file:com.orientechnologies.orient.graph.blueprints.GraphTest.java
@Test public void testCustomPredicate() { OrientGraphFactory orientGraphFactory = new OrientGraphFactory("memory:testCustomPredicate"); final OrientGraphNoTx g = orientGraphFactory.getNoTx(); try {//from w w w. j a v a 2 s.c om g.addVertex(null).setProperty("test", true); g.addVertex(null).setProperty("test", false); g.addVertex(null).setProperty("no", true); g.commit(); GraphQuery query = g.query(); query.has("test", new Predicate() { @Override public boolean evaluate(Object first, Object second) { return first != null && first.equals(second); } }, true); Iterable<Vertex> vertices = query.vertices(); final Iterator<Vertex> it = vertices.iterator(); Assert.assertTrue(it.hasNext()); Assert.assertTrue((Boolean) it.next().getProperty("test")); Assert.assertFalse(it.hasNext()); } finally { g.shutdown(); orientGraphFactory.close(); } }