List of usage examples for java.util.stream Collectors joining
public static Collector<CharSequence, ?, String> joining(CharSequence delimiter)
From source file:io.bitsquare.gui.util.BSFormatter.java
public String languageCodesToString(List<String> languageLocales) { return languageLocales.stream().map(LanguageUtil::getDisplayName).collect(Collectors.joining(", ")); }
From source file:com.ikanow.aleph2.data_import_manager.analytics.utils.TestAnalyticTriggerCrudUtils.java
@Test public void test_activateUpdateTimesAndSuspend() throws InterruptedException { assertEquals(0, _test_crud.countObjects().join().intValue()); final DataBucketBean bucket = buildBucket("/test/active/trigger", true); // 1) Store as above {/* w w w .ja v a 2 s. c o m*/ final Stream<AnalyticTriggerStateBean> test_stream = AnalyticTriggerBeanUtils .generateTriggerStateStream(bucket, false, Optional.of("test_host")); final List<AnalyticTriggerStateBean> test_list = test_stream.collect(Collectors.toList()); System.out.println("Resources = \n" + test_list.stream() .map(t -> BeanTemplateUtils.toJson(t).toString()).collect(Collectors.joining("\n"))); assertEquals(8L, test_list.size());//(8 not 7 because we only dedup at the DB) // 4 internal dependencies assertEquals(4L, test_list.stream().filter(t -> null != t.job_name()).count()); // 5 external dependencies assertEquals(4L, test_list.stream().filter(t -> null == t.job_name()).count()); final Map<Tuple2<String, String>, List<AnalyticTriggerStateBean>> grouped_triggers = test_list.stream() .collect(Collectors.groupingBy(t -> Tuples._2T(t.bucket_name(), null))); AnalyticTriggerCrudUtils.storeOrUpdateTriggerStage(bucket, _test_crud, grouped_triggers).join(); assertEquals(7L, _test_crud.countObjects().join().intValue()); } //DEBUG //printTriggerDatabase(); // Sleep to change times Thread.sleep(100L); //(activate) bucket.analytic_thread().jobs().stream().filter(job -> Optional.ofNullable(job.enabled()).orElse(true)) .forEach(job -> { AnalyticTriggerCrudUtils.createActiveBucketOrJobRecord(_test_crud, bucket, Optional.of(job), Optional.of("test_host")); }); // 2) Activate then save suspended - check suspended goes to pending { final Stream<AnalyticTriggerStateBean> test_stream = AnalyticTriggerBeanUtils .generateTriggerStateStream(bucket, true, Optional.of("test_host")); final List<AnalyticTriggerStateBean> test_list = test_stream.collect(Collectors.toList()); assertTrue("All suspended", test_list.stream().filter(t -> t.is_bucket_suspended()).findFirst().isPresent()); final Map<Tuple2<String, String>, List<AnalyticTriggerStateBean>> grouped_triggers = test_list.stream() .collect(Collectors.groupingBy(t -> Tuples._2T(t.bucket_name(), null))); //DEBUG //printTriggerDatabase(); assertEquals(13L, _test_crud.countObjects().join().intValue()); // ie 5 active jobs + 1 active bucket, 4 job dependencies, 3 external triggers AnalyticTriggerCrudUtils.storeOrUpdateTriggerStage(bucket, _test_crud, grouped_triggers).join(); //DEBUG //printTriggerDatabase(); assertEquals(17L, _test_crud.countObjects().join().intValue()); // ie 5 active jobs, + 1 active bucket, 4 job dependencies x2 (pending/non-pending), the 3 external triggers get overwritten assertEquals(7L, _test_crud.countObjectsBySpec(CrudUtils.allOf(AnalyticTriggerStateBean.class) .when(AnalyticTriggerStateBean::is_bucket_suspended, true)).join().intValue()); } // Sleep to change times Thread.sleep(100L); // 3) De-activate and check reverts to pending { AnalyticTriggerCrudUtils.deleteActiveJobEntries(_test_crud, bucket, bucket.analytic_thread().jobs(), Optional.of("test_host")).join(); bucket.analytic_thread().jobs().stream().forEach(job -> { //System.out.println("BEFORE: " + job.name() + ": " + _test_crud.countObjects().join().intValue()); AnalyticTriggerCrudUtils .updateCompletedJob(_test_crud, bucket.full_name(), job.name(), Optional.of("test_host")) .join(); //System.out.println(" AFTER: " + job.name() + ": " + _test_crud.countObjects().join().intValue()); }); assertEquals(8L, _test_crud.countObjects().join().intValue()); assertEquals(7L, _test_crud.countObjectsBySpec(CrudUtils.allOf(AnalyticTriggerStateBean.class) .when(AnalyticTriggerStateBean::is_pending, false)).join().intValue()); AnalyticTriggerCrudUtils .deleteActiveBucketRecord(_test_crud, bucket.full_name(), Optional.of("test_host")).join(); assertEquals(7L, _test_crud.countObjects().join().intValue()); } }
From source file:org.apache.nifi.minifi.c2.service.ConfigService.java
private Pair<MediaType, ConfigurationProvider> getProvider(List<MediaType> acceptValues) throws ConfigurationProviderException { List<Pair<MediaType, ConfigurationProvider>> mediaTypeList; try {/*from w ww . j av a 2 s . c o m*/ mediaTypeList = this.configurationProviderInfo.get().getMediaTypeList(); } catch (ConfigurationProviderException.Wrapper e) { throw e.unwrap(); } for (MediaType accept : acceptValues) { for (Pair<MediaType, ConfigurationProvider> pair : mediaTypeList) { MediaType mediaType = pair.getFirst(); if (accept.isCompatible(mediaType)) { return new Pair<>(mediaType, pair.getSecond()); } } } throw new WebApplicationException(Response.status(406) .entity("Unable to find configuration provider for " + "\"Accept: " + acceptValues.stream().map(Object::toString).collect(Collectors.joining(", ")) + "\" supported media types are " + mediaTypeList.stream().map(Pair::getFirst) .map(Object::toString).collect(Collectors.joining(", "))) .build()); }
From source file:com.adobe.acs.commons.replication.status.impl.JcrPackageReplicationStatusEventHandler.java
private void setReplicationStatus(JcrPackage jcrPackage, String replicatedBy, ResourceResolver resourceResolver) throws RepositoryException { final List<Resource> resources = new ArrayList<>(); final String packageId; try {//from w ww . j a v a 2s. c om JcrPackageDefinition packageDefinition = jcrPackage.getDefinition(); if (packageDefinition == null) { throw new RepositoryException( "Could not determine the ID for just replicated package (package invalid?)"); } else { packageId = packageDefinition.getId().toString(); } } catch (RepositoryException e) { throw new RepositoryException( "Could not determine the ID for just replicated package (package invalid?).", e); } try { for (final String packagePath : packageHelper.getContents(jcrPackage)) { final Resource resource = resourceResolver.getResource(packagePath); if (this.accept(resource)) { resources.add(resource); } } } catch (RepositoryException | PackageException | IOException e) { throw new RepositoryException( "Could not retrieve the Packages contents for package '" + packageId + "'", e); } try { if (resources.size() > 0) { replicationStatusManager.setReplicationStatus(resourceResolver, replicatedBy, getJcrPackageLastModified(jcrPackage), ReplicationStatusManager.Status.ACTIVATED, resources.toArray(new Resource[resources.size()])); log.info("Updated Replication Status for JCR Package: {}", packageId); } else { log.info( "Could not find any resources in JCR Package [ {} ] that are candidates to have their Replication Status updated", packageId); } } catch (RepositoryException | IOException e) { // enrich exception with path information (limited to 10 paths only) String paths = resources.stream().map(r -> r.getPath()).limit(10).collect(Collectors.joining(", ")); throw new RepositoryException("Exception occurred updating replication status for contents of package '" + packageId + "' covering paths: '" + paths + ", ...'", e); } }
From source file:nu.yona.server.analysis.service.AnalysisEngineService.java
private void logMultipleOverlappingActivities(ActivityPayload payload, GoalDto matchingGoal, DayActivity dayActivity, List<Activity> overlappingOfSameApp) { String overlappingActivitiesKind = payload.application.isPresent() ? MessageFormat.format("app activities of ''{0}''", payload.application.get()) : "network activities"; String overlappingActivities = overlappingOfSameApp.stream().map(Activity::toString) .collect(Collectors.joining(", ")); logger.warn(//from w w w . ja va 2 s .co m "Multiple overlapping {} found. The payload has start time {} and end time {}. The day activity ID is {} and the activity category ID is {}. The overlapping activities are: {}.", overlappingActivitiesKind, payload.startTime.toLocalDateTime(), payload.endTime.toLocalDateTime(), dayActivity.getId(), matchingGoal.getActivityCategoryId(), overlappingActivities); }
From source file:grakn.core.server.session.reader.GraknCqlBridgeRecordReader.java
private String makeColumnList(Collection<String> columns) { return columns.stream().map(this::quote).collect(Collectors.joining(",")); }
From source file:com.epam.reportportal.extension.bugtracking.rally.RallyStrategy.java
private void checkResponse(Response response) { if (response.getErrors().length > 0) { throw new ReportPortalException("Error during interacting with Rally: " + Stream.of(response.getErrors()).collect(Collectors.joining(" "))); }//ww w.j a v a 2 s. com }
From source file:me.ixfan.wechatkit.user.UserManager.java
/** * ????//from w ww .ja v a 2 s.co m * * @param tagId ID * @param openIds ?OpenID?openid?50 * @throws WeChatApiErrorException API?? */ public void batchTaggingUsersWithTag(int tagId, List<String> openIds) throws WeChatApiErrorException { Args.notNegative(tagId, "Tag ID"); Args.notEmpty(openIds, "OpenIds"); final String url = WeChatConstants.WECHAT_POST_BATCH_TAGGING.replace("${ACCESS_TOKEN}", super.tokenManager.getAccessToken()); final String jsonData = "{\"openid_list\":[${OPENIDS}],\"tagid\":${TAG_ID}}"; JsonObject jsonResp; try { jsonResp = HttpClientUtil.sendPostRequestWithJsonBody(url, jsonData.replace("${OPENIDS}", openIds.stream().collect(Collectors.joining(","))) .replace("${TAG_ID}", String.valueOf(tagId))); } catch (IOException e) { throw new RuntimeException(e); } if (jsonResp.get("errcode").getAsInt() != 0) { throw new WeChatApiErrorException(jsonResp.get("errcode").getAsInt(), jsonResp.get("errmsg").getAsString()); } }
From source file:chatbot.Chatbot.java
/** ************************************************************************************************** * Remove stop words from a sentence.//from w w w. j a va 2 s .c om * @return a string that is the sentence minus the stop words. */ public String removeStopWords(String sentence) { if (isNullOrEmpty(sentence)) return ""; String result = ""; ArrayList<String> al = splitToArrayList(sentence); if (al == null) return ""; return al.stream().filter(s -> !stopwords.contains(s.toLowerCase())).collect(Collectors.joining(" ")); }
From source file:com.compomics.colims.client.controller.AnalyticalRunsSearchSettingsController.java
/** * Set the analytical run details and search settings by given analytical * run Set empty if run is null/*w w w . j a v a 2 s .com*/ * * @param analyticalRun */ public void setAnalyticalRunDetailsSearchSettings(AnalyticalRun analyticalRun) { if (analyticalRun != null) { // fetch all needed fields fetchAnalyticalRun(analyticalRun); analyticalRunsSearchSettingsDialog.getNameTextField().setText(analyticalRun.getName()); analyticalRunsSearchSettingsDialog.getStartDateTextField() .setText(analyticalRun.getStartDate().toString()); analyticalRunsSearchSettingsDialog.getInstrumentTextField() .setText(analyticalRun.getInstrument().getName()); if (analyticalRun.getStorageLocation() != null) { analyticalRunsSearchSettingsDialog.getLocationTextField() .setText(analyticalRun.getStorageLocation()); } else { analyticalRunsSearchSettingsDialog.getLocationTextField().setText(""); } if (analyticalRun.getId() != null) { analyticalRunsSearchSettingsDialog.getAttachmentsTextField().setText(analyticalRun.getBinaryFiles() .stream().map(binaryFile -> binaryFile.toString()).collect(Collectors.joining(", "))); } else { analyticalRunsSearchSettingsDialog.getAttachmentsTextField().setText(""); } analyticalRunsSearchSettingsDialog.getSearchEngineTextField() .setText(analyticalRun.getSearchAndValidationSettings().getSearchEngine().toString()); analyticalRun.getSearchAndValidationSettings().getSearchSettingsHasFastaDbs().forEach(fastaDb -> { if (fastaDb.getFastaDbType().equals(FastaDbType.PRIMARY)) { analyticalRunsSearchSettingsDialog.getFastaNameTextField() .setText(fastaDb.getFastaDb().getFileName()); } }); analyticalRunsSearchSettingsDialog.getEnzymeTextField() .setText(analyticalRun.getSearchAndValidationSettings().getSearchParameters().getEnzymes()); analyticalRunsSearchSettingsDialog.getMaxMissedCleTextField() .setText(analyticalRun.getSearchAndValidationSettings().getSearchParameters() .getNumberOfMissedCleavages().toString()); analyticalRunsSearchSettingsDialog.getPreMasTolTextField().setText(analyticalRun .getSearchAndValidationSettings().getSearchParameters().getPrecMassTolerance().toString()); } else { analyticalRunsSearchSettingsDialog.getNameTextField().setText(""); analyticalRunsSearchSettingsDialog.getStartDateTextField().setText(""); analyticalRunsSearchSettingsDialog.getInstrumentTextField().setText(""); analyticalRunsSearchSettingsDialog.getLocationTextField().setText(""); analyticalRunsSearchSettingsDialog.getAttachmentsTextField().setText(""); analyticalRunsSearchSettingsDialog.getSearchEngineTextField().setText(""); analyticalRunsSearchSettingsDialog.getFastaNameTextField().setText(""); analyticalRunsSearchSettingsDialog.getEnzymeTextField().setText(""); analyticalRunsSearchSettingsDialog.getMaxMissedCleTextField().setText(""); analyticalRunsSearchSettingsDialog.getPreMasTolTextField().setText(""); } }