Refine search
/** * {@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; }
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; }
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 }
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 }
/** * {@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; }
@Nullable private static CandidateComponentsIndex doLoadIndex(ClassLoader classLoader) { if (shouldIgnoreIndex) { return null; } try { Enumeration<URL> urls = classLoader.getResources(COMPONENTS_RESOURCE_LOCATION); if (!urls.hasMoreElements()) { return null; } List<Properties> result = new ArrayList<>(); while (urls.hasMoreElements()) { URL url = urls.nextElement(); Properties properties = PropertiesLoaderUtils.loadProperties(new UrlResource(url)); result.add(properties); } if (logger.isDebugEnabled()) { logger.debug("Loaded " + result.size() + "] index(es)"); } int totalCount = result.stream().mapToInt(Properties::size).sum(); return (totalCount > 0 ? new CandidateComponentsIndex(result) : null); } catch (IOException ex) { throw new IllegalStateException("Unable to load indexes from location [" + COMPONENTS_RESOURCE_LOCATION + "]", ex); } }
public static int getConsumerAddressNum(String serviceUniqueName) { Set<ConsumerInvokerWrapper> providerInvokerWrapperSet = ProviderConsumerRegTable.getConsumerInvoker(serviceUniqueName); return providerInvokerWrapperSet.stream() .map(w -> w.getRegistryDirectory().getUrlInvokerMap()) .filter(Objects::nonNull) .mapToInt(Map::size).sum(); } }