Search in sources :

Example 1 with IntUnaryOperator

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) {
    }
}
Also used : IntUnaryOperator(java.util.function.IntUnaryOperator) TestCase(junit.framework.TestCase) IntUnaryOperator(java.util.function.IntUnaryOperator)

Example 2 with IntUnaryOperator

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;
        }
    });
}
Also used : IntUnaryOperator(java.util.function.IntUnaryOperator)

Example 3 with IntUnaryOperator

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());
}
Also used : IntStream(java.util.stream.IntStream) List(java.util.List) IntToDoubleFunction(java.util.function.IntToDoubleFunction) Assert(org.testng.Assert) DataProvider(org.testng.annotations.DataProvider) BaseTest(org.broadinstitute.hellbender.utils.test.BaseTest) IntUnaryOperator(java.util.function.IntUnaryOperator) Test(org.testng.annotations.Test) IntPredicate(java.util.function.IntPredicate) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) IntUnaryOperator(java.util.function.IntUnaryOperator) BaseTest(org.broadinstitute.hellbender.utils.test.BaseTest) Test(org.testng.annotations.Test)

Example 4 with IntUnaryOperator

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
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) IntBinaryOperator(java.util.function.IntBinaryOperator) IntUnaryOperator(java.util.function.IntUnaryOperator)

Example 5 with IntUnaryOperator

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);
}
Also used : Arrays(java.util.Arrays) ScheduledFuture(java.util.concurrent.ScheduledFuture) DoubleStatistics(com.simiacryptus.util.data.DoubleStatistics) IntUnaryOperator(java.util.function.IntUnaryOperator) BiFunction(java.util.function.BiFunction) LoggerFactory(org.slf4j.LoggerFactory) DoubleSummaryStatistics(java.util.DoubleSummaryStatistics) TrainingMonitor(com.simiacryptus.mindseye.opt.TrainingMonitor) Map(java.util.Map) ImageIO(javax.imageio.ImageIO) Layer(com.simiacryptus.mindseye.lang.Layer) URI(java.net.URI) Graph(guru.nidi.graphviz.model.Graph) LongToIntFunction(java.util.function.LongToIntFunction) StochasticComponent(com.simiacryptus.mindseye.layers.java.StochasticComponent) BufferedImage(java.awt.image.BufferedImage) UUID(java.util.UUID) ComponentEvent(java.awt.event.ComponentEvent) WindowAdapter(java.awt.event.WindowAdapter) DAGNode(com.simiacryptus.mindseye.network.DAGNode) Collectors(java.util.stream.Collectors) WindowEvent(java.awt.event.WindowEvent) Executors(java.util.concurrent.Executors) List(java.util.List) Stream(java.util.stream.Stream) ScalarStatistics(com.simiacryptus.util.data.ScalarStatistics) LoggingWrapperLayer(com.simiacryptus.mindseye.layers.java.LoggingWrapperLayer) DAGNetwork(com.simiacryptus.mindseye.network.DAGNetwork) IntStream(java.util.stream.IntStream) MonitoringWrapperLayer(com.simiacryptus.mindseye.layers.java.MonitoringWrapperLayer) ActionListener(java.awt.event.ActionListener) ScatterPlot(smile.plot.ScatterPlot) ByteArrayOutputStream(java.io.ByteArrayOutputStream) LinkSource(guru.nidi.graphviz.model.LinkSource) Tensor(com.simiacryptus.mindseye.lang.Tensor) HashMap(java.util.HashMap) Supplier(java.util.function.Supplier) JsonUtil(com.simiacryptus.util.io.JsonUtil) MutableNode(guru.nidi.graphviz.model.MutableNode) Charset(java.nio.charset.Charset) Factory(guru.nidi.graphviz.model.Factory) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) NotebookOutput(com.simiacryptus.util.io.NotebookOutput) WeakReference(java.lang.ref.WeakReference) LinkTarget(guru.nidi.graphviz.model.LinkTarget) Nonnull(javax.annotation.Nonnull) Nullable(javax.annotation.Nullable) LongSummaryStatistics(java.util.LongSummaryStatistics) PrintStream(java.io.PrintStream) Logger(org.slf4j.Logger) PlotCanvas(smile.plot.PlotCanvas) RankDir(guru.nidi.graphviz.attribute.RankDir) IOException(java.io.IOException) FileFilter(javax.swing.filechooser.FileFilter) ActionEvent(java.awt.event.ActionEvent) PercentileStatistics(com.simiacryptus.util.data.PercentileStatistics) File(java.io.File) java.awt(java.awt) ComponentAdapter(java.awt.event.ComponentAdapter) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) MonitoredObject(com.simiacryptus.util.MonitoredObject) IntToLongFunction(java.util.function.IntToLongFunction) Link(guru.nidi.graphviz.model.Link) Step(com.simiacryptus.mindseye.opt.Step) Comparator(java.util.Comparator) javax.swing(javax.swing) Nonnull(javax.annotation.Nonnull) LongToIntFunction(java.util.function.LongToIntFunction) IntToLongFunction(java.util.function.IntToLongFunction) IntUnaryOperator(java.util.function.IntUnaryOperator)

Aggregations

IntUnaryOperator (java.util.function.IntUnaryOperator)11 List (java.util.List)4 TestCase (junit.framework.TestCase)4 ArrayList (java.util.ArrayList)3 File (java.io.File)2 Arrays (java.util.Arrays)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 Set (java.util.Set)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 Collectors (java.util.stream.Collectors)2 IntStream (java.util.stream.IntStream)2 Stream (java.util.stream.Stream)2 Logger (org.slf4j.Logger)2 LoggerFactory (org.slf4j.LoggerFactory)2 Parameter (com.beust.jcommander.Parameter)1 IOUtils (com.github.lindenb.jvarkit.io.IOUtils)1 JvarkitException (com.github.lindenb.jvarkit.lang.JvarkitException)1 Percentile (com.github.lindenb.jvarkit.math.stats.Percentile)1 BedLine (com.github.lindenb.jvarkit.util.bio.bed.BedLine)1