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.ihtsdo.otf.refset.graph.gao.HistoryGao.java

/**
 * @param refsetId//ww w .j a v a 2 s . co  m
 * @param fromDate
 * @param toDate
 * @return
 * @throws RefsetGraphAccessException
 */
public ChangeRecord<Refset> getRefsetHeaderHistory(String refsetId, DateTime fromDate, DateTime toDate,
        Integer from, Integer to) throws RefsetGraphAccessException {

    Object[] criteria = { fromDate, toDate, from, to };

    LOGGER.debug("Getting refset history for refset id {}, and criteria {}", refsetId, criteria);

    ChangeRecord<Refset> history = new ChangeRecord<Refset>();

    TitanGraph g = null;

    try {

        g = f.getReadOnlyGraph();

        Iterable<Vertex> vRs = g.query().has(TYPE, VertexType.refset.toString()).has(ID, refsetId).limit(1)
                .vertices();

        if (!vRs.iterator().hasNext()) {

            throw new EntityNotFoundException("Refset does not exist for given refset id " + refsetId);
        }

        Vertex vR = vRs.iterator().next();
        //get required members as per range
        GremlinPipeline<Vertex, Edge> rPipe = new GremlinPipeline<Vertex, Edge>();
        rPipe.start(vR).outE(EdgeLabel.hasState.toString()).has(END, T.lte, toDate.getMillis())
                .has(START, T.gte, fromDate.getMillis()).range(from, to);

        List<Edge> ls = rPipe.toList();
        List<Refset> rs = RefsetConvertor.getHistoryRefsets(ls);

        history.setRecords(rs);

    } catch (Exception e) {

        RefsetGraphFactory.rollback(g);
        LOGGER.error("Error getting refsets member history", e);
        throw new RefsetGraphAccessException(e.getMessage(), e);

    } finally {

        RefsetGraphFactory.shutdown(g);
    }

    return history;
}

From source file:com.orientechnologies.orient.graph.blueprints.GraphTest.java

@Test
public void testCompositeKey() {

    OrientGraphNoTx graph = new OrientGraphNoTx("memory:testComposite");

    try {/*  ww w .  j a  va 2s  .c o m*/
        graph.createVertexType("Account");

        graph.command(new OCommandSQL("create property account.description STRING")).execute();
        graph.command(new OCommandSQL("create property account.namespace STRING")).execute();
        graph.command(new OCommandSQL("create property account.name STRING")).execute();
        graph.command(new OCommandSQL("create index account.composite on account (name, namespace) unique"))
                .execute();

        graph.addVertex("class:account",
                new Object[] { "name", "foo", "namespace", "bar", "description", "foobar" });
        graph.addVertex("class:account",
                new Object[] { "name", "foo", "namespace", "baz", "description", "foobaz" });

        Iterable<Vertex> vertices = graph
                .command(new OCommandSQL("select from index:account.composite where key = [ 'foo', 'baz' ]"))
                .execute();

        List list = IteratorUtils.toList(vertices.iterator());

        Assert.assertEquals(1, list.size());

        vertices = graph.getVertices("account.composite", new Object[] { "foo", "baz" });

        list = IteratorUtils.toList(vertices.iterator());

        Assert.assertEquals(1, list.size());

        vertices = graph.getVertices("account.composite", new OCompositeKey("foo", "baz"));

        list = IteratorUtils.toList(vertices.iterator());

        Assert.assertEquals(1, list.size());

        graph.getVertices("account.composite", new OCompositeKey("foo", "baz"));

    } finally {
        graph.drop();
    }
}

From source file:hudson.plugins.jira.JiraRestService.java

public BasicIssue createIssue(String projectKey, String description, String assignee,
        Iterable<String> components, String summary) {
    IssueInputBuilder builder = new IssueInputBuilder();
    builder.setProjectKey(projectKey).setDescription(description).setIssueTypeId(1L) // BUG
            .setSummary(summary);//from   ww  w. j ava  2 s.c o m

    if (!assignee.equals(""))
        builder.setAssigneeName(assignee);
    if (Iterators.size(components.iterator()) > 0) {
        builder.setComponentsNames(components);
    }

    final IssueInput issueInput = builder.build();

    try {
        return jiraRestClient.getIssueClient().createIssue(issueInput).get(timeout, TimeUnit.SECONDS);
    } catch (Exception e) {
        LOGGER.log(WARNING, "JIRA REST createIssue error: " + e.getMessage(), e);
        return null;
    }
}

From source file:org.ihtsdo.otf.refset.graph.gao.HistoryGao.java

/**
 * @param refsetId//from  ww w.  ja v a2s . com
 * @param fromDate
 * @param toDate
 * @param from
 * @param to
 * @return
 */
public ChangeRecord<Refset> getRefsetHeaderStateHistory(String refsetId, DateTime fromDate, DateTime toDate,
        int from, int to) throws RefsetGraphAccessException {

    Object[] criteria = { fromDate, toDate, from, to };

    LOGGER.debug("Getting refset history for refset id {}, and criteria {}", refsetId, criteria);

    ChangeRecord<Refset> history = new ChangeRecord<Refset>();

    TitanGraph g = null;

    try {

        g = f.getReadOnlyGraph();

        Iterable<Vertex> vRs = g.query().has(TYPE, VertexType.refset.toString()).has(ID, refsetId).limit(1)
                .vertices();

        if (!vRs.iterator().hasNext()) {

            throw new EntityNotFoundException("Refset does not exist for given refset id " + refsetId);
        }

        Vertex vR = vRs.iterator().next();
        //get required members as per range
        GremlinPipeline<Vertex, Vertex> rPipe = new GremlinPipeline<Vertex, Vertex>();
        rPipe.start(vR).outE(EdgeLabel.hasState.toString()).has(END, T.lte, toDate.getMillis())
                .has(START, T.gte, fromDate.getMillis()).inV().has(ACTIVE)
                .has(TYPE, VertexType.hMember.toString()).range(from, to);

        List<Vertex> ls = rPipe.toList();
        List<Refset> rs = RefsetConvertor.getStateRefsets(ls);

        history.setRecords(rs);

    } catch (Exception e) {

        RefsetGraphFactory.rollback(g);
        LOGGER.error("Error getting refsets member history", e);
        throw new RefsetGraphAccessException(e.getMessage(), e);

    } finally {

        RefsetGraphFactory.shutdown(g);
    }

    return history;

}

From source file:org.ihtsdo.otf.refset.graph.gao.HistoryGao.java

/**
 * @param refsetId/*from www. j  av a2 s .c o  m*/
 * @param referenceComponentId
 * @param from
 * @param to
 * @return
 * @throws RefsetGraphAccessException
 */
public ChangeRecord<Member> getMemberHistory(String refsetId, String id, DateTime fromDate, DateTime toDate,
        Integer from, Integer to) throws RefsetGraphAccessException {

    Object[] criteria = { id, fromDate, toDate, from, to };

    LOGGER.debug("Getting member history for refset id {} and criteria {}", refsetId, criteria);

    ChangeRecord<Member> history = new ChangeRecord<Member>();

    TitanGraph g = null;

    try {

        g = f.getReadOnlyGraph();

        Iterable<Vertex> vRs = g.query().has(TYPE, VertexType.refset.toString()).has(ID, refsetId).limit(1)
                .vertices();

        if (!vRs.iterator().hasNext()) {

            throw new EntityNotFoundException("Refset does not exist for given refset id " + refsetId);
        }

        Vertex vR = vRs.iterator().next();

        //get required members as per range

        GremlinPipeline<Vertex, Edge> fPipe = new GremlinPipeline<Vertex, Edge>();
        fPipe.start(vR).inE(EdgeLabel.members.toString()).outV().has(ID, T.eq, id)
                .outE(EdgeLabel.hasState.toString()).has(END, T.lte, toDate.getMillis())
                .has(START, T.gte, fromDate.getMillis()).range(from, to);

        List<Edge> fls = fPipe.toList();

        List<Member> ms = RefsetConvertor.getHistoryMembers(fls);
        history.setRecords(ms);

    } catch (Exception e) {

        RefsetGraphFactory.rollback(g);
        LOGGER.error("Error getting refsets history", e);
        throw new RefsetGraphAccessException(e.getMessage(), e);

    } finally {

        RefsetGraphFactory.shutdown(g);
    }

    LOGGER.debug("Returning {} ", history);

    return history;
}

From source file:org.ihtsdo.otf.refset.graph.gao.HistoryGao.java

/**
 * @param refsetId//from w  ww .  j  a  v a  2 s .c  o  m
 * @param memberId
 * @param fromDate
 * @param toDate
 * @param from
 * @param to
 * @return
 */
public ChangeRecord<Member> getMemberStateHistory(String refsetId, String id, DateTime fromDate,
        DateTime toDate, int from, int to) throws RefsetGraphAccessException {

    Object[] criteria = { id, fromDate, toDate, from, to };

    LOGGER.debug("Getting member history for refset id {} and criteria {}", refsetId, criteria);

    ChangeRecord<Member> history = new ChangeRecord<Member>();

    TitanGraph g = null;

    try {

        g = f.getReadOnlyGraph();

        Iterable<Vertex> vRs = g.query().has(TYPE, VertexType.refset.toString()).has(ID, refsetId).limit(1)
                .vertices();

        if (!vRs.iterator().hasNext()) {

            throw new EntityNotFoundException("Refset does not exist for given refset id " + refsetId);
        }

        Vertex vR = vRs.iterator().next();

        //get required members as per range

        GremlinPipeline<Vertex, Vertex> fPipe = new GremlinPipeline<Vertex, Vertex>();
        fPipe.start(vR).inE(EdgeLabel.members.toString()).outV().has(ID, T.eq, id)
                .outE(EdgeLabel.hasState.toString()).has(END, T.lte, toDate.getMillis())
                .has(START, T.gte, fromDate.getMillis()).inV().has(ACTIVE)
                .has(TYPE, VertexType.hMember.toString()).range(from, to);

        List<Vertex> fls = fPipe.toList();

        List<Member> ms = RefsetConvertor.getStateMembers(fls);
        history.setRecords(ms);

    } catch (Exception e) {

        RefsetGraphFactory.rollback(g);
        LOGGER.error("Error getting member state history", e);
        throw new RefsetGraphAccessException(e.getMessage(), e);

    } finally {

        RefsetGraphFactory.shutdown(g);
    }

    LOGGER.debug("Returning {} ", history);

    return history;

}

From source file:org.ihtsdo.otf.refset.graph.gao.HistoryGao.java

/**
 * @param refsetId/*from   ww  w. ja v  a2  s . c  o m*/
 * @param from
 * @param to
 * @return
 * @throws RefsetGraphAccessException
 */
public Map<String, ChangeRecord<Member>> getAllMembersHistory(String refsetId, DateTime fromDate,
        DateTime toDate, Integer from, Integer to) throws RefsetGraphAccessException {

    LOGGER.debug("Getting all member history for refset id {}", refsetId);

    Map<String, ChangeRecord<Member>> history = new HashMap<String, ChangeRecord<Member>>();

    TitanGraph g = null;

    try {

        g = f.getReadOnlyGraph();

        Iterable<Vertex> vRs = g.query().has(TYPE, VertexType.refset.toString()).has(ID, refsetId).limit(1)
                .vertices();

        if (!vRs.iterator().hasNext()) {

            throw new EntityNotFoundException("Refset does not exist for given refset id " + refsetId);
        }

        Vertex vR = vRs.iterator().next();

        GremlinPipeline<Vertex, Edge> fPipe = new GremlinPipeline<Vertex, Edge>();
        fPipe.start(vR).inE(EdgeLabel.members.toString()).range(from, to);
        List<Edge> fls = fPipe.toList();
        for (Edge e : fls) {

            Vertex v = e.getVertex(Direction.OUT);
            GremlinPipeline<Vertex, Edge> mhPipe = new GremlinPipeline<Vertex, Edge>();
            mhPipe.start(v).outE(EdgeLabel.hasState.toString()).has(END, T.lte, toDate.getMillis())
                    .has(START, T.gte, fromDate.getMillis()).range(from, to);
            List<Edge> mhls = mhPipe.toList();

            List<Member> ms = RefsetConvertor.getHistoryMembers(mhls);
            ChangeRecord<Member> cr = new ChangeRecord<Member>();
            String rcId = e.getProperty(ID);
            cr.setRecords(ms);
            history.put(rcId, cr);

        }

    } catch (Exception e) {

        RefsetGraphFactory.rollback(g);
        LOGGER.error("Error getting refsets member history", e);
        throw new RefsetGraphAccessException(e.getMessage(), e);

    } finally {

        RefsetGraphFactory.shutdown(g);
    }

    return history;
}

From source file:org.ihtsdo.otf.refset.graph.gao.HistoryGao.java

/**
 * @param refsetId//from   w  w  w.  j  a v  a 2  s .c  o  m
 * @param fromDate
 * @param toDate
 * @param from
 * @param to
 * @return
 */
public Map<String, ChangeRecord<Member>> getAllMembersStateHistory(String refsetId, DateTime fromDate,
        DateTime toDate, int from, int to) throws RefsetGraphAccessException {

    LOGGER.debug("Getting all member state history for refset id {}", refsetId);

    Map<String, ChangeRecord<Member>> history = new HashMap<String, ChangeRecord<Member>>();

    TitanGraph g = null;

    try {

        g = f.getReadOnlyGraph();

        Iterable<Vertex> vRs = g.query().has(TYPE, VertexType.refset.toString()).has(ID, refsetId).limit(1)
                .vertices();

        if (!vRs.iterator().hasNext()) {

            throw new EntityNotFoundException("Refset does not exist for given refset id " + refsetId);
        }

        Vertex vR = vRs.iterator().next();

        GremlinPipeline<Vertex, Edge> fPipe = new GremlinPipeline<Vertex, Edge>();
        fPipe.start(vR).inE(EdgeLabel.members.toString()).range(from, to);
        List<Edge> fls = fPipe.toList();
        for (Edge e : fls) {

            Vertex v = e.getVertex(Direction.OUT);
            GremlinPipeline<Vertex, Edge> mhPipe = new GremlinPipeline<Vertex, Edge>();
            mhPipe.start(v).outE(EdgeLabel.hasState.toString()).has(END, T.lte, toDate.getMillis())
                    .has(START, T.gte, fromDate.getMillis()).inV().has(ACTIVE)
                    .has(TYPE, VertexType.hMember.toString()).range(from, to);
            List<Edge> mhls = mhPipe.toList();

            List<Member> ms = RefsetConvertor.getHistoryMembers(mhls);
            ChangeRecord<Member> cr = new ChangeRecord<Member>();
            String rcId = e.getProperty(ID);
            cr.setRecords(ms);
            history.put(rcId, cr);

        }

    } catch (Exception e) {

        RefsetGraphFactory.rollback(g);
        LOGGER.error("Error getting refsets member history", e);
        throw new RefsetGraphAccessException(e.getMessage(), e);

    } finally {

        RefsetGraphFactory.shutdown(g);
    }

    return history;

}

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

License:asdf

/**
 * //from  ww w . j  a  va 2s .c o m
 * magic paginate method.
 * 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 HibernateCallback() {
        /**
         * @see org.springframework.orm.hibernate3.HibernateCallback#doInHibernate(org.hibernate.Session)
         */
        @Override
        public Object doInHibernate(Session session) throws HibernateException, SQLException {
            final Iterator it = con == null ? null : con.iterator();

            String conditionHQL = buildConditionHQL(persistClass, it).toString();

            //query list
            final StringBuffer queryHQL = new StringBuffer(conditionHQL);
            appendOrder(queryHQL, order);
            queryHQL.insert(0, SELECT_ID_CLAUSE);

            Query query = session.createQuery(queryHQL.toString());

            //count query
            final StringBuffer countHQL = new StringBuffer(conditionHQL);
            countHQL.insert(0, "select count(*) ");
            Query countQuery = session.createQuery(countHQL.toString());

            if (it != null) {
                int i = 0;
                while (it.hasNext()) {
                    Object obj = it.next();
                    query.setParameter(i, obj);
                    countQuery.setParameter(i, obj);
                    i++;
                }
            }
            //get perpage
            int perPage = options.getPerPage();
            int page = options.getPage();
            if (page < 1) {
                page = 1;
            }
            query.setFirstResult((page - 1) * perPage);
            query.setMaxResults(perPage);
            //query total record number
            options.setTotalRecord((Long) countQuery.iterate().next());

            ResultTransformer transformer = new LazyLoadEntityTransformer(session, persistClass);
            query.setResultTransformer(transformer);

            PaginationList list = new PaginationList(query.list().iterator(), options);

            return list;

        }
    });
}

From source file:ltistarter.JPATests.java

@Test
@Transactional/*w ww  .j  a v a  2s.c  o m*/
public void testJPARelations() {
    Iterable<ProfileEntity> profiles;
    Iterable<LtiUserEntity> users;
    Iterable<SSOKeyEntity> ssoKeys;
    ProfileEntity profile;
    SSOKeyEntity ssoKey;

    assertNotNull(profileRepository);
    assertNotNull(ltiUserRepository);
    assertNotNull(ssoKeyRepository);

    profiles = profileRepository.findAll();
    assertFalse(profiles.iterator().hasNext());
    users = ltiUserRepository.findAll();
    assertFalse(users.iterator().hasNext());
    ssoKeys = ssoKeyRepository.findAll();
    assertFalse(ssoKeys.iterator().hasNext());

    profileRepository.save(new ProfileEntity("AaronZeckoski", null, "azeckoski@test.com"));
    profileRepository.save(new ProfileEntity("BeckyZeckoski", null, "rzeckoski@test.com"));
    profiles = profileRepository.findAll();
    assertTrue(profiles.iterator().hasNext());
    assertEquals(2, CollectionUtils.size(profiles.iterator()));
    profile = profileRepository.findOne(91919l);
    assertNull(profile);
    profile = profileRepository.findByProfileKey("AaronZeckoski");
    assertNotNull(profile);
    assertTrue(profile.getSsoKeys().isEmpty());

    ssoKeyRepository.save(new SSOKeyEntity("random_GOOGLEKEY", "google.com"));
    ssoKeyRepository.save(new SSOKeyEntity("AZ_google_key", "google.com"));
    ssoKeys = ssoKeyRepository.findAll();
    assertTrue(ssoKeys.iterator().hasNext());
    assertEquals(2, CollectionUtils.size(ssoKeys.iterator()));
    ssoKey = ssoKeyRepository.findByKeyKey("AZ_google_key");
    assertNotNull(ssoKey);
    assertNull(ssoKey.getProfile());

    // now add profile to the ssoKey
    ssoKey.setProfile(profile);
    profile.getSsoKeys().add(ssoKey);
    ssoKeyRepository.save(ssoKey);
    ssoKey = ssoKeyRepository.findByKeyKey("AZ_google_key");
    assertNotNull(ssoKey);
    assertNotNull(ssoKey.getProfile());
    profile = ssoKey.getProfile();
    assertFalse(profile.getSsoKeys().isEmpty());
    assertEquals(1, profile.getSsoKeys().size());

    // now remove the ssoKey and make sure things worked
    // TODO more tests
}