本文整理了Java中java.util.stream.Stream.mapToInt()
方法的一些代码示例,展示了Stream.mapToInt()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Stream.mapToInt()
方法的具体详情如下:
包路径:java.util.stream.Stream
类名称:Stream
方法名:mapToInt
[英]Returns an IntStream consisting of the results of applying the given function to the elements of this stream.
This is an intermediate operation.
[中]返回一个IntStream,该IntStream包含将给定函数应用于该流元素的结果。
这是一个intermediate operation。
代码示例来源:origin: prestodb/presto
public InputChannels(List<Integer> inputChannels)
{
this.inputChannels = inputChannels.stream().mapToInt(Integer::intValue).toArray();
}
代码示例来源:origin: spring-projects/spring-framework
@Override
public DefaultDataBuffer write(ByteBuffer... buffers) {
if (!ObjectUtils.isEmpty(buffers)) {
int capacity = Arrays.stream(buffers).mapToInt(ByteBuffer::remaining).sum();
ensureCapacity(capacity);
Arrays.stream(buffers).forEach(this::write);
}
return this;
}
代码示例来源:origin: neo4j/neo4j
private int[] getOrCreatePropertyKeyIds( String[] properties )
{
return Arrays.stream( properties )
.mapToInt( BatchInserterImpl.this::getOrCreatePropertyKeyId )
.toArray();
}
代码示例来源:origin: spring-projects/spring-framework
/**
* {@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;
}
代码示例来源:origin: apache/flink
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);
}
代码示例来源:origin: apache/incubator-druid
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;
}
代码示例来源:origin: Vedenin/useful-java-links
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
}
代码示例来源:origin: stackoverflow.com
List<Integer> list = Arrays.asList(1, 2, 3, 4);
int[] arr = list.stream().mapToInt(i -> i).toArray(); //[1, 2, 3, 4]
list.set(1, null); //[1, null, 3, 4]
arr = list.stream().filter(i -> i != null).mapToInt(i -> i).toArray(); //[1, 3, 4]
代码示例来源:origin: Vedenin/useful-java-links
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]
}
代码示例来源:origin: shekhargulati/99-problems
public static <T> long lengthStream1(List<T> list) {
return list.stream().mapToInt(x -> 1).sum();
}
代码示例来源:origin: prestodb/presto
public InterpretedHashGenerator(List<Type> hashChannelTypes, List<Integer> hashChannels)
{
this(hashChannelTypes, requireNonNull(hashChannels).stream().mapToInt(i -> i).toArray());
}
代码示例来源:origin: ben-manes/caffeine
public IntStream getTopK(int k) {
return stream.topK(k).stream().mapToInt(counter -> (int) counter.getCount());
}
代码示例来源:origin: apache/pulsar
@Override
public int getAvailablePermits() {
return consumers.values().stream().mapToInt(ConsumerImpl::getAvailablePermits).sum();
}
代码示例来源:origin: stackoverflow.com
List<Integer> primes = Arrays.asList(2, 3, 5, 7, 11, 13, 17, 19, 23, 29);
IntSummaryStatistics stats = primes.stream()
.mapToInt((x) -> x)
.summaryStatistics();
System.out.println(stats);
代码示例来源:origin: EngineHub/WorldEdit
@Nullable
public int[] getLegacyFromItem(ItemType itemType) {
if (!itemToStringMap.containsKey(itemType)) {
return null;
} else {
String value = itemToStringMap.get(itemType).stream().findFirst().get();
return Arrays.stream(value.split(":")).mapToInt(Integer::parseInt).toArray();
}
}
代码示例来源:origin: apache/incubator-druid
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
}
代码示例来源:origin: biezhi/30-seconds-of-java8
/**
* 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();
}
代码示例来源:origin: apache/incubator-druid
@Override
public int getQueryCount()
{
return rels.stream().mapToInt(rel -> ((DruidRel) rel).getQueryCount()).sum();
}
代码示例来源:origin: prestodb/presto
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);
}
代码示例来源:origin: prestodb/presto
private static VarcharType varcharType(List<String> values)
{
if (values.stream().anyMatch(Objects::isNull)) {
return VARCHAR;
}
return createVarcharType(values.stream().mapToInt(String::length).max().getAsInt());
}
内容来源于网络,如有侵权,请联系作者删除!