use of java.util.function.IntUnaryOperator in project MindsEye by SimiaCryptus.
the class TestUtil method shuffle.
/**
* Shuffle int stream.
*
* @param stream the stream
* @return the int stream
*/
public static IntStream shuffle(@Nonnull IntStream stream) {
// http://primes.utm.edu/lists/small/10000.txt
long coprimeA = 41387;
long coprimeB = 9967;
long ringSize = coprimeA * coprimeB - 1;
@Nonnull IntToLongFunction fn = x -> (x * coprimeA * coprimeA) % ringSize;
@Nonnull LongToIntFunction inv = x -> (int) ((x * coprimeB * coprimeB) % ringSize);
@Nonnull IntUnaryOperator conditions = x -> {
assert x < ringSize;
assert x >= 0;
return x;
};
return stream.map(conditions).mapToLong(fn).sorted().mapToInt(inv);
}
use of java.util.function.IntUnaryOperator in project ignite by apache.
the class IndexQueryRangeTest method check.
/**
* @param left First cache key, inclusive.
* @param right Last cache key, exclusive.
*/
private void check(Query<Cache.Entry<Long, Person>> qry, int left, int right) throws Exception {
QueryCursor<Cache.Entry<Long, Person>> cursor = cache.query(qry);
int expSize = (right - left) * duplicates;
Set<Long> expKeys = new HashSet<>(expSize);
List<Integer> expOrderedValues = new LinkedList<>();
boolean desc = idxName.equals(DESC_IDX);
int from = desc ? right - 1 : left;
int to = desc ? left - 1 : right;
IntUnaryOperator op = (i) -> desc ? i - 1 : i + 1;
for (int i = from; i != to; i = op.applyAsInt(i)) {
for (int j = 0; j < duplicates; j++) {
expOrderedValues.add(i);
expKeys.add((long) CNT * j + i);
}
}
AtomicInteger actSize = new AtomicInteger();
((QueryCursorEx<Cache.Entry<Long, Person>>) cursor).getAll(entry -> {
assertEquals(expOrderedValues.remove(0).intValue(), entry.getValue().id);
assertTrue(expKeys.remove(entry.getKey()));
int persId = entry.getKey().intValue() % CNT;
assertEquals(new Person(persId), entry.getValue());
actSize.incrementAndGet();
});
assertEquals(expSize, actSize.get());
assertTrue(expKeys.isEmpty());
}
use of java.util.function.IntUnaryOperator in project j2objc by google.
the class IntUnaryOperatorTest method testAndThen_null.
public void testAndThen_null() throws Exception {
IntUnaryOperator plusOne = x -> x + 1;
try {
plusOne.andThen(null);
fail();
} catch (NullPointerException expected) {
}
}
use of java.util.function.IntUnaryOperator in project j2objc by google.
the class IntUnaryOperatorTest method testCompose.
public void testCompose() throws Exception {
IntUnaryOperator plusOne = x -> x + 1;
IntUnaryOperator twice = x -> 2 * x;
assertEquals(11, plusOne.compose(twice).applyAsInt(5));
}
use of java.util.function.IntUnaryOperator in project j2objc by google.
the class IntUnaryOperatorTest method testAndThen.
public void testAndThen() throws Exception {
IntUnaryOperator plusOne = x -> x + 1;
IntUnaryOperator twice = x -> 2 * x;
assertEquals(12, plusOne.andThen(twice).applyAsInt(5));
}
Aggregations