List of usage examples for java.util Collection forEach
default void forEach(Consumer<? super T> action)
From source file:Main.java
public static <T> boolean hasCycle(Collection<T> vertices, Function<T, Collection<T>> neighborExtractor) { Map<T, Collection<T>> parents = vertices.stream().collect(toMap(identity(), v -> new ArrayList<T>())); vertices.forEach( v -> nullSafeCollection(neighborExtractor.apply(v)).forEach(child -> parents.get(child).add(v))); Set<T> roots = vertices.stream().filter(v -> parents.get(v).isEmpty()).collect(Collectors.toSet()); while (!roots.isEmpty()) { T root = roots.iterator().next(); roots.remove(root);//from ww w. j a va 2 s .co m parents.remove(root); nullSafeCollection(neighborExtractor.apply(root)).forEach(child -> { parents.get(child).remove(root); if (parents.get(child).isEmpty()) { roots.add(child); } }); } return !parents.isEmpty(); }
From source file:org.sonar.server.qualityprofile.ws.SearchDataLoader.java
private static void addAll(Map<String, QProfile> qualityProfiles, Collection<QProfile> list) { list.forEach(qualityProfile -> qualityProfiles.put(qualityProfile.language(), qualityProfile)); }
From source file:org.sonar.server.qualityprofile.ws.SearchDataLoader.java
private static void addAllFromDto(Map<String, QProfile> qualityProfiles, Collection<QualityProfileDto> list) { list.forEach(qualityProfile -> qualityProfiles.put(qualityProfile.getLanguage(), QualityProfileDtoToQProfile.INSTANCE.apply(qualityProfile))); }
From source file:no.ntnu.okse.web.controller.LogController.java
/** * Private helper method that updates information regarding which log files that are available */// www . j a v a 2 s . c o m private static void updateAvailableLogFiles() { File dir = new File("logs"); Collection<File> files = FileUtils.listFiles(dir, TrueFileFilter.INSTANCE, TrueFileFilter.INSTANCE); files.forEach(f -> { if (!fileNames.containsValue(f.getName())) { if (f.getName().equalsIgnoreCase("okse.log")) { fileNames.put(0, f.getName()); } else { fileNames.put(fileID++, f.getName()); } } }); }
From source file:io.tilt.minka.domain.ShardDuty.java
public static String toStringIds(Collection<ShardDuty> duties) { final StringBuilder sb = new StringBuilder(); duties.forEach(i -> sb.append(i.getDuty().getId()).append(", ")); return sb.toString(); }
From source file:io.tilt.minka.domain.ShardDuty.java
public static String toStringBrief(Collection<ShardDuty> duties) { final StringBuilder sb = new StringBuilder(); duties.forEach(i -> sb.append(i.toBrief()).append(", ")); return sb.toString(); }
From source file:io.tilt.minka.domain.ShardDuty.java
public static String toString(Collection<ShardDuty> duties) { final StringBuilder sb = new StringBuilder(); duties.forEach(i -> sb.append(i.toString()).append(", ")); return sb.toString(); }
From source file:com.anathema_roguelike.main.utilities.Utils.java
public static <T extends HasWeightedProbability> T getWeightedRandomSample(Collection<T> col) { ArrayList<Pair<T, Double>> list = new ArrayList<>(); col.forEach(i -> { list.add(new Pair<>(i, i.getWeightedProbability())); });//w ww. java 2 s . c om return new EnumeratedDistribution<>(list).sample(); }
From source file:com.qwazr.QwazrConfiguration.java
private static Set<String> buildGroups(Collection<String> groupCollection) { if (groupCollection == null || groupCollection.isEmpty()) return null; Set<String> groups = new HashSet<>(); groupCollection.forEach((g) -> groups.add(g.trim())); return groups; }
From source file:org.apache.geode.geospatial.function.GeoQueryFunction.java
public static final List<PdxInstance> query(String wellKnowText) { //Use the default connection pool to make the request on. If we were connected to more then one //distributed system we would have ask for right system. Since we are connected to only one we are fine // with default. Pool pool = ClientCacheFactory.getAnyInstance().getDefaultPool(); //Since the spatial data is large and it partitioned over N servers we need to query all of the servers at the //same time. On servers tell GemFire to execute the specifed function on all servers. Execution execution = FunctionService.onServers(pool).withArgs(wellKnowText); //We cause the execution to happen asynchronously Collection<Collection<PdxInstance>> resultCollector = (Collection<Collection<PdxInstance>>) execution .execute(ID).getResult();//from w w w . ja v a2 s.c o m ArrayList<PdxInstance> results = new ArrayList<>(); resultCollector.forEach(pdxInstanceCollection -> { if (pdxInstanceCollection != null) { pdxInstanceCollection.forEach(locationEvent -> { if (locationEvent != null) { results.add(locationEvent); } }); } }); return results; }