List of usage examples for java.util.stream Collectors toCollection
public static <T, C extends Collection<T>> Collector<T, ?, C> toCollection(Supplier<C> collectionFactory)
From source file:com.olacabs.fabric.compute.sources.kafka.impl.TransactionManager.java
private List<EventSetMeta> readExistingTransactions() throws Exception { final String txnLocation = path(); List<String> txnIds = curator.getChildren().forPath(txnLocation); Collections.sort(txnIds, (lhs, rhs) -> Long.compare(Long.parseLong(lhs), Long.parseLong(rhs))); return txnIds.stream().map(txnId -> { try {//from w w w. jav a 2 s. c om return mapper.readValue(curator.getData().forPath(txnPath(txnId)), EventSetMeta.class); } catch (Exception e) { throw new RuntimeException(e); } }).collect(Collectors.toCollection(ArrayList::new)); }
From source file:mesclasses.handlers.ModelHandler.java
public ObservableList<Cours> getCoursForClasse(Classe classe) { return data.getCours().stream().filter(c -> c.getClasse().getName().equals(classe.getName())) .collect(Collectors.toCollection(FXCollections::observableArrayList)); }
From source file:net.techcable.sonarpet.utils.ProfileUtils.java
private static List<PlayerProfile> postNames(List<String> names) { //This one doesn't cache JSONArray request = names.stream().collect(Collectors.toCollection(JSONArray::new)); Object rawResponse = postJson("https://api.mojang.com/profiles/minecraft", request); if (!(rawResponse instanceof JSONArray)) return null; JSONArray response = (JSONArray) rawResponse; List<PlayerProfile> profiles = new ArrayList<>(); for (Object rawEntry : response) { if (!(rawEntry instanceof JSONObject)) return null; JSONObject entry = (JSONObject) rawEntry; PlayerProfile profile = deserializeProfile(entry); if (profile != null) profiles.add(profile);/* w w w . j a v a 2s . c o m*/ } return profiles; }
From source file:com.thoughtworks.go.config.RolesConfig.java
public RolesConfig ofType(String pluginType) { if (isBlank(pluginType)) { return this; }//from ww w . j av a 2 s .co m Class<? extends Role> roleClass = ROLE_FILTER_MAP.get(pluginType); if (roleClass == null) { throw new BadRequestException("Bad role type `" + pluginType + "`. Valid values are " + StringUtils.join(ROLE_FILTER_MAP.keySet(), ", ")); } return this.stream().filter(role -> role.getClass().isAssignableFrom(roleClass)) .collect(Collectors.toCollection(RolesConfig::new)); }
From source file:com.evolveum.midpoint.common.refinery.RefinedObjectClassDefinitionImpl.java
@Override public Collection<? extends QName> getNamesOfAttributesWithOutboundExpressions() { return getAttributeDefinitions().stream().filter(attrDef -> attrDef.getOutboundMappingType() != null) .map(attrDef -> attrDef.getName()).collect(Collectors.toCollection(HashSet::new)); }
From source file:nova.core.wrapper.mc.forge.v17.wrapper.block.forward.FWBlock.java
@Override public ArrayList<ItemStack> getDrops(World world, int x, int y, int z, int metadata, int fortune) { Block blockInstance;/*from ww w . j ava 2s .c o m*/ // see onBlockHarvested for why the harvestedBlocks hack exists // this method will be called exactly once after destroying the block BlockPosition position = new BlockPosition(world, x, y, z); if (harvestedBlocks.containsKey(position)) { blockInstance = harvestedBlocks.remove(position); } else { blockInstance = getBlockInstance(world, new Vector3D(x, y, z)); } Block.DropEvent event = new Block.DropEvent(blockInstance); blockInstance.events.publish(event); return new ArrayList<>(event.drops.stream().map(item -> (ItemStack) Game.natives().toNative(item)) .collect(Collectors.toCollection(ArrayList::new))); }
From source file:uk.trainwatch.nrod.timetable.tools.TimeTableChecker.java
private void findUnsupportedATOCCode(final Path cifFile) { // Strict mode so we fail on an invalid record type final CIFParser parser = new CIFParser(true); CounterConsumer<String> found = new CounterConsumer<>(); LOG.log(Level.INFO, "Scanning for unsupported ATOCCode's..."); lines(cifFile).map(parser::parse).map(Functions.castTo(BasicScheduleExtras.class)).filter(Objects::nonNull). // Filter for the unkown value filter(s -> s.getAtocCode() == ATOCCode.UNKNOWN). // Swap back the original line from the file map(parser::currentLine).//from w ww .j ava 2 s .c o m // Manually extract the field map(l -> l.substring(11, 13)). // Count it for the result peek(found). // collect into a set then report findings collect(Collectors.toCollection(() -> new TreeSet())). // This is formatted so can be pasted into ATOCCode source forEach(c -> System.out.printf("/**\n/* %1$s\n*/\n%1$s(\"%1$s\",\"%1$s\"),\n", c)); LOG.log(Level.INFO, () -> "Found " + found.get() + " unknown entries"); }
From source file:mesclasses.handlers.ModelHandler.java
public ObservableList<Cours> getCoursForDate(LocalDate date) { String day = NodeUtil.getJour(date); return data.getCours().stream().filter(c -> c.getDay().equals(day) && NodeUtil.coursHappensThisDay(c, date)) .collect(Collectors.toCollection(FXCollections::observableArrayList)); }
From source file:Imputers.KnniLDProb.java
/** * Performs imputation using an already calculated similarity matrix. Used * for optimizing parameters as the similarity matrix only has to be calculated * once./* w w w. jav a 2 s . co m*/ * * The author is aware this description is a bit light on detail. Please * contact the author if further details are needed. * @param original Genotypes called based purely on read counts * @param callprobs Called genotype probabilities * @param list List of masked genotypes and their masked genotype * @param sim Similarity matrix * @return List of imputed probabilities */ protected List<SingleGenotypeProbability> impute(byte[][] original, List<SingleGenotypeProbability> callprobs, List<SingleGenotypeMasked> list, int[][] sim) { if (!SingleGenotypePosition.samePositions(callprobs, list)) { //Needs a proper error throw new ProgrammerException(); } Progress progress = ProgressFactory.get(list.size()); return IntStream.range(0, list.size()).mapToObj(i -> { SingleGenotypeMasked sgr = list.get(i); SingleGenotypeProbability sgc = callprobs.get(i); SingleGenotypeProbability sgp; if (Arrays.stream(sgr.getMasked()).sum() < knownDepth) { sgp = new SingleGenotypeProbability(sgr.getSample(), sgr.getSNP(), imputeSingle(original, sgr.getSample(), sgr.getSNP(), true, sim)); } else { sgp = new SingleGenotypeProbability(sgr.getSample(), sgr.getSNP(), sgc.getProb()); } progress.done(); return sgp; }).collect(Collectors.toCollection(ArrayList::new)); }
From source file:io.druid.server.coordinator.cost.SegmentsCostCache.java
SegmentsCostCache(ArrayList<Bucket> sortedBuckets) { this.sortedBuckets = Preconditions.checkNotNull(sortedBuckets, "buckets should not be null"); this.intervals = sortedBuckets.stream().map(Bucket::getInterval) .collect(Collectors.toCollection(ArrayList::new)); Preconditions.checkArgument(BUCKET_ORDERING.isOrdered(sortedBuckets), "buckets must be ordered by interval"); }