List of usage examples for java.util SortedSet forEach
default void forEach(Consumer<? super T> action)
From source file:Main.java
public static void main(String[] args) { // Sort the names based on their length, placing null first SortedSet<String> names = new TreeSet<>(Comparator.nullsFirst(Comparator.comparing(String::length))); names.add("XML"); names.add("CSS"); names.add("HTML"); names.add(null); // Adds a null // Print the names names.forEach(System.out::println); }
From source file:Main.java
public static void main(String[] args) { SortedSet<Person> personsById = new TreeSet<>(Comparator.comparing(Person::getId)); personsById.add(new Person(1, "X")); personsById.add(new Person(2, "Z")); personsById.add(new Person(3, "A")); personsById.add(new Person(4, "C")); personsById.add(new Person(4, "S")); // A duplicate Person System.out.println("Persons by Id:"); personsById.forEach(System.out::println); SortedSet<Person> personsByName = new TreeSet<>(Comparator.comparing(Person::getName)); personsByName.add(new Person(1, "X")); personsByName.add(new Person(2, "Z")); personsByName.add(new Person(3, "A")); personsByName.add(new Person(4, "C")); System.out.println("Persons by Name: "); personsByName.forEach(System.out::println); }
From source file:fi.helsinki.opintoni.config.CacheConfiguration.java
@PreDestroy public void destroy() { log.debug("Remove Cache Manager metrics"); SortedSet<String> names = metricRegistry.getNames(); names.forEach(metricRegistry::remove); log.debug("Closing Cache Manager"); cacheManager.shutdown();/*from ww w .j ava2s . c om*/ }
From source file:org.obiba.mica.micaConfig.service.helper.DceIdAggregationMetaDataHelper.java
@Cacheable(value = "aggregations-metadata", key = "'dce'") public Map<String, AggregationMetaDataProvider.LocalizedMetaData> getDces() { try {/* w w w .j a v a 2 s .c o m*/ List<BaseStudy> studies = sudo( () -> publishedStudyService.findAllByClassName(Study.class.getSimpleName())); Map<String, AggregationMetaDataProvider.LocalizedMetaData> map = Maps.newHashMap(); studies.forEach(study -> { SortedSet<Population> pops = study.getPopulations(); if (pops == null) return; pops.forEach(population -> { SortedSet<DataCollectionEvent> dces = population.getDataCollectionEvents(); if (dces == null) return; dces.forEach(dce -> mapIdToMetadata(map, study, population, dce)); }); }); sudo(() -> publishedStudyService.findAllByClassName(HarmonizationStudy.class.getSimpleName())).stream() .forEach(hStudy -> hStudy.getPopulations().stream() .forEach(population -> mapIdToMetadata(map, hStudy, population, null))); return map; } catch (Exception e) { log.debug("Could not build DCE aggregation metadata {}", e); return Maps.newHashMap(); } }
From source file:org.obiba.mica.web.model.StudySummaryDtos.java
@NotNull public Mica.StudySummaryDto.Builder asHarmonizationStudyDtoBuilder(@NotNull HarmonizationStudy study, boolean isPublished, long variablesCount) { Mica.StudySummaryDto.Builder builder = Mica.StudySummaryDto.newBuilder(); builder.setPublished(isPublished);//from w w w. j a va 2s. co m builder.setId(study.getId()) // .setTimestamps(TimestampsDtos.asDto(study)) // .addAllName(localizedStringDtos.asDto(study.getName())) // .addAllAcronym(localizedStringDtos.asDto(study.getAcronym())) // .addAllObjectives(localizedStringDtos.asDto(study.getObjectives())) .setVariables(isPublished ? variablesCount : 0); if (study.getLogo() != null) builder.setLogo(attachmentDtos.asDto(study.getLogo())); SortedSet<Population> populations = study.getPopulations(); if (populations != null) { populations.forEach(population -> builder.addPopulationSummaries(asDto(population))); } builder.setPermissions(permissionsDtos.asDto(study)); return builder; }
From source file:org.obiba.mica.web.model.StudySummaryDtos.java
@NotNull public Mica.StudySummaryDto.Builder asCollectionStudyDtoBuilder(@NotNull Study study, boolean isPublished, long variablesCount) { Mica.StudySummaryDto.Builder builder = Mica.StudySummaryDto.newBuilder(); builder.setPublished(isPublished);//from w w w . ja v a 2 s . co m builder.setId(study.getId()) // .setTimestamps(TimestampsDtos.asDto(study)) // .addAllName(localizedStringDtos.asDto(study.getName())) // .addAllAcronym(localizedStringDtos.asDto(study.getAcronym())) // .addAllObjectives(localizedStringDtos.asDto(study.getObjectives())) .setVariables(isPublished ? variablesCount : 0); if (study.getLogo() != null) builder.setLogo(attachmentDtos.asDto(study.getLogo())); addDesignInBuilderIfPossible(study.getModel(), builder); addTargetNumberInBuilderIfPossible(study.getModel(), builder); Collection<String> countries = new HashSet<>(); SortedSet<Population> populations = study.getPopulations(); if (populations != null) { countries.addAll(extractCountries(populations)); populations.forEach(population -> builder.addPopulationSummaries(asDto(population))); addDataSources(builder, populations); } builder.setPermissions(permissionsDtos.asDto(study)); builder.addAllCountries(countries); return builder; }
From source file:io.wcm.caconfig.editor.impl.ConfigNamesServlet.java
private JSONArray getConfigNames(Resource contextResource) throws JSONException { JSONArray output = new JSONArray(); SortedSet<String> configNames = configManager.getConfigurationNames(); SortedSet<JSONObject> sortedResult = new TreeSet<>(new Comparator<JSONObject>() { @Override//from w w w . ja v a 2s .c o m public int compare(JSONObject o1, JSONObject o2) { String label1 = o1.optString("label"); String label2 = o2.optString("label"); if (StringUtils.equals(label1, label2)) { String configName1 = o1.optString("configName"); String configName2 = o2.optString("configName"); return configName1.compareTo(configName2); } return label1.compareTo(label2); } }); for (String configName : configNames) { ConfigurationMetadata metadata = configManager.getConfigurationMetadata(configName); if (metadata != null) { JSONObject item = new JSONObject(); item.put("configName", configName); item.putOpt("label", metadata.getLabel()); item.putOpt("description", metadata.getDescription()); item.put("collection", metadata.isCollection()); item.put("exists", hasConfig(contextResource, configName, metadata.isCollection())); item.put("allowAdd", allowAdd(contextResource, configName)); sortedResult.add(item); } } sortedResult.forEach(output::put); return output; }
From source file:org.apache.storm.daemon.logviewer.utils.LogCleaner.java
/** * Delete old log dirs for which the workers are no longer alive. *//*from ww w. j a v a 2 s. c o m*/ @Override public void run() { try { int nowSecs = Time.currentTimeSecs(); Set<File> oldLogDirs = selectDirsForCleanup(nowSecs * 1000); SortedSet<File> deadWorkerDirs = getDeadWorkerDirs(nowSecs, oldLogDirs); LOG.debug("log cleanup: now={} old log dirs {} dead worker dirs {}", nowSecs, oldLogDirs.stream().map(File::getName).collect(joining(",")), deadWorkerDirs.stream().map(File::getName).collect(joining(","))); deadWorkerDirs.forEach(Unchecked.consumer(dir -> { String path = dir.getCanonicalPath(); LOG.info("Cleaning up: Removing {}", path); try { Utils.forceDelete(path); cleanupEmptyTopoDirectory(dir); } catch (Exception ex) { LOG.error(ex.getMessage(), ex); } })); perWorkerDirCleanup(maxPerWorkerLogsSizeMb * 1024 * 1024); globalLogCleanup(maxSumWorkerLogsSizeMb * 1024 * 1024); } catch (Exception ex) { LOG.error("Exception while cleaning up old log.", ex); } }
From source file:org.wso2.msf4j.service.TestMicroservice.java
@Path("/sortedSetQueryParam") @GET/*from w ww .ja v a 2 s .c om*/ public String testSortedSetQueryParam(@QueryParam("id") SortedSet<Integer> ids) { StringBuilder response = new StringBuilder(); ids.forEach(id -> response.append(id).append(",")); if (response.length() > 0) { response.setLength(response.length() - 1); } return response.toString(); }
From source file:org.zaproxy.gradle.UpdateAddOnZapVersionsEntries.java
@TaskAction public void update() throws Exception { if (checksumAlgorithm.get().isEmpty()) { throw new IllegalArgumentException("The checksum algorithm must not be empty."); }//from w w w . j ava 2 s . com if (fromFile.isPresent()) { if (fromUrl.isPresent()) { throw new IllegalArgumentException( "Only one of the properties, URL or file, can be set at the same time."); } if (!downloadUrl.isPresent()) { throw new IllegalArgumentException("The download URL must be provided when specifying the file."); } } else if (!fromUrl.isPresent()) { throw new IllegalArgumentException("Either one of the properties, URL or file, must be set."); } if (downloadUrl.get().isEmpty()) { throw new IllegalArgumentException("The download URL must not be empty."); } try { URL url = new URL(downloadUrl.get()); if (!HTTPS_SCHEME.equalsIgnoreCase(url.getProtocol())) { throw new IllegalArgumentException( "The provided download URL does not use HTTPS scheme: " + url.getProtocol()); } } catch (IOException e) { throw new IllegalArgumentException("Failed to parse the download URL: " + e.getMessage(), e); } Path addOn = getAddOn(); String addOnId = extractAddOnId(addOn.getFileName().toString()); AddOnEntry addOnEntry = new AddOnEntry(addOnId, new AddOnConfBuilder(addOn, downloadUrl.get(), checksumAlgorithm.get(), releaseDate.get()).build()); for (File zapVersionsFile : into.getFiles()) { if (!Files.isRegularFile(zapVersionsFile.toPath())) { throw new IllegalArgumentException("The provided path is not a file: " + zapVersionsFile); } SortedSet<AddOnEntry> addOns = new TreeSet<>(); XMLConfiguration zapVersionsXml = new CustomXmlConfiguration(); zapVersionsXml.load(zapVersionsFile); Arrays.stream(zapVersionsXml.getStringArray(ADD_ON_ELEMENT)).filter(id -> !addOnId.equals(id)) .forEach(id -> { String key = ADD_ON_NODE_PREFIX + id; addOns.add(new AddOnEntry(id, zapVersionsXml.configurationAt(key))); zapVersionsXml.clearTree(key); }); zapVersionsXml.clearTree(ADD_ON_ELEMENT); zapVersionsXml.clearTree(ADD_ON_NODE_PREFIX + addOnId); addOns.add(addOnEntry); addOns.forEach(e -> { zapVersionsXml.addProperty(ADD_ON_ELEMENT, e.getAddOnId()); zapVersionsXml.addNodes(ADD_ON_NODE_PREFIX + e.getAddOnId(), e.getData().getRootNode().getChildren()); }); zapVersionsXml.save(zapVersionsFile); } }