/** * {@inheritDoc} * <p>This implementation creates a single {@link DefaultDataBuffer} * to contain the data in {@code dataBuffers}. */ @Override public DefaultDataBuffer join(List<? extends DataBuffer> dataBuffers) { Assert.notEmpty(dataBuffers, "DataBuffer List must not be empty"); int capacity = dataBuffers.stream().mapToInt(DataBuffer::readableByteCount).sum(); DefaultDataBuffer result = allocateBuffer(capacity); dataBuffers.forEach(result::write); dataBuffers.forEach(DataBufferUtils::release); return result; }
private int computeTotalMainWidth() { final List<AttributedString> mainLines = getMainLines(); final List<AttributedString> mainHeaderLines = getMainHeaderLines(); final int max1 = mainLines.stream().mapToInt(AttributedString::length).max().orElse(0); final int max2 = mainHeaderLines.stream().mapToInt(AttributedString::length).max().orElse(0); return Math.max(max1, max2); }
public Collection<ServerHolder> getAllServers() { final int historicalSize = historicals.values().stream().mapToInt(Collection::size).sum(); final int realtimeSize = realtimes.size(); final List<ServerHolder> allServers = new ArrayList<>(historicalSize + realtimeSize); historicals.values().forEach(allServers::addAll); allServers.addAll(realtimes); return allServers; }
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 static void testMapToInt() { System.out.println(); System.out.println("Test mapToInt start"); Collection<String> collection = Arrays.asList("a1", "a2", "a3", "a1"); // Delete first char of element and returns number int[] number = collection.stream().mapToInt((s) -> Integer.parseInt(s.substring(1))).toArray(); System.out.println("number = " + Arrays.toString(number)); // print number = [1, 2, 3, 1] }
static long requiredBufferCapacity( int cardinality, AggregatorFactory[] aggregatorFactories ) { final int cardinalityWithMissingValue = cardinality + 1; final int recordSize = Arrays.stream(aggregatorFactories) .mapToInt(AggregatorFactory::getMaxIntermediateSizeWithNulls) .sum(); return getUsedFlagBufferCapacity(cardinalityWithMissingValue) + // total used flags size (long) cardinalityWithMissingValue * recordSize; // total values size }
/** * Input a line of numbers separated by space as integers * and return ArrayList of Integers. * eg. the String "1 2 3 4 5 6 7 8 9" is returned as an ArrayList of Integers. * * @param numbers range of numbers separated by space as a string * @return ArrayList of Integers */ public static int[] stringToIntegers(String numbers) { return Arrays.stream(numbers.split(" ")).mapToInt(Integer::parseInt).toArray(); }
private static Function<Page, Page> enforceLayoutProcessor(List<Symbol> expectedLayout, Map<Symbol, Integer> inputLayout) { int[] channels = expectedLayout.stream() .peek(symbol -> checkArgument(inputLayout.containsKey(symbol), "channel not found for symbol: %s", symbol)) .mapToInt(inputLayout::get) .toArray(); if (Arrays.equals(channels, range(0, inputLayout.size()).toArray())) { // this is an identity mapping return Function.identity(); } return new PageChannelSelector(channels); }