本文整理了Java中java.util.stream.Stream.generate()
方法的一些代码示例,展示了Stream.generate()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Stream.generate()
方法的具体详情如下:
包路径:java.util.stream.Stream
类名称:Stream
方法名:generate
暂无
代码示例来源:origin: prestodb/presto
private static <T> Stream<T> cyclingShuffledStream(Collection<T> collection)
{
List<T> list = new ArrayList<>(collection);
Collections.shuffle(list);
return Stream.generate(() -> list).flatMap(List::stream);
}
}
代码示例来源:origin: google/guava
@Override
public Spliterator<T> spliterator() {
return Stream.generate(() -> iterable).flatMap(Streams::stream).spliterator();
}
代码示例来源:origin: apache/hbase
private LongAdder[] createCounters(int numBins) {
return Stream.generate(LongAdder::new).limit(numBins + 3).toArray(LongAdder[]::new);
}
代码示例来源:origin: prestodb/presto
@Override
public Spliterator<T> spliterator() {
return Stream.generate(() -> iterable).flatMap(Streams::stream).spliterator();
}
代码示例来源:origin: apache/ignite
@Override public Stream<LabeledVector<Double>> labeled() {
return Stream.generate(gen::getWithId)
.map(v -> new LabeledVector<>(v.vector, (double)v.distributionId));
}
};
代码示例来源:origin: apache/ignite
/** {@inheritDoc} */
@Override public Stream<IgniteBiTuple<String, byte[]>> stream() {
buf.flip();
return Stream.generate(() -> {
int keyLen = buf.getInt();
int dataLen = buf.getInt();
byte[] tmpBuf = new byte[Math.max(keyLen, dataLen)];
buf.get(tmpBuf, 0, keyLen);
String key = new String(tmpBuf, 0, keyLen, StandardCharsets.UTF_8);
buf.get(tmpBuf, 0, dataLen);
return new IgniteBiTuple<>(key, tmpBuf.length > dataLen ? Arrays.copyOf(tmpBuf, dataLen) : tmpBuf);
}).limit(size);
}
代码示例来源:origin: wildfly/wildfly
@Override
public Spliterator<T> spliterator() {
return Stream.generate(() -> iterable).flatMap(Streams::stream).spliterator();
}
代码示例来源:origin: apache/ignite
@Override public Stream<LabeledVector<Double>> labeled() {
return Stream.generate(gen).map(v -> new LabeledVector<>(v, 0.0));
}
};
代码示例来源:origin: shekhargulati/strman-java
/**
* Returns a repeated string given a multiplier.
*
* @param value The input String
* @param multiplier Number of repeats
* @return The String repeated
*/
public static String repeat(final String value, final int multiplier) {
validate(value, NULL_STRING_PREDICATE, NULL_STRING_MSG_SUPPLIER);
return Stream.generate(() -> value).limit(multiplier).collect(joining());
}
代码示例来源:origin: micrometer-metrics/micrometer
@Setup(Level.Iteration)
public void setup() {
final Random r = new Random(1234567891L);
dataIterator = Iterators.cycle(
Stream.generate(() -> Math.round(Math.exp(2.0 + r.nextGaussian()))).limit(1048576)
.collect(Collectors.toList()));
}
}
代码示例来源:origin: apache/hbase
@Override
public List<String> resolve(List<String> names) {
return Stream.generate(() -> "rack").limit(names.size()).collect(Collectors.toList());
}
代码示例来源:origin: apache/hbase
private Set<String> randNamespaces(Random rand) {
return Stream.generate(() -> Long.toHexString(rand.nextLong())).limit(rand.nextInt(5))
.collect(toSet());
}
代码示例来源:origin: apache/hbase
private Map<TableName, List<String>> randTableCFs(Random rand) {
int size = rand.nextInt(5);
Map<TableName, List<String>> map = new HashMap<>();
for (int i = 0; i < size; i++) {
TableName tn = TableName.valueOf(Long.toHexString(rand.nextLong()));
List<String> cfs = Stream.generate(() -> Long.toHexString(rand.nextLong()))
.limit(rand.nextInt(5)).collect(toList());
map.put(tn, cfs);
}
return map;
}
代码示例来源:origin: apache/ignite
/** {@inheritDoc} */
@Override public Stream<UpstreamEntry> transform(Stream<UpstreamEntry> upstream) {
PoissonDistribution poisson = new PoissonDistribution(
new Well19937c(seed),
subsampleRatio,
PoissonDistribution.DEFAULT_EPSILON,
PoissonDistribution.DEFAULT_MAX_ITERATIONS);
return upstream.sequential().flatMap(en -> Stream.generate(() -> en).limit(poisson.sample()));
}
}
代码示例来源:origin: apache/ignite
/**
* Test data generation
*/
private static Stream<IgniteBiTuple<String, byte[]>> generateTestData(int size, int fromKey) {
final AtomicInteger idx = new AtomicInteger(fromKey);
final Random rnd = new Random();
return Stream.generate(() -> {
byte[] val = new byte[1024];
rnd.nextBytes(val);
return new IgniteBiTuple<>("KEY_" + (fromKey < 0 ? rnd.nextInt() : idx.getAndIncrement()), val);
}).limit(size);
}
代码示例来源:origin: prestodb/presto
@BeforeClass
public void setUp()
throws Exception
{
tempFile = new TempFile();
Random random = new Random();
Iterator<String> iterator = Stream.generate(() -> Long.toHexString(random.nextLong())).limit(POSITION_COUNT).iterator();
writeOrcFileColumnHive(
tempFile.getFile(),
ORC_12,
createOrcRecordWriter(tempFile.getFile(), ORC_12, ZLIB, javaStringObjectInspector),
VARCHAR,
iterator);
}
代码示例来源:origin: resilience4j/resilience4j
@Test
public void testRingBitSetWithSlightlyLessCapacity() {
RingBitSet ringBitSet = new RingBitSet(100);
long expectedCardinality = Stream.generate(ThreadLocalRandom.current()::nextBoolean)
.limit(1000)
.peek(ringBitSet::setNextBit)
.skip(900)
.mapToInt(b -> b ? 1 : 0)
.sum();
assertThat(ringBitSet.cardinality()).isEqualTo((int) expectedCardinality);
assertThat(ringBitSet.size()).isEqualTo(128);
assertThat(ringBitSet.length()).isEqualTo(100);
}
代码示例来源:origin: neo4j/neo4j
@Procedure
public Stream<MyOutputRecord> throwsInStream( )
{
return Stream.<MyOutputRecord>generate( () ->
{
throw new IndexOutOfBoundsException();
}).onClose( () ->
{
throw new ExceptionDuringClose();
} );
}
}
代码示例来源:origin: Alluxio/alluxio
/**
* Checks receive responses more than buffer size in order.
*/
@Test
public void receiveMoreThanBufferSize() throws Exception {
WriteResponse[] responses = Stream.generate(() -> WriteResponse.newBuilder().build())
.limit(BUFFER_SIZE * 2).toArray(WriteResponse[]::new);
EXECUTOR.submit(() -> {
for (WriteResponse response : responses) {
mResponseObserver.onNext(response);
}
});
Thread.sleep(SHORT_TIMEOUT);
for (WriteResponse response : responses) {
WriteResponse actualResponse = mStream.receive(TIMEOUT);
Assert.assertEquals(response, actualResponse);
}
}
代码示例来源:origin: Alluxio/alluxio
/**
* Checks receive fails immediately upon error even if buffer is full.
*/
@Test
public void receiveErrorWhenBufferFull() throws Exception {
mThrown.expect(UnauthenticatedException.class);
mThrown.expectMessage(containsString(TEST_MESSAGE));
WriteResponse[] responses = Stream.generate(() -> WriteResponse.newBuilder().build())
.limit(BUFFER_SIZE).toArray(WriteResponse[]::new);
for (WriteResponse response : responses) {
mResponseObserver.onNext(response);
}
mResponseObserver.onError(Status.UNAUTHENTICATED.asRuntimeException());
for (WriteResponse response : responses) {
WriteResponse actualResponse = mStream.receive(TIMEOUT);
Assert.assertEquals(response, actualResponse);
}
}
内容来源于网络,如有侵权,请联系作者删除!