本文整理汇总了Java中java.util.PrimitiveIterator.OfInt方法的典型用法代码示例。如果您正苦于以下问题:Java PrimitiveIterator.OfInt方法的具体用法?Java PrimitiveIterator.OfInt怎么用?Java PrimitiveIterator.OfInt使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.PrimitiveIterator
的用法示例。
在下文中一共展示了PrimitiveIterator.OfInt方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: iterate
import java.util.PrimitiveIterator; //导入方法依赖的package包/类
/**
* Returns an infinite sequential ordered {@code IntStream} produced by iterative
* application of a function {@code f} to an initial element {@code seed},
* producing a {@code Stream} consisting of {@code seed}, {@code f(seed)},
* {@code f(f(seed))}, etc.
*
* <p>The first element (position {@code 0}) in the {@code IntStream} will be
* the provided {@code seed}. For {@code n > 0}, the element at position
* {@code n}, will be the result of applying the function {@code f} to the
* element at position {@code n - 1}.
*
* @param seed the initial element
* @param f a function to be applied to to the previous element to produce
* a new element
* @return A new sequential {@code IntStream}
*/
public static IntStream iterate(final int seed, final IntUnaryOperator f) {
Objects.requireNonNull(f);
final PrimitiveIterator.OfInt iterator = new PrimitiveIterator.OfInt() {
int t = seed;
@Override
public boolean hasNext() {
return true;
}
@Override
public int nextInt() {
int v = t;
t = f.applyAsInt(t);
return v;
}
};
return StreamSupport.intStream(Spliterators.spliteratorUnknownSize(
iterator,
Spliterator.ORDERED | Spliterator.IMMUTABLE | Spliterator.NONNULL), false);
}
示例2: iteratorOfInt
import java.util.PrimitiveIterator; //导入方法依赖的package包/类
/**
* Returns a primitive iterator for this range
* @return the primitive iterator
*/
private PrimitiveIterator.OfInt iteratorOfInt() {
return new PrimitiveIterator.OfInt() {
private int value = start();
@Override
public boolean hasNext() {
if (excludes != null) {
while (excludes.test(value) && inBounds(value)) {
value = ascend ? value + step : value - step;
}
}
return inBounds(value);
}
@Override
public int nextInt() {
final int next = value;
value = ascend ? value + step : value - step;
return next;
}
};
}
示例3: testIntForEachRemainingWithNull
import java.util.PrimitiveIterator; //导入方法依赖的package包/类
public void testIntForEachRemainingWithNull() {
PrimitiveIterator.OfInt i = new PrimitiveIterator.OfInt() {
@Override
public int nextInt() {
return 0;
}
@Override
public boolean hasNext() {
return false;
}
};
assertThrowsNPE(() -> i.forEachRemaining((IntConsumer) null));
assertThrowsNPE(() -> i.forEachRemaining((Consumer<Integer>) null));
}
示例4: testIntForEachRemainingWithNull
import java.util.PrimitiveIterator; //导入方法依赖的package包/类
public void testIntForEachRemainingWithNull() {
PrimitiveIterator.OfInt i = new PrimitiveIterator.OfInt() {
@Override
public int nextInt() {
return 0;
}
@Override
public boolean hasNext() {
return false;
}
};
executeAndCatch(() -> i.forEachRemaining((IntConsumer) null));
executeAndCatch(() -> i.forEachRemaining((Consumer<Integer>) null));
}
示例5: testBitsetStream
import java.util.PrimitiveIterator; //导入方法依赖的package包/类
@Test(dataProvider = "cases")
public void testBitsetStream(String name, IntStream data) {
BitSet bs = data.collect(BitSet::new, BitSet::set, BitSet::or);
assertEquals(bs.cardinality(), bs.stream().count());
int[] indexHolder = new int[] { -1 };
bs.stream().forEach(i -> {
int ei = indexHolder[0];
indexHolder[0] = bs.nextSetBit(ei + 1);
assertEquals(i, indexHolder[0]);
});
PrimitiveIterator.OfInt it = bs.stream().iterator();
for (int i = bs.nextSetBit(0); i >= 0; i = bs.nextSetBit(i + 1)) {
assertTrue(it.hasNext());
assertEquals(it.nextInt(), i);
if (i == Integer.MAX_VALUE)
break; // or (i + 1) would overflow
}
assertFalse(it.hasNext());
}
示例6: testBitsetStream
import java.util.PrimitiveIterator; //导入方法依赖的package包/类
@Test(dataProvider = "cases")
public void testBitsetStream(String name, IntStream data) {
BitSet bs = new BitSet();
long setBits = data.distinct()
.peek(i -> bs.set(i))
.count();
assertEquals(bs.cardinality(), setBits);
assertEquals(bs.cardinality(), bs.stream().reduce(0, (s, i) -> s+1));
PrimitiveIterator.OfInt it = bs.stream().iterator();
for (int i = bs.nextSetBit(0); i >= 0; i = bs.nextSetBit(i+1)) {
assertTrue(it.hasNext());
assertEquals(it.nextInt(), i);
}
assertFalse(it.hasNext());
}
示例7: testBitsetStream
import java.util.PrimitiveIterator; //导入方法依赖的package包/类
@Test(dataProvider = "cases")
public void testBitsetStream(String name, IntStream data) {
BitSet bs = new BitSet();
long setBits = data.distinct()
.peek(i -> bs.set(i))
.count();
assertEquals(bs.cardinality(), setBits);
assertEquals(bs.cardinality(), bs.stream().reduce(0, (s, i) -> s+1));
PrimitiveIterator.OfInt it = bs.stream().iterator();
for (int i = bs.nextSetBit(0); i >= 0; i = bs.nextSetBit(i+1)) {
assertTrue(it.hasNext());
assertEquals(it.nextInt(), i);
if (i == Integer.MAX_VALUE)
break; // or (i+1) would overflow
}
assertFalse(it.hasNext());
}
示例8: chars
import java.util.PrimitiveIterator; //导入方法依赖的package包/类
/**
* Returns a stream of {@code int} zero-extending the {@code char} values
* from this sequence. Any char which maps to a <a
* href="{@docRoot}/java/lang/Character.html#unicode">surrogate code
* point</a> is passed through uninterpreted.
*
* <p>If the sequence is mutated while the stream is being read, the
* result is undefined.
*
* @return an IntStream of char values from this sequence
* @since 1.8
*/
public default IntStream chars() {
class CharIterator implements PrimitiveIterator.OfInt {
int cur = 0;
public boolean hasNext() {
return cur < length();
}
public int nextInt() {
if (hasNext()) {
return charAt(cur++);
} else {
throw new NoSuchElementException();
}
}
@Override
public void forEachRemaining(IntConsumer block) {
for (; cur < length(); cur++) {
block.accept(charAt(cur));
}
}
}
return StreamSupport.intStream(() ->
Spliterators.spliterator(
new CharIterator(),
length(),
Spliterator.ORDERED),
Spliterator.SUBSIZED | Spliterator.SIZED | Spliterator.ORDERED,
false);
}
示例9: projectionsOfRegions
import java.util.PrimitiveIterator; //导入方法依赖的package包/类
/**
* Get region projections in the form of map (regionIndex -> regionProjections).
*
* @param featureIdx Feature index.
* @param maxDepth Max depth of decision tree.
* @param regionIndexes Indexes of regions for which we want get projections.
* @param blockSize Size of regions block.
* @param affinity Affinity function.
* @param trainingUUID UUID of training.
* @param ignite Ignite instance.
* @return Region projections in the form of map (regionIndex -> regionProjections).
*/
public static Map<Integer, RegionProjection> projectionsOfRegions(int featureIdx, int maxDepth,
IntStream regionIndexes, int blockSize, IgniteFunction<Integer, Object> affinity, UUID trainingUUID,
Ignite ignite) {
HashMap<Integer, RegionProjection> regsForSearch = new HashMap<>();
IgniteCache<RegionKey, List<RegionProjection>> cache = getOrCreate(ignite);
PrimitiveIterator.OfInt itr = regionIndexes.iterator();
int curBlockIdx = -1;
List<RegionProjection> block = null;
Object affinityKey = affinity.apply(featureIdx);
while (itr.hasNext()) {
int i = itr.nextInt();
int blockIdx = i / blockSize;
if (blockIdx != curBlockIdx) {
block = cache.localPeek(key(featureIdx, blockIdx, affinityKey, trainingUUID));
curBlockIdx = blockIdx;
}
if (block == null)
throw new IllegalStateException("Unexpected null block at index " + i);
RegionProjection reg = block.get(i % blockSize);
if (reg.depth() < maxDepth)
regsForSearch.put(i, reg);
}
return regsForSearch;
}
示例10: chars
import java.util.PrimitiveIterator; //导入方法依赖的package包/类
/**
* Returns a stream of {@code int} zero-extending the {@code char} values
* from this sequence. Any char which maps to a <a
* href="{@docRoot}/java/lang/Character.html#unicode">surrogate code
* point</a> is passed through uninterpreted.
*
* <p>The stream binds to this sequence when the terminal stream operation
* commences (specifically, for mutable sequences the spliterator for the
* stream is <a href="../util/Spliterator.html#binding"><em>late-binding</em></a>).
* If the sequence is modified during that operation then the result is
* undefined.
*
* @return an IntStream of char values from this sequence
* @since 1.8
*/
public default IntStream chars() {
class CharIterator implements PrimitiveIterator.OfInt {
int cur = 0;
public boolean hasNext() {
return cur < length();
}
public int nextInt() {
if (hasNext()) {
return charAt(cur++);
} else {
throw new NoSuchElementException();
}
}
@Override
public void forEachRemaining(IntConsumer block) {
for (; cur < length(); cur++) {
block.accept(charAt(cur));
}
}
}
return StreamSupport.intStream(() ->
Spliterators.spliterator(
new CharIterator(),
length(),
Spliterator.ORDERED),
Spliterator.SUBSIZED | Spliterator.SIZED | Spliterator.ORDERED,
false);
}
示例11: degenerateTree
import java.util.PrimitiveIterator; //导入方法依赖的package包/类
private Node.OfInt degenerateTree(PrimitiveIterator.OfInt it) {
if (!it.hasNext()) {
return Nodes.node(new int[0]);
}
int i = it.nextInt();
if (it.hasNext()) {
return new Nodes.ConcNode.OfInt(Nodes.node(new int[] {i}), degenerateTree(it));
}
else {
return Nodes.node(new int[] {i});
}
}
示例12: split
import java.util.PrimitiveIterator; //导入方法依赖的package包/类
public static <V> IList<Node<V>> split(Object editor, Node<V> node, int targetSize) {
IList<Node<V>> result = new LinearList<>();
if ((node.size() >> 1) < targetSize) {
result.addLast(node);
} else {
Node<V> acc = new Node<>(editor, node.prefix, node.offset);
PrimitiveIterator.OfInt masks = Util.masks(node.datamap | node.nodemap);
while (masks.hasNext()) {
int mask = masks.nextInt();
if (acc.size() >= targetSize) {
result.addLast(acc);
acc = new Node<>(editor, node.prefix, node.offset);
}
if (node.isEntry(mask)) {
acc = transferEntry(mask, node, acc);
} else if (node.isNode(mask)) {
Node<V> child = node.node(mask);
if (child.size() >= (targetSize << 1)) {
split(editor, child, targetSize).stream()
.map(n -> new Node<V>(editor, node.prefix, node.offset).putNode(mask, n))
.forEach(result::addLast);
} else {
acc = acc.putNode(mask, child);
}
}
}
if (acc.size() > 0) {
result.addLast(acc);
}
}
return result;
}
示例13: iterator
import java.util.PrimitiveIterator; //导入方法依赖的package包/类
@Override
public PrimitiveIterator.OfInt iterator() {
return s.iterator();
}
示例14: iterator
import java.util.PrimitiveIterator; //导入方法依赖的package包/类
@Override
PrimitiveIterator.OfInt iterator();
示例15: iterator
import java.util.PrimitiveIterator; //导入方法依赖的package包/类
@Override
public PrimitiveIterator.OfInt iterator() {
return Spliterators.iterator(spliterator());
}