use of java.util.function.IntUnaryOperator in project j2objc by google.
the class IntUnaryOperatorTest method testCompose_null.
public void testCompose_null() throws Exception {
IntUnaryOperator plusOne = x -> x + 1;
try {
plusOne.compose(null);
fail();
} catch (NullPointerException expected) {
}
}
use of java.util.function.IntUnaryOperator in project intellij-community by JetBrains.
the class Test method foo.
void foo() {
int k = i.incrementAndGet();
i.compareAndSet(1, 2);
i.updateAndGet(new IntUnaryOperator() {
@Override
public int applyAsInt(int operand) {
return operand + 5;
}
});
}
use of java.util.function.IntUnaryOperator in project gatk by broadinstitute.
the class IndexRangeUnitTest method testMapToInteger.
@Test(dataProvider = "correctFromToData", dependsOnMethods = "testCorrectConstruction")
public void testMapToInteger(final int from, final int to) {
final IndexRange range = new IndexRange(from, to);
final IntUnaryOperator func = n -> n * n - 5;
Assert.assertEquals(range.mapToInteger(func), IntStream.range(from, to).map(func).toArray());
}
use of java.util.function.IntUnaryOperator in project java-example by 1479005017.
the class AtomicIntegerTest method main.
public static void main(String[] args) {
AtomicInteger atomicInteger = new AtomicInteger(0);
/*
* 获取当前值
* get()
* @return 当前值
*/
// int: 0
System.out.println("int: " + atomicInteger.get());
/*
* 设置值
* set(value)
*/
atomicInteger.set(0);
/*
* 获取旧值,设置新值
* getAndSet(newValue)
* @return 旧值
*/
// int: 0
System.out.println("int: " + atomicInteger.getAndSet(1));
/*
* 如果旧值为expectedValue时,设置新值newValue
* compareAndSet(expectedValue, newValue)
* @return 是否设置成功
*/
// succeed: true
System.out.println("succeed: " + atomicInteger.compareAndSet(1, 2));
/*
*
* getAndIncrement()
* @return
*/
/*
*
* getAndDecrement()
* @return
*/
/*
*
* getAndAdd(delta)
* @return
*/
/*
*
* incrementAndGet()
* @return
*/
/*
*
* decrementAndGet()
* @return
*/
/*
*
* addAndGet(delta)
* @return
*/
/*
*
* getAndUpdate(function)
* @return
*/
/*
*
* updateAndGet(function)
* @return
*/
System.out.println("int: " + atomicInteger.updateAndGet(new IntUnaryOperator() {
@Override
public int applyAsInt(int value) {
return value * 2;
}
}));
// int: 4
/*
*
* getAndAccumulate(delta, function)
* @return
*/
/*
*
* accumulateAndGet(delta, function)
* @return
*/
System.out.println("int: " + atomicInteger.accumulateAndGet(1, new IntBinaryOperator() {
@Override
public int applyAsInt(int value, int operand) {
return value + operand;
}
}));
// int: 5
}
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);
}
Aggregations