List of usage examples for java.lang Iterable iterator
Iterator<T> iterator();
From source file:org.apereo.openlrs.repositories.statements.ElasticSearchStatementRepository.java
@SuppressWarnings("unchecked") @Override//from ww w .j av a 2 s .c o m public List<Statement> get(Map<String, String> filters) { String actor = filters.get(StatementUtils.ACTOR_FILTER); String activity = filters.get(StatementUtils.ACTIVITY_FILTER); String since = filters.get(StatementUtils.SINCE_FILTER); String until = filters.get(StatementUtils.UNTIL_FILTER); int limit = getLimit(filters.get(StatementUtils.LIMIT_FILTER)); ; XApiActor xApiActor = null; if (StringUtils.isNotBlank(actor)) { ObjectMapper objectMapper = new ObjectMapper(); try { xApiActor = objectMapper.readValue(actor.getBytes(), XApiActor.class); } catch (Exception e) { log.error(e.getMessage(), e); } } SearchQuery searchQuery = null; if (StringUtils.isNotBlank(activity) && xApiActor != null) { QueryBuilder actorQuery = buildActorQuery(xApiActor); QueryBuilder activityQuery = nestedQuery("object", boolQuery().must(matchQuery("object.id", activity))); BoolQueryBuilder boolQuery = boolQuery().must(actorQuery).must(activityQuery); searchQuery = startQuery(limit, boolQuery).build(); } else if (xApiActor != null) { QueryBuilder query = buildActorQuery(xApiActor); if (query != null) { searchQuery = startQuery(limit, query).build(); } } else if (StringUtils.isNotBlank(activity)) { QueryBuilder query = nestedQuery("object", boolQuery().must(matchQuery("object.id", activity))); searchQuery = startQuery(limit, query).build(); } else if (StringUtils.isNotBlank(since) || StringUtils.isNotBlank(until)) { QueryBuilder query = null; if (StringUtils.isNotBlank(since) && StringUtils.isNotBlank(until)) { query = new RangeQueryBuilder("stored").from(since).to(until); } else { if (StringUtils.isNotBlank(since)) { query = new RangeQueryBuilder("stored").from(since).to("now"); } if (StringUtils.isNotBlank(until)) { try { DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'"); TimeZone tz = TimeZone.getTimeZone("UTC"); formatter.setTimeZone(tz); Date date = (Date) formatter.parse(until); Calendar calendar = Calendar.getInstance(); calendar.setTime(date); calendar.add(Calendar.YEAR, -1); query = new RangeQueryBuilder("stored").from(formatter.format(calendar.getTime())) .to(until); } catch (ParseException e) { log.error(e.getMessage(), e); return null; } } } NativeSearchQueryBuilder searchQueryBuilder = startQuery(limit, query); searchQuery = searchQueryBuilder.withSort(new FieldSortBuilder("stored").order(SortOrder.DESC)).build(); } else if (limit > 0) { searchQuery = startQuery(limit, null).build(); } if (searchQuery != null) { if (log.isDebugEnabled()) { if (searchQuery.getQuery() != null) { log.debug(String.format("Elasticsearch query %s", searchQuery.getQuery().toString())); } } Iterable<Statement> iterableStatements = esSpringDataRepository.search(searchQuery); if (iterableStatements != null) { return IteratorUtils.toList(iterableStatements.iterator()); } } return null; }
From source file:com.link_intersystems.lang.reflect.criteria.MemberCriteriaTest.java
@Test public void annotatedElementsPackage2Class2Member() throws SecurityException, NoSuchMethodException { ClassCriteria classCriteria = new ClassCriteria(); classCriteria.setSelection(ClassType.CLASSES); memberCriteria.membersOfType(Method.class); memberCriteria.named("size"); Iterable<Class<?>> classIterable = classCriteria.getIterable(ArrayList.class); Iterable<? extends AnnotatedElement> annotatedElementIterable = memberCriteria .getAnnotatedElementIterable(classIterable, IterateStrategy.PACKAGE_CLASS_MEMBERS); Iterator<? extends AnnotatedElement> iterator = annotatedElementIterable.iterator(); assertTrue(iterator.hasNext());/*from w w w . j a va 2s. c o m*/ AnnotatedElement next = iterator.next(); assertEquals(ArrayList.class.getPackage(), next); next = iterator.next(); assertEquals(ArrayList.class, next); next = iterator.next(); assertEquals(ArrayList.class.getDeclaredMethod("size"), next); next = iterator.next(); assertEquals(AbstractList.class.getPackage(), next); next = iterator.next(); assertEquals(AbstractList.class, next); next = iterator.next(); assertEquals(AbstractCollection.class.getPackage(), next); next = iterator.next(); assertEquals(AbstractCollection.class, next); next = iterator.next(); assertEquals(AbstractCollection.class.getDeclaredMethod("size"), next); next = iterator.next(); assertEquals(Object.class.getPackage(), next); next = iterator.next(); assertEquals(Object.class, next); assertFalse(iterator.hasNext()); }
From source file:fr.inria.atlanmod.neoemf.graph.blueprints.datastore.estores.impl.DirectWriteBlueprintsResourceEStoreImpl.java
protected boolean isSet(InternalEObject object, EReference eReference) { Vertex vertex = graph.getVertex(object); if (vertex != null) { Iterable<Vertex> vertices = vertex.getVertices(Direction.OUT, eReference.getName()); return vertices.iterator().hasNext(); } else {/*from w w w . j a va 2 s. c o m*/ return false; } }
From source file:com.adobe.communities.ugc.migration.legacyExport.UGCExportHelper.java
public static void extractTranslation(final JSONWriter writer, final Resource translationResource) throws JSONException, IOException { final Iterable<Resource> translations = translationResource.getChildren(); final ValueMap props = translationResource.adaptTo(ValueMap.class); String languageLabel = (String) props.get("language"); if (null == languageLabel) { languageLabel = (String) props.get("mtlanguage"); if (null == languageLabel) { return; }// w ww . ja v a 2s .c o m } writer.key(ContentTypeDefinitions.LABEL_TRANSLATION); writer.object(); writer.key("mtlanguage"); if (languageLabel.equals("nb")) { // SPECIAL CASE FOR LEGACY EXPORTER ONLY: // the label for norwegian changed between 6.0 and 6.1 // (i.e. this section must be removed for 6.1 exporter) languageLabel = "no"; } writer.value(languageLabel); writer.key("jcr:created"); writer.value(props.get("jcr:created", Long.class)); writer.key("jcr:createdBy"); writer.value(props.get("jcr:createdBy")); if (translations.iterator().hasNext()) { writer.key(ContentTypeDefinitions.LABEL_TRANSLATIONS); final JSONWriter translationObjects = writer.object(); UGCExportHelper.extractTranslations(translationObjects, translations); writer.endObject(); } writer.endObject(); }
From source file:argendata.web.controller.DatasetController.java
@RequestMapping(method = RequestMethod.GET) public ModelAndView findAll() { ModelAndView mav = new ModelAndView(); this.datasetService.cleanIndex(); Iterable<Dataset> datasetsResults = datasetService.getAllApprovedDatasets(); Iterator<Dataset> iterator = datasetsResults.iterator(); List<Dataset> data = new ArrayList<Dataset>(); while (iterator.hasNext()) { data.add((Dataset) iterator.next()); }//from ww w . jav a 2s . c o m mav.addObject("datasets", data); return mav; }
From source file:ca.unbsj.cbakerlab.owlexprmanager.ClassExpressionTreeGenerator.java
/** * Assign names of variables as vertex property 'nodeVariableName' for either Resource, Data value. * *///from w w w .j av a 2 s.co m public void assignNodeVariableNames(List<Graph> existingGraph) { int numberOfVertices = 0; Integer currentDegree; for (Graph g : existingGraph) { // get the number of vertices Iterable<Vertex> vit = g.getVertices(); Iterator it = vit.iterator(); while (it.hasNext()) { numberOfVertices++; it.next(); } //System.out.println(" NUMOFVERTICES "+numberOfVertices); // get the sorted edges traversed in DFS order List<Edge> edgesListSorted = sortEdgesInDFS(g.getEdges()); List<Vertex> verticesListSorted = sortVerticesInDFS(edgesListSorted, numberOfVertices); System.out.println("Sorted Vertices: " + verticesListSorted.toString()); System.out.println("Sorted Edges: " + edgesListSorted.toString()); for (Vertex v : verticesListSorted) { // set the root node as input if (v.getId().equals("0")) v.setProperty("nodeVariableName", "input"); else { // assign empty content for each non-root node v.setProperty("nodeVariableName", ""); // if the vertex is NOT the root (i.e. Resource input) and common, set and increment the name // get the current degree as an Element object and cast it to int currentDegree = v.getProperty("degree"); if (currentDegree > 1) v.setProperty("nodeVariableName", "common" + "ResStmt" + (++commonNodeCounter)); // if (currentDegree == 1) { Edge e = getIncomingEdge(v, edgesListSorted); if (!e.getLabel().equals("")) v.setProperty("nodeVariableName", "ResStmt" + (++otherNodeCounter)); } // Assign nodeVariableName property to the leaf node(s) with degree = 0 if (currentDegree == 0) { // clean the node content of 'name' and, set and increment it v.setProperty("nodeVariableName", getSimpleName(v.getProperty("name").toString()) + "Node" + (++leafNodeCounter)); } } } // For each property edge that does not have a label, propagate the nodeVariableName // of the parent to the child for (Edge edge : edgesListSorted) { if (edge.getLabel().equals("")) //System.out.println("edge "+edge.getId()+ " is empty"); edge.getVertex(Direction.IN).setProperty("nodeVariableName", edge.getVertex(Direction.OUT).getProperty("nodeVariableName")); } } }
From source file:com.spectralogic.ds3cli.command.Recover.java
@Override public DefaultResult call() throws Exception { try {//from ww w.jav a 2 s . c o m if (listOnly) { return new DefaultResult( RecoveryFileManager.printSearchFiles(this.id, this.bucketName, this.jobType)); } if (deleteFiles) { return new DefaultResult(RecoveryFileManager.deleteFiles(this.id, this.bucketName, this.jobType)); } // get exactly file to recover final Iterable<Path> files = RecoveryFileManager.searchFiles(this.id, this.bucketName, this.jobType); if (Iterables.isEmpty(files)) { return new DefaultResult("No matching recovery files found."); } if (Iterables.size(files) > 1) { return new DefaultResult("Multiple matching recovery files found:\n" + RecoveryFileManager.printSearchFiles(this.id, this.bucketName, this.jobType) + "Please restrict search criteria."); } final Path file = files.iterator().next(); final RecoveryJob job = RecoveryFileManager.getRecoveryJobByFile(file.toFile()); return new DefaultResult(recover(job)); } catch (final IOException e) { throw new CommandException("Recovery Job failed", e); } }
From source file:com.orientechnologies.orient.graph.blueprints.GraphTest.java
@Test(expected = IllegalArgumentException.class) public void testCompositeExceptionKey() { OrientGraphNoTx graph = new OrientGraphNoTx("memory:testComposite"); try {/*from w w w . java 2s .com*/ 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()); graph.getVertices("account.composite", new Object[] { "foo", "baz", "bar" }); } finally { graph.drop(); } }
From source file:microsoft.exchange.webservices.data.notification.StreamingSubscriptionConnection.java
/** * Initializes a new instance of the StreamingSubscriptionConnection class. * * @param service The ExchangeService instance this connection uses to connect * to the server.//from w w w . ja v a 2s . c o m * @param subscriptions Iterable subcriptions * @param lifetime The maximum time, in minutes, the connection will remain open. * Lifetime must be between 1 and 30. * @throws Exception */ public StreamingSubscriptionConnection(ExchangeService service, Iterable<StreamingSubscription> subscriptions, int lifetime) throws Exception { this(service, lifetime); EwsUtilities.validateParamCollection(subscriptions.iterator(), "subscriptions"); for (StreamingSubscription subscription : subscriptions) { this.subscriptions.put(subscription.getId(), subscription); } }
From source file:com.atlassian.jira.applinks.JiraAppLinksHostApplication.java
/** * @return an {@link Iterable} containing an {@link com.atlassian.applinks.host.spi.EntityReference} for every * entity in the local instance visible to the currently logged in user. Note, the implementation * <strong>must perform a permission check</strong> and return only entities visible the context user (who * may be anonymous).//from w ww.java 2s. c o m * User requires to have either the BROWSE project, JIRA Administrator or PROJECT ADMIN permission. */ @Override public Iterable<EntityReference> getLocalEntities() { final Iterable<Project> projects = Iterables.filter(projectManager.getProjectObjects(), new Predicate<Project>() { @Override public boolean apply(@Nullable Project input) { return (input != null) && checkProjectPermissions(input, true); } }); if (!projects.iterator().hasNext()) { return Collections.emptyList(); } return newArrayList(Iterables.transform(projects, new ProjectToEntityRef())); }