List of usage examples for java.util.stream IntStream range
public static IntStream range(int startInclusive, int endExclusive)
From source file:org.talend.dataprep.api.service.command.preparation.DiffMetadata.java
private HttpRequestBase onExecute(final String dataSetId, final String preparationId, final List<Action> actionsToAdd) { // original actions (currently applied on the preparation) final List<Action> originalActions; try {//from w w w . j a va 2 s . com originalActions = objectMapper.readerFor(new TypeReference<List<Action>>() { }).readValue(getInput()); } catch (final IOException e) { throw new TDPException(UNABLE_TO_READ_PREPARATION, e, withBuilder().put("id", preparationId).build()); } // prepare the preview parameters out of the preparation actions final List<PreviewParameters> previewParameters = IntStream.range(0, actionsToAdd.size()) .mapToObj((index) -> { try { // base actions = original actions + actions to add from 0 to index final List<Action> previousActionsToAdd = actionsToAdd.subList(0, index); final List<Action> baseActions = new ArrayList<>(originalActions); baseActions.addAll(previousActionsToAdd); // diff actions actions = base actions + the action to add for diff final Action singleActionToAdd = actionsToAdd.get(index); final List<Action> diffActions = new ArrayList<>(baseActions); diffActions.add(singleActionToAdd); return new PreviewParameters( // serializeActions(baseActions), // serializeActions(diffActions), // dataSetId, // null, // null, // HEAD); } catch (IOException e) { throw new TDPException(UNABLE_TO_READ_PREPARATION, e, withBuilder().put("id", preparationId).build()); } }).collect(toList()); // create the http action to perform try { final String uri = transformationServiceUrl + "/transform/diff/metadata"; final HttpPost transformationCall = new HttpPost(uri); transformationCall.setEntity(new StringEntity( objectMapper.writer().writeValueAsString(previewParameters), APPLICATION_JSON)); return transformationCall; } catch (JsonProcessingException e) { throw new TDPException(CommonErrorCodes.UNEXPECTED_EXCEPTION, e); } }
From source file:org.apache.pulsar.compaction.CompactedTopicTest.java
/** * Build a compacted ledger, and return the id of the ledger, the position of the different * entries in the ledger, and a list of gaps, and the entry which should be returned after the gap. */// www. j a v a2 s .c om private Triple<Long, List<Pair<MessageIdData, Long>>, List<Pair<MessageIdData, Long>>> buildCompactedLedger( BookKeeper bk, int count) throws Exception { LedgerHandle lh = bk.createLedger(1, 1, Compactor.COMPACTED_TOPIC_LEDGER_DIGEST_TYPE, Compactor.COMPACTED_TOPIC_LEDGER_PASSWORD); List<Pair<MessageIdData, Long>> positions = new ArrayList<>(); List<Pair<MessageIdData, Long>> idsInGaps = new ArrayList<>(); AtomicLong ledgerIds = new AtomicLong(10L); AtomicLong entryIds = new AtomicLong(0L); CompletableFuture.allOf(IntStream.range(0, count).mapToObj((i) -> { List<MessageIdData> idsInGap = new ArrayList<MessageIdData>(); if (r.nextInt(10) == 1) { long delta = r.nextInt(10) + 1; idsInGap.add(MessageIdData.newBuilder().setLedgerId(ledgerIds.get()).setEntryId(entryIds.get() + 1) .build()); ledgerIds.addAndGet(delta); entryIds.set(0); } long delta = r.nextInt(5); if (delta != 0) { idsInGap.add(MessageIdData.newBuilder().setLedgerId(ledgerIds.get()).setEntryId(entryIds.get() + 1) .build()); } MessageIdData id = MessageIdData.newBuilder().setLedgerId(ledgerIds.get()) .setEntryId(entryIds.addAndGet(delta + 1)).build(); @Cleanup RawMessage m = new RawMessageImpl(id, Unpooled.EMPTY_BUFFER); CompletableFuture<Void> f = new CompletableFuture<>(); ByteBuf buffer = m.serialize(); lh.asyncAddEntry(buffer, (rc, ledger, eid, ctx) -> { if (rc != BKException.Code.OK) { f.completeExceptionally(BKException.create(rc)); } else { positions.add(Pair.of(id, eid)); idsInGap.forEach((gid) -> idsInGaps.add(Pair.of(gid, eid))); f.complete(null); } }, null); return f; }).toArray(CompletableFuture[]::new)).get(); lh.close(); return Triple.of(lh.getId(), positions, idsInGaps); }
From source file:fi.helsinki.opintoni.service.usefullink.UsefulLinkTransactionalService.java
public List<UsefulLinkDto> updateOrder(Long userId, OrderUsefulLinksDto orderUsefulLinksDto, Locale locale) { List<UsefulLink> usefulLinks = usefulLinkRepository.findByUserIdOrderByOrderIndexAsc(userId); Map<Long, UsefulLink> usefulLinkMap = usefulLinks.stream().collect(Collectors.toMap(u -> u.id, u -> u)); IntStream.range(0, orderUsefulLinksDto.usefulLinkIds.size()).forEach(i -> { Long usefulLinkId = orderUsefulLinksDto.usefulLinkIds.get(i); usefulLinkMap.get(usefulLinkId).orderIndex = i; });// w w w . ja v a 2 s. com return usefulLinks.stream().sorted(UsefulLink::compareTo) .map(usefulLink -> usefulLinkConverter.toDto(usefulLink, locale)).collect(Collectors.toList()); }
From source file:com.utbm.lo54.service.CourseSessionService.java
/** * Retourne les noms sessions par id//from www. jav a 2 s . c o m * @param id * @return une liste de nom de session */ public Map<Course_session, Integer> getSessionNameById(List<Integer> id) { Collection<Course_session> col = courseSessionRepository.findByIdIn(id); Iterator<Course_session> iter = col.iterator(); Map<Course_session, Integer> map = IntStream.range(0, col.size()).parallel().boxed() .collect(toConcurrentMap(i -> { synchronized (iter) { return iter.next(); } }, i -> i)); return map; }
From source file:org.wallerlab.yoink.cube.service.CubeBuilderImpl.java
private List<Coord> getAllCoordinates(Cube cube) { Coord[] initialValues = new SimpleCoord[cube.getSize()]; List<Coord> coordinates = Collections.synchronizedList(Arrays.asList(initialValues)); IntStream.range(0, cube.getNumberOfXYZSteps()[0]).parallel().forEach(nXStep -> { for (int nYStep = 0; nYStep < cube.getNumberOfXYZSteps()[1]; nYStep++) { for (int nZStep = 0; nZStep < cube.getNumberOfXYZSteps()[2]; nZStep++) { // get the coordinate in cube int[] xyzCurrentStep = new int[] { nXStep, nYStep, nZStep }; Coord currentCoord = coordInCubeCalculator.calculate(xyzCurrentStep, cube); // get the index of a grid point in cube int indexInCube = nXStep * cube.getNumberOfXYZSteps()[1] * cube.getNumberOfXYZSteps()[2] + nYStep * cube.getNumberOfXYZSteps()[2] + nZStep; coordinates.set(indexInCube, currentCoord); }/*www.j av a 2 s .c om*/ } }); return coordinates; }
From source file:org.gradoop.flink.model.impl.operators.matching.single.cypher.operators.join.functions.MergeEmbeddings.java
/** * Creates a new UDF instance.//from w ww. j av a 2s. c o m * * @param rightColumns number of columns in the right embedding * @param joinColumnsRight join columns of the right side * @param distinctVertexColumnsLeft distinct vertex columns of the left embedding * @param distinctVertexColumnsRight distinct vertex columns of the right embedding * @param distinctEdgeColumnsLeft distinct edge columns of the left embedding * @param distinctEdgeColumnsRight distinct edge columns of the right embedding */ public MergeEmbeddings(int rightColumns, List<Integer> joinColumnsRight, List<Integer> distinctVertexColumnsLeft, List<Integer> distinctVertexColumnsRight, List<Integer> distinctEdgeColumnsLeft, List<Integer> distinctEdgeColumnsRight) { this.nonJoinColumnsRight = IntStream.range(0, rightColumns).filter(col -> !joinColumnsRight.contains(col)) .toArray(); this.joinColumnsRightSize = joinColumnsRight.size(); ToIntFunction<Integer> f = i -> i; this.distinctVertexColumnsLeft = distinctVertexColumnsLeft.stream().mapToInt(f).toArray(); this.distinctVertexColumnsRight = distinctVertexColumnsRight.stream().mapToInt(f).toArray(); this.distinctEdgeColumnsLeft = distinctEdgeColumnsLeft.stream().mapToInt(f).toArray(); this.distinctEdgeColumnsRight = distinctEdgeColumnsRight.stream().mapToInt(f).toArray(); this.checkDistinctVertices = distinctVertexColumnsLeft.size() > 0 || distinctVertexColumnsRight.size() > 0; this.checkDistinctEdges = distinctEdgeColumnsLeft.size() > 0 || distinctEdgeColumnsRight.size() > 0; this.reuseEmbedding = new Embedding(); }
From source file:com.dgtlrepublic.anitomyj.Tokenizer.java
/** Returns then delimiters found in a token range. */ private String getDelimiters(TokenRange range) { final StringBuilder delimiters = new StringBuilder(); Function<Integer, Boolean> isDelimiter = c -> { if (!StringHelper.isAlphanumericChar((char) c.intValue())) { if (StringUtils.containsAny(String.valueOf((char) c.intValue()), options.allowedDelimiters)) { if (!StringUtils.containsAny(delimiters.toString(), String.valueOf((char) c.intValue()))) { return true; }/*from w w w.ja v a 2 s .c o m*/ } } return false; }; IntStream.range(range.getOffset(), Math.min(filename.length(), range.getOffset() + range.getSize())) .filter(value -> isDelimiter.apply((int) filename.charAt(value))) .forEach(value -> delimiters.append(filename.charAt(value))); return delimiters.toString(); }
From source file:info.archinnov.achilles.internals.statements.StatementWrapper.java
default void appendRowDataToBuilder(Row row, List<ColumnDefinitions.Definition> columnsDef, StringBuilder builder) {/*w w w . ja v a2 s . c om*/ StringJoiner joiner = new StringJoiner(", ", "\t", "\n"); IntStream.range(0, columnsDef.size()).forEach(index -> { final ColumnDefinitions.Definition def = columnsDef.get(index); final Object value = extractValueFromRow(row, index, def.getType()); joiner.add(format("%s: %s", def.getName(), value)); }); builder.append(joiner.toString()); }
From source file:com.netflix.spinnaker.halyard.cli.services.v1.ResponseUnwrapper.java
private static int formatTasks(List<DaemonTask> tasks, int lastChildCount) { if (tasks.size() == 0 || GlobalOptions.getGlobalOptions().isQuiet()) { return tasks.size(); }//from w w w . j a va2s.c om int taskCountGrowth = tasks.size() - lastChildCount; IntStream.range(0, taskCountGrowth * 2).forEach(i -> AnsiPrinter.out.println("")); AnsiSnippet snippet = new AnsiSnippet("").addMove(AnsiMove.UP, tasks.size() * 2); AnsiPrinter.out.print(snippet.toString()); for (DaemonTask task : tasks) { formatLastEvent(task); } return tasks.size(); }
From source file:org.bonej.ops.ellipsoid.QuadricToEllipsoid.java
private static Matrix3dc toOrientationMatrix(final EigenDecomposition decomposition) { final List<Vector3d> vectors = IntStream.range(0, 3).mapToObj(decomposition::getEigenvector) .map(e -> new Vector3d(e.getEntry(0), e.getEntry(1), e.getEntry(2))).collect(Collectors.toList()); return new Matrix3d(vectors.get(0), vectors.get(1), vectors.get(2)); }