List of usage examples for java.lang Iterable iterator
Iterator<T> iterator();
From source file:com.infinities.nova.securitygroups.rules.api.DaseinSecurityGroupRulesApi.java
/** * @param context/*from w w w .jav a 2s. c om*/ * @param projectId * @param string * @return * @throws ConcurrentException * @throws CloudException * @throws InternalException * @throws ExecutionException * @throws InterruptedException */ private Rule getRule(OpenstackRequestContext context, String projectId, String securityGroupId, String ruleId, Rule rule) throws InternalException, CloudException, ConcurrentException, InterruptedException, ExecutionException { AsyncResult<Firewall> result = this.getSupport(context.getProjectId()).getFirewall(securityGroupId); Firewall firewall = result.get(); Collection<FirewallRule> firewallRules = firewall.getRules(); Iterable<FirewallRule> iterable = firewallRules; if (firewallRules == null || firewallRules.isEmpty()) { iterable = this.getSupport(context.getProjectId()).getRules(firewall.getProviderFirewallId()).get(); } Iterator<FirewallRule> iterator = iterable.iterator(); while (iterator.hasNext()) { FirewallRule firewallRule = iterator.next(); if (ruleId.equals(firewallRule.getProviderRuleId())) { return toRule(firewallRule, firewall, projectId); } } return rule; }
From source file:com.atlassian.jira.rest.client.internal.async.AsynchronousIssueRestClient.java
@Override public Promise<Iterable<CimProject>> getCreateIssueMetadata(@Nullable GetCreateIssueMetadataOptions options) { final UriBuilder uriBuilder = UriBuilder.fromUri(baseUri).path("issue/createmeta"); if (options != null) { if (options.projectIds != null) { uriBuilder.queryParam("projectIds", Joiner.on(",").join(options.projectIds)); }//from w ww. j av a 2 s . c o m if (options.projectKeys != null) { uriBuilder.queryParam("projectKeys", Joiner.on(",").join(options.projectKeys)); } if (options.issueTypeIds != null) { uriBuilder.queryParam("issuetypeIds", Joiner.on(",").join(options.issueTypeIds)); } final Iterable<String> issueTypeNames = options.issueTypeNames; if (issueTypeNames != null) { for (final String name : issueTypeNames) { uriBuilder.queryParam("issuetypeNames", name); } } final Iterable<String> expandos = options.expandos; if (expandos != null && expandos.iterator().hasNext()) { uriBuilder.queryParam("expand", Joiner.on(",").join(expandos)); } } return getAndParse(uriBuilder.build(), createIssueMetadataJsonParser); }
From source file:net.riezebos.thoth.content.impl.GitContentManager.java
@Override public PagedList<Commit> getCommits(String path, int pageNumber, int pageSize) throws ContentManagerException { path = ThothUtil.stripPrefix(path, "/"); try (Git repos = getRepository()) { Repository repository = repos.getRepository(); List<Commit> commits = new ArrayList<>(); LogCommand log = repos.log();/*from w w w . j a v a 2 s . co m*/ if (path != null) log = log.addPath(path); Iterable<RevCommit> revisions = log.call(); Iterator<RevCommit> iterator = revisions.iterator(); // First skip over the pages we are not interested in int skipCount = (pageNumber - 1) * pageSize; while (skipCount-- > 0 && iterator.hasNext()) iterator.next(); // Now add the revisions while (iterator.hasNext() && commits.size() < pageSize) { RevCommit revCommit = iterator.next(); commits.add(getCommit(repository, revCommit, path)); } PagedList<Commit> pagedList = new PagedList<>(commits, iterator.hasNext()); return pagedList; } catch (IOException | GitAPIException e) { throw new ContentManagerException(e); } }
From source file:msi.gama.kernel.model.GamlModelSpecies.java
@Override public void setChildren(final Iterable<? extends ISymbol> children) { final List forExperiment = new ArrayList<>(); final List<IExperimentPlan> theExperiments = new ArrayList<>(); for (final Iterator<? extends ISymbol> it = children.iterator(); it.hasNext();) { final ISymbol s = it.next(); if (s instanceof IExperimentPlan) { theExperiments.add((IExperimentPlan) s); it.remove();/*from w w w . j av a 2 s.co m*/ } else if (s instanceof AbstractOutputManager) { forExperiment.add(s); it.remove(); } } // Add the variables, etc. to the model super.setChildren(children); // Add the experiments and the default outputs to all experiments for (final IExperimentPlan exp : theExperiments) { addExperiment(exp); exp.setChildren(forExperiment); } }
From source file:com.adobe.communities.ugc.migration.legacyProfileExport.MessagesExportServlet.java
@Override protected void doGet(final SlingHttpServletRequest request, final SlingHttpServletResponse response) throws ServletException, IOException { response.setContentType("application/octet-stream"); final String headerKey = "Content-Disposition"; final String headerValue = "attachment; filename=\"export.zip\""; response.setHeader(headerKey, headerValue); File outFile = null;//from w ww. ja v a 2 s .c o m exportedIds = new HashMap<String, Boolean>(); messagesForExport = new HashMap<String, JSONObject>(); try { outFile = File.createTempFile(UUID.randomUUID().toString(), ".zip"); if (!outFile.canWrite()) { throw new ServletException("Cannot write to specified output file"); } FileOutputStream fos = new FileOutputStream(outFile); BufferedOutputStream bos = new BufferedOutputStream(fos); zip = new ZipOutputStream(bos); responseWriter = new OutputStreamWriter(zip); OutputStream outStream = null; InputStream inStream = null; try { int start = 0; int increment = 100; try { do { Iterable<Message> messages = messagingService.search(request.getResourceResolver(), new MessageFilter(), start, start + increment); if (messages.iterator().hasNext()) { exportMessagesBatch(messages); } else { break; } start += increment; } while (true); } catch (final RepositoryException e) { // do nothing for now } IOUtils.closeQuietly(zip); IOUtils.closeQuietly(bos); IOUtils.closeQuietly(fos); // obtains response's output stream outStream = response.getOutputStream(); inStream = new FileInputStream(outFile); // copy from file to output IOUtils.copy(inStream, outStream); } catch (final IOException e) { throw new ServletException(e); } catch (Exception e) { throw new ServletException(e); } finally { IOUtils.closeQuietly(zip); IOUtils.closeQuietly(bos); IOUtils.closeQuietly(fos); IOUtils.closeQuietly(inStream); IOUtils.closeQuietly(outStream); } } finally { if (outFile != null) { outFile.delete(); } } }
From source file:com.adobe.communities.ugc.migration.export.MessagesExportServlet.java
@Override protected void doGet(@Nonnull final SlingHttpServletRequest request, @Nonnull final SlingHttpServletResponse response) throws ServletException, IOException { response.setContentType("application/octet-stream"); final String headerKey = "Content-Disposition"; final String headerValue = "attachment; filename=\"export.zip\""; response.setHeader(headerKey, headerValue); File outFile = null;/*from ww w . j av a 2 s.co m*/ exportedIds = new HashMap<String, Boolean>(); messagesForExport = new HashMap<String, JSONObject>(); try { outFile = File.createTempFile(UUID.randomUUID().toString(), ".zip"); if (!outFile.canWrite()) { throw new ServletException("Cannot write to specified output file"); } FileOutputStream fos = new FileOutputStream(outFile); BufferedOutputStream bos = new BufferedOutputStream(fos); zip = new ZipOutputStream(bos); responseWriter = new OutputStreamWriter(zip); OutputStream outStream = null; InputStream inStream = null; try { int start = 0; int increment = 100; try { do { Iterable<Message> messages = messagingService.search(request.getResourceResolver(), new MessageFilter(), start, start + increment); if (messages.iterator().hasNext()) { exportMessagesBatch(messages); } else { break; } start += increment; } while (true); } catch (final RepositoryException e) { // do nothing for now } IOUtils.closeQuietly(zip); IOUtils.closeQuietly(bos); IOUtils.closeQuietly(fos); // obtains response's output stream outStream = response.getOutputStream(); inStream = new FileInputStream(outFile); // copy from file to output IOUtils.copy(inStream, outStream); } catch (final IOException e) { throw new ServletException(e); } catch (Exception e) { throw new ServletException(e); } finally { IOUtils.closeQuietly(zip); IOUtils.closeQuietly(bos); IOUtils.closeQuietly(fos); IOUtils.closeQuietly(inStream); IOUtils.closeQuietly(outStream); } } finally { if (outFile != null) { outFile.delete(); } } }
From source file:com.epam.reportportal.extension.bugtracking.jira.JiraStrategy.java
/** * Get list of project users available for assignee field * * @param jiraProject/*from ww w. java 2 s . co m*/ * @return */ private List<AllowedValue> getJiraProjectAssignee(Project jiraProject) { List<AllowedValue> result = Lists.newArrayList(); Iterable<BasicProjectRole> jiraProjectRoles = jiraProject.getProjectRoles(); Iterator<BasicProjectRole> itr = jiraProjectRoles.iterator(); List<String> temp = Lists.newArrayList(); while (itr.hasNext()) { try { ProjectRole role = (ProjectRole) itr.next(); Iterable<RoleActor> actors = role.getActors(); for (RoleActor actor : actors) { if (!temp.contains(actor.getName())) { temp.add(actor.getName()); result.add(new AllowedValue(String.valueOf(actor.getId()), actor.getDisplayName())); } } } catch (Exception e) { LOGGER.error(e.getMessage(), e); } } return result; }
From source file:com.aliyun.odps.graph.local.worker.Worker.java
@SuppressWarnings("unchecked") public void Compute() throws IOException { prepareMsg();//w w w. j a v a 2 s. c o m for (Vertex v : vertices.values()) { Iterable<Writable> msg = mLastStepMessage.get(v); if (v.isHalted() && msg.iterator().hasNext()) { v.wakeUp(); } if (!v.isHalted()) { v.compute(mTaskContext, msg); } } }
From source file:io.orchestrate.client.integration.FetchTest.java
@Test public void fetchEventsForObject() throws InterruptedException, ExecutionException, TimeoutException { final String key = generateString(); final String value = "{}"; final String eventType = generateString(); KvStoreOperation kvStoreOp = new KvStoreOperation(TEST_COLLECTION, key, value); Future<KvMetadata> future_1 = client().execute(kvStoreOp); KvMetadata kvMetadata = future_1.get(3, TimeUnit.SECONDS); EventStoreOperation eventStoreOp = new EventStoreOperation(TEST_COLLECTION, key, eventType, value); Future<Boolean> future_2 = client().execute(eventStoreOp); Boolean success = future_2.get(3, TimeUnit.SECONDS); EventFetchOperation<String> eventFetchOp = new EventFetchOperation<String>(TEST_COLLECTION, key, eventType, String.class); Iterable<Event<String>> results = result(eventFetchOp); assertNotNull(kvMetadata);//from w w w. j a v a 2s . c o m assertNotNull(success); assertTrue(success); assertNotNull(results); Iterator<Event<String>> iter = results.iterator(); assertTrue(iter.hasNext()); Event<String> event = iter.next(); assertEquals(value, event.getValue()); }
From source file:com.auditbucket.test.functional.TestRegistration.java
@Test public void testCompanyUsers() throws DatagioException { createCompanyUsers("mike", 10); Iterable<CompanyUser> users = companyService.getUsers(); assertTrue(users.iterator().hasNext()); }