本文整理了Java中java.util.stream.IntStream.findAny()
方法的一些代码示例,展示了IntStream.findAny()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。IntStream.findAny()
方法的具体详情如下:
包路径:java.util.stream.IntStream
类名称:IntStream
方法名:findAny
[英]Returns an OptionalInt describing some element of the stream, or an empty OptionalInt if the stream is empty.
This is a short-circuiting terminal operation.
The behavior of this operation is explicitly nondeterministic; it is free to select any element in the stream. This is to allow for maximal performance in parallel operations; the cost is that multiple invocations on the same source may not return the same result. (If a stable result is desired, use #findFirst() instead.)
[中]返回描述流中某些元素的Optionant,如果流为空,则返回空Optionant。
这是一个short-circuiting terminal operation。
此操作的行为明显不确定;可以自由选择流中的任何元素。这是为了在并行操作中实现最大性能;代价是对同一个源的多次调用可能不会返回相同的结果。(如果需要稳定的结果,请改用#findFirst()
代码示例来源:origin: speedment/speedment
@Override
public OptionalInt execute() {
try (final IntStream stream = buildPrevious()) {
return stream.findAny();
}
}
}
代码示例来源:origin: ivan-vasilev/neuralnetworks
/**
* @param d
* - dimension
* @return the index of this dimension within the global dimensions
*/
protected int getDimensionGlobalIndex(int d)
{
int result = d;
if (IntStream.range(0, globalDimensions.length).filter(i -> globalDimensionsLimit[1][i] - globalDimensionsLimit[0][i] != globalDimensions[i]).findAny().isPresent())
{
for (int i = 0, dim = 0; i < globalDimensions.length; i++)
{
if (globalDimensionsLimit[0][i] != globalDimensionsLimit[1][i])
{
if (dim == d)
{
result = i;
break;
}
dim++;
}
}
}
return result;
}
代码示例来源:origin: speedment/speedment
default OptionalInt findAny(IntPipeline pipeline) {
requireNonNull(pipeline);
return optimize(pipeline).getAsIntStream().findAny();
}
代码示例来源:origin: apache/incubator-druid
/**
* Find the index of valueIndices which is {@link IndexedInts} returned from {@link #getValueSelector()#getRow()}
* corresponding to the {@link #subColumnName}.
*
* @return index for valueIndices if found. -1 otherwise.
*/
private int findValueIndicesIndexForSubColumn()
{
final DimensionSelector keySelector = getKeySelector();
final DimensionSelector valueSelector = getValueSelector();
final IndexedInts keyIndices = keySelector.getRow();
final IndexedInts valueIndices = valueSelector.getRow();
final int limit = Math.min(keyIndices.size(), valueIndices.size());
return IntStream
.range(0, limit)
.filter(i -> subColumnName.equals(keySelector.lookupName(keyIndices.get(i)))) // subColumnName is never null
.findAny()
.orElse(-1);
}
代码示例来源:origin: apache/incubator-druid
this.state = state;
final int taskIndex = IntStream.range(0, runningTasks.size())
.filter(i -> runningTasks.get(i).getId().equals(getId())).findAny()
.orElse(-1);
if (taskIndex == -1) {
代码示例来源:origin: rakam-io/rakam
.filter(i -> finalFields.get(i).getName().equals(colName)).findAny().getAsInt())
.toArray();
代码示例来源:origin: net.dongliu/commons-lang
@Override
public OptionalInt findAny() {
return stream.findAny();
}
代码示例来源:origin: triplea-game/triplea
static int getNumber(final String methodName, final Class<?>[] argTypes, final Class<?> remoteInterface) {
final Method[] methods = remoteInterface.getMethods();
Arrays.sort(methods, methodComparator);
return IntStream.range(0, methods.length)
.filter(i -> methods[i].getName().equals(methodName))
.filter(i -> Arrays.equals(argTypes, methods[i].getParameterTypes()))
.findAny()
.orElseThrow(() -> new IllegalStateException("Method not found: " + methodName));
}
代码示例来源:origin: aboullaite/SpringBoot-Excel-Csv
public Integer generateRandomInteger(Integer integer) {
return random.ints(integer, 80)
.findAny()
.getAsInt();
}
}
代码示例来源:origin: se.ugli.ugli-commons/ugli-commons
@Override
public OptionalInt findAny() {
// This is a terminal operation
return evalAndclose(() -> stream.findAny());
}
代码示例来源:origin: com.speedment.runtime/runtime-core
default OptionalInt findAny(IntPipeline pipeline) {
requireNonNull(pipeline);
return optimize(pipeline).getAsIntStream().findAny();
}
代码示例来源:origin: BruceEckel/OnJava8-Examples
public static void main(String[] args) {
System.out.println(rands().findFirst().getAsInt());
System.out.println(
rands().parallel().findFirst().getAsInt());
System.out.println(rands().findAny().getAsInt());
System.out.println(
rands().parallel().findAny().getAsInt());
}
}
代码示例来源:origin: the8472/mldht
void decorate(PullMetaDataConnection con) {
con.poolGenerator = this::getPool;
con.dhtPort = dhts.stream().mapToInt(d -> d.getConfig().getListeningPort()).findAny().getAsInt();
con.pexConsumer = (toAdd) -> {
toAdd.forEach(item -> {
this.addCandidate(con.remoteAddress().getAddress(), item);
});
};
}
代码示例来源:origin: one.util/streamex
@Override
public OptionalInt findAny() {
if (context.fjp != null)
return context.terminate(stream()::findAny);
return stream().findAny();
}
代码示例来源:origin: us.ihmc/robot-environment-awareness
.findAny()
.getAsInt();
int previousEndIndex = ListWrappingIndexTools.previous(startIndex, orderedBorderEdges);
代码示例来源:origin: Nike-Inc/riposte
private Set<Cookie> createCookies(int numberOfCookies) {
if (numberOfCookies < 0) {
return null;
}
Set<Cookie> cookies = new HashSet<>();
for (int x = 0; x < numberOfCookies; x++) {
Cookie cookie = new DefaultCookie(UUID.randomUUID().toString(), UUID.randomUUID().toString());
cookie.setHttpOnly(new Random().ints(0, 1000).findAny().getAsInt() % 2 == 0);
cookie.setMaxAge(new Random().longs(0, 1000).findAny().getAsLong());
cookies.add(cookie);
}
return cookies;
}
代码示例来源:origin: org.infinispan/infinispan-core
public void testConflictsDetected() {
// Test that no conflicts are detected at the start
// Deliberately introduce conflicts and make sure they are detected
waitForClusterToForm(CACHE_NAME);
IntStream.range(0, NUMBER_OF_CACHE_ENTRIES).forEach(i -> getCache(0).put(i, "v" + i));
final int cacheIndex = numMembersInCluster - 1;
assertEquals(0, getConflicts(cacheIndex).count());
introduceCacheConflicts();
List<Map<Address, CacheEntry<Object, Object>>> conflicts = getConflicts(cacheIndex).collect(Collectors.toList());
assertEquals(INCONSISTENT_VALUE_INCREMENT, conflicts.size());
for (Map<Address, CacheEntry<Object, Object>> map : conflicts) {
assertEquals(NUMBER_OF_OWNERS, map.keySet().size());
Collection<CacheEntry<Object, Object>> mapValues = map.values();
int key = mapValues.stream().filter(e -> !(e instanceof NullCacheEntry)).mapToInt(e -> (Integer) e.getKey()).findAny().orElse(-1);
assertTrue(key > -1);
if (key % NULL_VALUE_FREQUENCY == 0) {
assertTrue(map.values().stream().anyMatch(NullCacheEntry.class::isInstance));
} else {
List<Object> icvs = map.values().stream().map(CacheEntry::getValue).distinct().collect(Collectors.toList());
assertEquals(NUMBER_OF_OWNERS, icvs.size());
assertTrue("Expected one of the conflicting string values to be 'INCONSISTENT'", icvs.contains("INCONSISTENT"));
}
}
}
代码示例来源:origin: cc.redberry/rings
.filter(i -> groebner.get(i) != null)
.filter(i -> dv.dvDivisibleBy(groebner.get(i).lt()))
.findAny();
if (divisorOpt.isPresent()) {
代码示例来源:origin: chocoteam/choco-solver
.filter(k -> time[k] > capaMax).findAny();
if (tmax.isPresent()) {
int t = tmax.getAsInt() + min;
内容来源于网络,如有侵权,请联系作者删除!