List of usage examples for java.util Collection addAll
boolean addAll(Collection<? extends E> c);
From source file:hoot.services.writers.osm.ChangesetDbWriter.java
/** * Performs the OSM element database update portion for a changeset upload * request and returns the elements modified * * Unlike OSM, we don't keep track of multiple versions of the same element. * * OSM element udpate process/* w w w . ja v a2s .c o m*/ * * create = insert new modify = update existing + insert new * * hoot element update process * * create = insert new modify = update existing * * @param changesetId * ID of the changeset being uploaded to * @param reviewedItemsChangeset * changeset contents * @return changeset upload response * @throws Exception */ @SuppressWarnings("unchecked") public Document write(final long mapId, final long changesetId, final String reviewedItemsChangeset) throws Exception { log.debug("Uploading data for changeset with ID: " + changesetId + " ..."); Document reviewedItemsChangesetDoc = null; try { reviewedItemsChangesetDoc = (new ChangesetUploadXmlValidator()) .parseAndValidate(reviewedItemsChangeset); } catch (Exception e) { throw new Exception("Error parsing changeset diff data: " + StringUtils.abbreviate(reviewedItemsChangeset, 100) + " (" + e.getMessage() + ")"); } changeset = new Changeset(mapId, changesetId, conn); this.requestChangesetId = changeset.getId(); changeset.verifyAvailability(); if (changeset.requestChangesExceedMaxElementThreshold(reviewedItemsChangesetDoc)) { throw new Exception("Changeset maximum element threshold exceeded."); } requestChangesetMapId = mapId; Collection<XmlSerializable> changesetDiffElements = new ArrayList<XmlSerializable>(); changesetDiffElements.addAll(write(reviewedItemsChangesetDoc)); return (new ChangesetUploadResponseWriter()).writeResponse(changesetId, (List<XmlSerializable>) (List<?>) changesetDiffElements); }
From source file:org.openinfinity.core.async.ParallelServiceActivatorIntegrationTest.java
@Test public void givenKnownCrudInterfacesWhenActivatingParellelServiceCallsThenCallBackResultsMustBeExpected() { ParallelServiceActivator parallelServiceActivator = new ParallelServiceActivator(); parallelServiceActivator.setExecutorServiceAdapter(executorServiceAdapter); final Collection<Account> actualAccounts = new ArrayList<Account>(); String id = "1"; parallelServiceActivator.prepareToQueryAllById(integrationTestService, id, "accounts1") .prepareToQueryAllById(integrationTestService2, id, "accounts2").activate() .onResult("accounts1", new AsyncResultCallback<Collection<Account>>() { @Override//from ww w . j a v a 2 s . c o m public void onResult(Collection<Account> accounts) { assertNotNull(accounts); actualAccounts.addAll(accounts); } }).onResult("accounts2", new AsyncResultCallback<Collection<Account>>() { @Override public void onResult(Collection<Account> accounts) { assertNotNull(accounts); actualAccounts.addAll(accounts); } }); assertEquals(2, actualAccounts.size()); }
From source file:com.panet.imeta.job.JobEntryLoader.java
public boolean readNatives() { try {// w w w .j a va 2s .c o m // annotated classes first ConfigManager<?> jobsAnntCfg = KettleConfig.getInstance().getManager("jobs-annotation-config"); Collection<JobPluginMeta> jobs = jobsAnntCfg.loadAs(JobPluginMeta.class); ConfigManager<?> jobsCfg = KettleConfig.getInstance().getManager("jobs-xml-config"); Collection<JobPluginMeta> cjobs = jobsCfg.loadAs(JobPluginMeta.class); jobs.addAll(cjobs); for (JobPluginMeta job : jobs) if (job.getType() != JobEntryType.NONE) pluginList.add(new JobPlugin(JobPlugin.TYPE_NATIVE, job.getId(), job.getType(), job.getTooltipDesc(), null, null, job.getImageFileName(), job.getClassName().getName(), job.getCategory())); } catch (KettleConfigException e) { e.printStackTrace(); return false; } return true; }
From source file:com.jaspersoft.jasperserver.remote.services.impl.RunReportServiceImpl.java
public void startReportExecution(final ReportExecution reportExecution, ReportExecutionOptions reportExecutionOptions) { final ReportExecutionOptions options = reportExecutionOptions != null ? reportExecutionOptions : reportExecution.getOptions(); reportExecution.setStatus(ExecutionStatus.queued); reportExecution.setReportUnitResult(null); final Locale locale = LocaleContextHolder.getLocale(); final TimeZone timeZone = TimeZoneContextHolder.getTimeZone(); final SecurityContext context = SecurityContextHolder.getContext(); // reset exports if any for (ExportExecution exportExecution : reportExecution.getExports().values()) exportExecution.reset();/*from w ww .j a v a 2s . c om*/ asyncExecutor.execute(new Runnable() { @Override public void run() { LocaleContextHolder.setLocale(locale); TimeZoneContextHolder.setTimeZone(timeZone); SecurityContextHolder.setContext(context); ReportUnitResult reportUnitResult = null; ErrorDescriptor errorDescriptor = null; try { final String reportUnitUri = reportExecution.getReportURI(); final Map<String, String[]> rawParameters = reportExecution.getRawParameters(); // convert parameters from raw strings to objects Map<String, Object> convertedParameters = null; try { convertedParameters = executeInputControlsCascadeWithRawInput(reportUnitUri, rawParameters); } catch (CascadeResourceNotFoundException e) { throw new ResourceNotFoundException( "URI:" + e.getResourceUri() + " Type:" + e.getResourceType()); } catch (InputControlsValidationException e) { // raw type is used in core class. Cast is safe. @SuppressWarnings("unchecked") List<ValidationError> errors = e.getErrors().getErrors(); List<String> errorParameters = new ArrayList<String>(); for (ValidationError error : errors) { errorParameters.add(error.toString()); } throw new RemoteException( new ErrorDescriptor.Builder().setErrorCode("input.controls.validation.error") .setMessage("Input controls validation failure") .setParameters(errorParameters.toArray()).getErrorDescriptor()); } // forward parameters without input control defined for (String currentKey : rawParameters.keySet()) { String[] currentValue = rawParameters.get(currentKey); if (currentValue != null && !convertedParameters.containsKey(currentKey)) { Object valueToForward; if (currentValue.length == 1) { // forward as single value valueToForward = currentValue[0]; } else { // forward as collection Collection<String> collection = new ArrayList<String>(); collection.addAll(Arrays.asList(currentValue)); valueToForward = collection; } convertedParameters.put(currentKey, valueToForward); } } reportExecution.setStatus(ExecutionStatus.execution); reportUnitResult = reportExecutor.runReport(reportUnitUri, convertedParameters, options); } catch (RemoteException e) { errorDescriptor = e.getErrorDescriptor(); } catch (Exception e) { errorDescriptor = errorDescriptorBuildingService.buildErrorDescriptor(e); } if (errorDescriptor != null) { reportExecution.setErrorDescriptor(errorDescriptor); } if (reportUnitResult != null) { final String requestId = options.getRequestId(); if (!requestId.equals(reportUnitResult.getRequestId())) { throw new IllegalStateException( "Report unit request and report unit result should have the same ID. RequestId: " + requestId + " ResultId: " + reportUnitResult.getRequestId()); } reportExecution.setReportUnitResult(reportUnitResult); // wait for report execution to complete for execution status actualization reportUnitResult.getJasperPrint(); actualizeExecutionStatus(reportExecution); } } }); }
From source file:cc.gospy.example.google.GoogleScholarSpider.java
public Collection<String> getResultLinks(final String keyword, final int pageFrom, final int pageTo) { if (pageFrom < 1) throw new IllegalArgumentException(pageFrom + "<" + 1); if (pageFrom >= pageTo) throw new IllegalArgumentException(pageFrom + ">=" + pageTo); final AtomicInteger currentPage = new AtomicInteger(pageFrom); final AtomicBoolean returned = new AtomicBoolean(false); final Collection<String> links = new LinkedHashSet<>(); Gospy googleScholarSpider = Gospy.custom() .setScheduler(//from ww w .j a va2s .c om Schedulers.VerifiableScheduler.custom().setExitCallback(() -> returned.set(true)).build()) .addFetcher(Fetchers.HttpFetcher.custom() .before(request -> request.setConfig( RequestConfig.custom().setProxy(new HttpHost("127.0.0.1", 8118)).build())) .build()) .addProcessor(Processors.XPathProcessor.custom().extract( "//*[@id='gs_ccl_results']/div/div/h3/a/@href", (task, resultList, returnedData) -> { links.addAll(resultList); currentPage.incrementAndGet(); if (pageFrom <= currentPage.get() && currentPage.get() < pageTo) { return Arrays.asList( new Task(String.format("https://scholar.google.com/scholar?start=%d&q=%s", (currentPage.get() - 1) * 10, keyword))); } else { return Arrays.asList(); } }).build()) .build() .addTask(String.format("https://scholar.google.com/scholar?start=%d&q=%s", pageFrom, keyword)); googleScholarSpider.start(); while (!returned.get()) ; // block until spider returned googleScholarSpider.stop(); return links; }
From source file:module.siadap.presentationTier.actions.SiadapProcessCountAction.java
@EntryPoint public ActionForward showUnit(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { SiadapYearWrapper siadapYearWrapper = (SiadapYearWrapper) getRenderedObject("siadapYearWrapper"); if (siadapYearWrapper == null) { //let's try to get the year through the parameter String yearString = getAttribute(request, "year"); if (yearString == null) { ArrayList<Integer> yearsWithConfigs = SiadapYearsFromExistingSiadapConfigurations .getYearsWithExistingConfigs(); if (yearsWithConfigs.contains(new Integer(new LocalDate().getYear()))) { int year = new LocalDate().getYear(); siadapYearWrapper = new SiadapYearWrapper(year); } else { siadapYearWrapper = new SiadapYearWrapper(yearsWithConfigs.get(yearsWithConfigs.size() - 1)); }/*from www .j a v a2 s . c o m*/ } else { siadapYearWrapper = new SiadapYearWrapper(Integer.parseInt(yearString)); } } request.setAttribute("siadapYearWrapper", siadapYearWrapper); SiadapYearConfiguration configuration = siadapYearWrapper.getSiadapYearConfiguration(); if (configuration == null) { return forward("/module/siadap/unit.jsp"); } request.setAttribute("configuration", configuration); SiadapProcessStateEnumWrapper siadapProcessStateToFilter = (SiadapProcessStateEnumWrapper) getRenderedObject( "siadapProcessStateToFilter"); if (siadapProcessStateToFilter == null) { String enumAsParam = request.getParameter("siadapProcessStateEnumToFilterOrdinal"); SiadapProcessStateEnum enumToUse = SiadapStateToShowInCount.getDefaultStateToFilter(); if (!StringUtils.isBlank(enumAsParam)) { enumToUse = SiadapProcessStateEnum.valueOf(enumAsParam); } siadapProcessStateToFilter = new SiadapProcessStateEnumWrapper(enumToUse); } request.setAttribute("siadapProcessStateToFilter", siadapProcessStateToFilter); Unit unit = (Unit) getDomainObject(request, "unitId"); if (unit == null) { unit = configuration.getSiadapStructureTopUnit(); //and let's also get the total number of SIADAPs for this year int siadapsCount = SiadapYearConfiguration.getSiadapYearConfiguration(siadapYearWrapper.getChosenYear()) .getSiadapsSet().size(); int siadapsDefinitiveCount = 0; Map<SiadapProcessStateEnum, Integer> stateCount = new HashMap<SiadapProcessStateEnum, Integer>(); for (Siadap siadap : SiadapRootModule.getInstance().getSiadaps()) { if (siadap.getYear().equals(siadapYearWrapper.getChosenYear())) { siadapsDefinitiveCount++; //let's put them on an HashMap by state TODO use Guave to do this SiadapProcessStateEnum state = siadap.getState(); Integer integer = stateCount.get(state); if (integer == null) { integer = 0; } integer++; stateCount.put(state, integer); } } request.setAttribute("totalDefinitiveCount", stateCount); request.setAttribute("siadapsCount", siadapsCount); request.setAttribute("siadapsDefinitiveCount", siadapsDefinitiveCount); } final Collection<Party> parents = UnitSiadapWrapper.UnitTransverseUtil.getActiveParents(unit, configuration); final Collection<Party> children = UnitSiadapWrapper.UnitTransverseUtil.getActiveChildren(unit, configuration); OrganizationChart<Party> chart = new OrganizationChart<Party>(unit, parents, children, 3); request.setAttribute("chart", chart); final Collection<Accountability> workerAccountabilities = UnitSiadapWrapper.UnitTransverseUtil .getActiveChildrenWorkers(unit, configuration); request.setAttribute("workerAccountabilities", workerAccountabilities); UnitSiadapWrapper unitSiadapWrapper = new UnitSiadapWrapper(unit, configuration.getYear()); final Person unitResponsible = unitSiadapWrapper.getEvaluationResponsible(); request.setAttribute("unitResponsible", unitResponsible); final Collection<Person> unitHarmonizers = new TreeSet<Person>(Party.COMPARATOR_BY_NAME); UnitSiadapWrapper harmonizationUnit = new UnitSiadapWrapper(unitSiadapWrapper.getHarmonizationUnit(), configuration.getYear()); if (harmonizationUnit.isValidHarmonizationUnit()) { unitHarmonizers.addAll(harmonizationUnit.getHarmonizationResponsibles()); } request.setAttribute("unitHarmonizers", unitHarmonizers); return forward("/module/siadap/unit.jsp"); }
From source file:com.algoTrader.entity.marketData.BarDaoBase.java
/** * {@inheritDoc}//w w w. j a va2 s.co m */ @Override public final Collection toBarVOCollection(Collection<?> entities) { Collection result = new ArrayList<BarVO>(); if (entities != null) { CollectionUtils.transform(entities, this.BARVO_TRANSFORMER); result.addAll((Collection) entities); } return result; }
From source file:edu.stanford.muse.email.MuseEmailFetcher.java
public Collection<String> getDataErrors() { Collection<String> result = new LinkedHashSet<>(); if (fetchers == null) return result; for (MTEmailFetcher fetcher : fetchers) { if (fetcher != null && fetcher.getDataErrors() != null) result.addAll(fetcher.getDataErrors()); }//from w w w . j ava 2 s . c o m return result; }
From source file:com.cloudera.oryx.ml.serving.als.model.ALSServingModel.java
/** * Like {@link #pruneX(Collection)} and {@link #pruneY(Collection)} but prunes the * known-items data structure./* www . j a v a 2s . c o m*/ */ void pruneKnownItems(Collection<String> users, final Collection<String> items) { // Keep all users in the new model, or, that have been added since last model Lock xWriteLock = xLock.writeLock(); xWriteLock.lock(); try { knownItems.removeIf(new KeyOnlyBiPredicate<>(new AndPredicate<>(new NotContainsPredicate<>(users), new NotContainsPredicate<>(recentNewUsers)))); } finally { xWriteLock.unlock(); } // This will be easier to quickly copy the whole (smallish) set rather than // deal with locks below final Collection<String> allRecentKnownItems = new HashSet<>(); for (int partition = 0; partition < Y.length; partition++) { Lock yWriteLock = yLocks[partition].writeLock(); yWriteLock.lock(); try { allRecentKnownItems.addAll(recentNewItems[partition]); } finally { yWriteLock.unlock(); } } Lock xReadLock = xLock.readLock(); xReadLock.lock(); try { for (ObjSet<String> knownItemsForUser : knownItems.values()) { synchronized (knownItemsForUser) { knownItemsForUser.removeIf(new Predicate<String>() { @Override public boolean test(String value) { return !items.contains(value) && !allRecentKnownItems.contains(value); } }); } } } finally { xReadLock.unlock(); } }
From source file:org.openinfinity.core.async.ParallelServiceActivatorIntegrationTest.java
@Test public void givenKnownCrudInterfacesWhenActivatingParellelServiceCallsThenCallBackResultsMustBeExpectedWithoutIdOnProperaccount() { ParallelServiceActivator parallelServiceActivator = new ParallelServiceActivator(); parallelServiceActivator.setExecutorServiceAdapter(executorServiceAdapter); String id = "testname"; final Collection<Account> actualAccounts = new ArrayList<Account>(); parallelServiceActivator.prepareToQueryAllById(integrationTestService, id) .prepareToQueryAllById(integrationTestService2, id).activate(); Collection<Account> accounts1 = parallelServiceActivator.loadResult(); Collection<Account> accounts2 = parallelServiceActivator.loadResult(); assertNotNull(accounts1);//w ww . j a v a2 s. co m assertEquals(1, accounts2.size()); for (Account account : accounts1) { assertEquals("testname", account.getId()); actualAccounts.addAll(accounts1); } for (Account account : accounts2) { assertEquals("testname", account.getId()); actualAccounts.addAll(accounts2); } assertNotNull(accounts1); assertEquals(2, actualAccounts.size()); }