Example usage for java.util.function IntSupplier getAsInt

List of usage examples for java.util.function IntSupplier getAsInt

Introduction

In this page you can find the example usage for java.util.function IntSupplier getAsInt.

Prototype

int getAsInt();

Source Link

Document

Gets a result.

Usage

From source file:Main.java

public static void main(String[] args) {
    IntSupplier i = () -> Integer.MAX_VALUE;

    System.out.println(i.getAsInt());

}

From source file:com.gemstone.gemfire.internal.LocalStatisticsImplJUnitTest.java

@Test
public void badSupplierParamShouldThrowError() {
    IntSupplier supplier1 = mock(IntSupplier.class);
    when(supplier1.getAsInt()).thenReturn(23);
    thrown.expect(IllegalArgumentException.class);
    stats.setIntSupplier(23, supplier1);
}

From source file:com.gemstone.gemfire.internal.LocalStatisticsImplJUnitTest.java

@Test
public void invokeSuppliersShouldCatchSupplierErrorsAndReturnCount() {
    IntSupplier supplier1 = mock(IntSupplier.class);
    when(supplier1.getAsInt()).thenThrow(NullPointerException.class);
    stats.setIntSupplier(4, supplier1);/*from  w  ww.  j a va2s. co  m*/
    assertEquals(1, stats.invokeSuppliers());

    verify(supplier1).getAsInt();
}

From source file:com.gemstone.gemfire.internal.LocalStatisticsImplJUnitTest.java

@Test
public void invokeIntSuppliersShouldUpdateStats() {
    IntSupplier supplier1 = mock(IntSupplier.class);
    when(supplier1.getAsInt()).thenReturn(23);
    stats.setIntSupplier(4, supplier1);/*from   w  ww  .j  av a  2  s .  co  m*/
    assertEquals(0, stats.invokeSuppliers());

    verify(supplier1).getAsInt();
    assertEquals(23, stats.getInt(4));
}

From source file:com.gemstone.gemfire.internal.LocalStatisticsImplJUnitTest.java

@Test
public void invokeSuppliersShouldLogErrorOnlyOnce() {
    final Logger originalLogger = StatisticsImpl.logger;
    try {/* w w  w. j  a  v  a  2  s .  c  om*/
        final Logger logger = mock(Logger.class);
        StatisticsImpl.logger = logger;
        IntSupplier supplier1 = mock(IntSupplier.class);
        when(supplier1.getAsInt()).thenThrow(NullPointerException.class);
        stats.setIntSupplier(4, supplier1);
        assertEquals(1, stats.invokeSuppliers());
        verify(logger, times(1)).warn(anyString(), anyString(), anyInt(), isA(NullPointerException.class));
        assertEquals(1, stats.invokeSuppliers());
        //Make sure the logger isn't invoked again
        verify(logger, times(1)).warn(anyString(), anyString(), anyInt(), isA(NullPointerException.class));
    } finally {
        StatisticsImpl.logger = originalLogger;
    }
}

From source file:org.apache.accumulo.core.file.rfile.RolllingStatsTest.java

private void testDistribrution(IntSupplier d) {
    StatTester st = new StatTester(2017);

    for (int i = 0; i < 7000; i++) {
        st.addValue(d.getAsInt());
    }/*from  www.  java2s  .  co  m*/

    st.check();
}

From source file:org.apache.commons.weaver.privilizer.example.MethodReferencesUsingBlueprints.java

public int utilsReadPrivateField() {
    final IntSupplier s = Utils::readPrivateField;
    return s.getAsInt();
}

From source file:org.apache.ratis.RaftTestUtil.java

public static void delay(IntSupplier getDelayMs) throws InterruptedException {
    final int t = getDelayMs.getAsInt();
    if (t > 0) {
        Thread.sleep(t);// w w w.j  av  a 2 s.c om
    }
}

From source file:org.briljantframework.array.AbstractIntArray.java

@Override
public void assign(IntSupplier supplier) {
    for (int i = 0; i < size(); i++) {
        set(i, supplier.getAsInt());
    }// w  w w  .ja  va2s .  c  o m
}