当前位置: 首页>>代码示例>>Java>>正文


Java PrimitiveIterator类代码示例

本文整理汇总了Java中java.util.PrimitiveIterator的典型用法代码示例。如果您正苦于以下问题:Java PrimitiveIterator类的具体用法?Java PrimitiveIterator怎么用?Java PrimitiveIterator使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


PrimitiveIterator类属于java.util包,在下文中一共展示了PrimitiveIterator类的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);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:38,代码来源:IntStream.java

示例2: iterate

import java.util.PrimitiveIterator; //导入依赖的package包/类
/**
 * Returns an infinite sequential ordered {@code LongStream} 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 LongStream} 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 LongStream}
 */
public static LongStream iterate(final long seed, final LongUnaryOperator f) {
    Objects.requireNonNull(f);
    final PrimitiveIterator.OfLong iterator = new PrimitiveIterator.OfLong() {
        long t = seed;

        @Override
        public boolean hasNext() {
            return true;
        }

        @Override
        public long nextLong() {
            long v = t;
            t = f.applyAsLong(t);
            return v;
        }
    };
    return StreamSupport.longStream(Spliterators.spliteratorUnknownSize(
            iterator,
            Spliterator.ORDERED | Spliterator.IMMUTABLE | Spliterator.NONNULL), false);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:38,代码来源:LongStream.java

示例3: iterate

import java.util.PrimitiveIterator; //导入依赖的package包/类
/**
 * Returns an infinite sequential ordered {@code DoubleStream} 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 DoubleStream}
 * 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 DoubleStream}
 */
public static DoubleStream iterate(final double seed, final DoubleUnaryOperator f) {
    Objects.requireNonNull(f);
    final PrimitiveIterator.OfDouble iterator = new PrimitiveIterator.OfDouble() {
        double t = seed;

        @Override
        public boolean hasNext() {
            return true;
        }

        @Override
        public double nextDouble() {
            double v = t;
            t = f.applyAsDouble(t);
            return v;
        }
    };
    return StreamSupport.doubleStream(Spliterators.spliteratorUnknownSize(
            iterator,
            Spliterator.ORDERED | Spliterator.IMMUTABLE | Spliterator.NONNULL), false);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:38,代码来源:DoubleStream.java

示例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));
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:17,代码来源:PrimitiveIteratorDefaults.java

示例5: testLongForEachRemainingWithNull

import java.util.PrimitiveIterator; //导入依赖的package包/类
public void testLongForEachRemainingWithNull() {
    PrimitiveIterator.OfLong i = new PrimitiveIterator.OfLong() {
        @Override
        public long nextLong() {
            return 0;
        }

        @Override
        public boolean hasNext() {
            return false;
        }
    };

    executeAndCatch(() -> i.forEachRemaining((LongConsumer) null));
    executeAndCatch(() -> i.forEachRemaining((Consumer<Long>) null));
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:17,代码来源:PrimitiveIteratorDefaults.java

示例6: testDoubleForEachRemainingWithNull

import java.util.PrimitiveIterator; //导入依赖的package包/类
public void testDoubleForEachRemainingWithNull() {
    PrimitiveIterator.OfDouble i = new PrimitiveIterator.OfDouble() {
        @Override
        public double nextDouble() {
            return 0;
        }

        @Override
        public boolean hasNext() {
            return false;
        }
    };

    executeAndCatch(() -> i.forEachRemaining((DoubleConsumer) null));
    executeAndCatch(() -> i.forEachRemaining((Consumer<Double>) null));
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:17,代码来源:PrimitiveIteratorDefaults.java

示例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);
    }
    assertFalse(it.hasNext());
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:18,代码来源:BitSetStreamTest.java

示例8: 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));
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:17,代码来源:PrimitiveIteratorDefaults.java

示例9: testLongForEachRemainingWithNull

import java.util.PrimitiveIterator; //导入依赖的package包/类
public void testLongForEachRemainingWithNull() {
    PrimitiveIterator.OfLong i = new PrimitiveIterator.OfLong() {
        @Override
        public long nextLong() {
            return 0;
        }

        @Override
        public boolean hasNext() {
            return false;
        }
    };

    assertThrowsNPE(() -> i.forEachRemaining((LongConsumer) null));
    assertThrowsNPE(() -> i.forEachRemaining((Consumer<Long>) null));
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:17,代码来源:PrimitiveIteratorDefaults.java

示例10: testDoubleForEachRemainingWithNull

import java.util.PrimitiveIterator; //导入依赖的package包/类
public void testDoubleForEachRemainingWithNull() {
    PrimitiveIterator.OfDouble i = new PrimitiveIterator.OfDouble() {
        @Override
        public double nextDouble() {
            return 0;
        }

        @Override
        public boolean hasNext() {
            return false;
        }
    };

    assertThrowsNPE(() -> i.forEachRemaining((DoubleConsumer) null));
    assertThrowsNPE(() -> i.forEachRemaining((Consumer<Double>) null));
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:17,代码来源:PrimitiveIteratorDefaults.java

示例11: 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());
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:23,代码来源:BitSetStreamTest.java

示例12: calculateRegionInfo

import java.util.PrimitiveIterator; //导入依赖的package包/类
/** {@inheritDoc} */
@Override public VarianceData calculateRegionInfo(DoubleStream s, int size) {
    PrimitiveIterator.OfDouble itr = s.iterator();
    int i = 0;

    double mean = 0.0;
    double m2 = 0.0;

    // Here we calculate variance and mean by incremental computation.
    while (itr.hasNext()) {
        i++;
        double x = itr.next();
        double delta = x - mean;
        mean += delta / i;
        double delta2 = x - mean;
        m2 += delta * delta2;
    }

    return new VarianceData(m2 / i, size, mean);
}
 
开发者ID:Luodian,项目名称:Higher-Cloud-Computing-Project,代码行数:21,代码来源:VarianceSplitCalculator.java

示例13: 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;
        }
    };
}
 
开发者ID:zavtech,项目名称:morpheus-core,代码行数:25,代码来源:RangeOfInts.java

示例14: iteratorOfDouble

import java.util.PrimitiveIterator; //导入依赖的package包/类
/**
 * Returns a primitive iterator for this range
 * @return  the primitive iterator
 */
private PrimitiveIterator.OfDouble iteratorOfDouble() {
    return new PrimitiveIterator.OfDouble() {
        private double 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 double nextDouble() {
            final double next = value;
            value = ascend ? value + step : value - step;
            return next;
        }
    };
}
 
开发者ID:zavtech,项目名称:morpheus-core,代码行数:25,代码来源:RangeOfDoubles.java

示例15: iteratorOfLong

import java.util.PrimitiveIterator; //导入依赖的package包/类
/**
 * Returns a primitive iterator for this range
 * @return  the primitive iterator
 */
private PrimitiveIterator.OfLong iteratorOfLong() {
    return new PrimitiveIterator.OfLong() {
        private long 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 long nextLong() {
            final long next = value;
            value = ascend ? value + step : value - step;
            return next;
        }
    };
}
 
开发者ID:zavtech,项目名称:morpheus-core,代码行数:25,代码来源:RangeOfLongs.java


注:本文中的java.util.PrimitiveIterator类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。