/** * Returns an {@link IntStream} containing the elements of the first stream, followed by the * elements of the second stream, and so on. * * <p>This is equivalent to {@code Stream.of(streams).flatMapToInt(stream -> stream)}, but the * returned stream may perform better. * * @see IntStream#concat(IntStream, IntStream) */ public static IntStream concat(IntStream... streams) { // TODO(lowasser): optimize this later return Stream.of(streams).flatMapToInt(stream -> stream); }
/** * Returns an {@link IntStream} containing the elements of the first stream, followed by the * elements of the second stream, and so on. * * <p>This is equivalent to {@code Stream.of(streams).flatMapToInt(stream -> stream)}, but the * returned stream may perform better. * * @see IntStream#concat(IntStream, IntStream) */ public static IntStream concat(IntStream... streams) { // TODO(lowasser): optimize this later return Stream.of(streams).flatMapToInt(stream -> stream); }
/** * Returns an {@link IntStream} containing the elements of the first stream, followed by the * elements of the second stream, and so on. * * <p>This is equivalent to {@code Stream.of(streams).flatMapToInt(stream -> stream)}, but the * returned stream may perform better. * * @see IntStream#concat(IntStream, IntStream) */ public static IntStream concat(IntStream... streams) { // TODO(lowasser): optimize this later return Stream.of(streams).flatMapToInt(stream -> stream); }
/** * Returns an {@link IntStream} containing the elements of the first stream, followed by the * elements of the second stream, and so on. * * <p>This is equivalent to {@code Stream.of(streams).flatMapToInt(stream -> stream)}, but the * returned stream may perform better. * * @see IntStream#concat(IntStream, IntStream) */ public static IntStream concat(IntStream... streams) { // TODO(lowasser): optimize this later return Stream.of(streams).flatMapToInt(stream -> stream); }
public FlatMapToIntAction(Function<? super T, ? extends IntStream> mapper) { super(s -> s.flatMapToInt(requireNonNull(mapper)), IntStream.class, FLAT_MAP_TO); }
private static void testFlatMapToInt() { System.out.println(); System.out.println("Test flat map start"); Collection<String> collection = Arrays.asList("1,2,0", "4,5"); // Get sum all digit from strings int sum = collection.stream().flatMapToInt((p) -> Arrays.asList(p.split(",")).stream().mapToInt(Integer::parseInt)).sum(); System.out.println("sum = " + sum); // print sum = 12 }
private int[] propertyKeyIds() { return populations.stream().flatMapToInt( this::propertyKeyIds ).distinct().toArray(); }
int[][] arr = { {1, 2, 3}, {4, 5, 6}, {7, 8, 9} }; IntStream stream = Arrays.stream(arr).flatMapToInt(x -> Arrays.stream(x));
private int extractMaxIndex(String key, String suffixPattern) { // extract index and property keys final String escapedKey = Pattern.quote(key); final Pattern pattern = Pattern.compile(escapedKey + "\\.(\\d+)" + suffixPattern); final IntStream indexes = properties.keySet().stream() .flatMapToInt(k -> { final Matcher matcher = pattern.matcher(k); if (matcher.find()) { return IntStream.of(Integer.valueOf(matcher.group(1))); } return IntStream.empty(); }); // determine max index return indexes.max().orElse(-1); }
/** * Flattens an array. * * @param elements input array * @return flattened array */ public static int[] flatten(Object[] elements) { return Arrays.stream(elements) .flatMapToInt(el -> el instanceof int[] ? Arrays.stream((int[]) el) : IntStream.of((int) el) ).toArray(); }
private int[] entityTokenIds() { return populations.stream().flatMapToInt( population -> Arrays.stream( population.schema().getEntityTokenIds() ) ).toArray(); }
@Override public IntStream flatMapToInt(Function<? super T, ? extends IntStream> mapper) { requireNonNull(mapper); return materialize().flatMapToInt(mapper); }
@Override public IntStream flatMapToInt(Function<? super T, ? extends IntStream> mapper) { requireNonNull(mapper); if (STRICT) { return toStream().flatMapToInt(mapper); } return mapper.apply(element); }
/** * Deep flattens an array. * * @param input A nested array containing integers * @return flattened array */ public static int[] deepFlatten(Object[] input) { return Arrays.stream(input) .flatMapToInt(o -> { if (o instanceof Object[]) { return Arrays.stream(deepFlatten((Object[]) o)); } return IntStream.of((Integer) o); }).toArray(); }
public static IntStream rleRegion() { int numRuns = ThreadLocalRandom.current().nextInt(1, 2048); int[] runs = createSorted16BitInts(numRuns * 2); return IntStream.range(0, numRuns) .map(i -> i * 2) .mapToObj(i -> IntStream.range(runs[i], runs[i + 1])) .flatMapToInt(i -> i); }
@Override public int getNodes() { return IntStream.concat( IntStream.of(baseGraph.getNodes()-1), extraEdges.stream().flatMapToInt(edge -> IntStream.of(edge.getBaseNode(), edge.getAdjNode()))) .max().getAsInt()+1; }
@Override public IntStream build(boolean parallel) { return previous().build(parallel).flatMapToInt(mapper); } }
@Override public IntStream flatMapToInt(Function<? super T, ? extends IntStream> mapper) { return wrap(stream().flatMapToInt(mapper)); }
@Override public int getNodes() { return IntStream.concat( IntStream.of(graphHopperStorage.getNodes()-1), additionalEdges.stream().flatMapToInt(edge -> IntStream.of(edge.getBaseNode(), edge.getAdjNode()))) .max().getAsInt()+1; }
/** * Extract the lines of all the locations in the specified component. All the flows and secondary locations * are taken into account. The lines present in multiple flows and locations are kept * duplicated. Ordering of results is not guaranteed. * <p> * TODO should be a method of DefaultIssue, as soon as it's no * longer in sonar-core and can access sonar-db-dao. */ public static IntStream allLinesFor(DefaultIssue issue, String componentId) { DbIssues.Locations locations = issue.getLocations(); if (locations == null) { return IntStream.empty(); } Stream<DbCommons.TextRange> textRanges = Stream.concat( locations.hasTextRange() ? Stream.of(locations.getTextRange()) : Stream.empty(), locations.getFlowList().stream() .flatMap(f -> f.getLocationList().stream()) .filter(l -> Objects.equals(componentIdOf(issue, l), componentId)) .map(DbIssues.Location::getTextRange)); return textRanges.flatMapToInt(range -> IntStream.rangeClosed(range.getStartLine(), range.getEndLine())); }