类java.util.function.IntSupplier源码实例Demo

下面列出了怎么用java.util.function.IntSupplier的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: gizmo   文件: FunctionTestCase.java
@Test
public void testNestedFunction() throws Exception {
    MethodDescriptor getAsInt = MethodDescriptor.ofMethod(IntSupplier.class, "getAsInt", int.class);
    MethodDescriptor addExact = MethodDescriptor.ofMethod(Math.class, "addExact", int.class, int.class, int.class);

    final TestClassLoader cl = new TestClassLoader(getClass().getClassLoader());
    try (ClassCreator creator = ClassCreator.builder().classOutput(cl).className("com.MyTest").interfaces(IntSupplier.class).build()) {
        MethodCreator bc = creator.getMethodCreator("getAsInt", int.class);
        ResultHandle seven = bc.invokeStaticMethod(addExact, bc.load(2), bc.load(5));
        FunctionCreator f1 = bc.createFunction(IntSupplier.class);
        BytecodeCreator f1bc = f1.getBytecode();
        ResultHandle four = f1bc.invokeStaticMethod(addExact, seven, f1bc.load(- 3));
        FunctionCreator f2 = f1bc.createFunction(IntSupplier.class);
        BytecodeCreator f2bc = f2.getBytecode();
        f2bc.returnValue(f2bc.invokeStaticMethod(addExact, seven, four));
        f1bc.returnValue(f1bc.invokeInterfaceMethod(getAsInt, f2.getInstance()));
        bc.returnValue(bc.invokeInterfaceMethod(getAsInt, f1.getInstance()));
    }
    Class<? extends IntSupplier> clazz = cl.loadClass("com.MyTest").asSubclass(IntSupplier.class);
    IntSupplier supplier = clazz.getDeclaredConstructor().newInstance();
    Assert.assertEquals(11, supplier.getAsInt());
}
 
源代码2 项目: turbo-rpc   文件: ConcurrentIntToIntArrayMap.java
public int getOrUpdate(int key, IntSupplier producer) {
	int value = get(key);

	if (value != notFound) {
		return value;
	}

	synchronized (this) {
		value = get(key);

		if (value != notFound) {
			return value;
		}

		value = producer.getAsInt();
		put(key, value);

		return value;
	}
}
 
源代码3 项目: DrivenByMoss   文件: HwSurfaceFactoryImpl.java
/** {@inheritDoc} */
@Override
public IHwLight createLight (final int surfaceID, final OutputID outputID, final IntSupplier supplier, final IntConsumer sendValueConsumer, final IntFunction<ColorEx> stateToColorFunction, final IHwButton button)
{
    this.lightCounter++;
    final String id = createID (surfaceID, outputID == null ? "LIGHT" + this.lightCounter : outputID.name ());

    final MultiStateHardwareLight hardwareLight = this.hardwareSurface.createMultiStateHardwareLight (id);

    final Supplier<? extends InternalHardwareLightState> valueSupplier = () -> new EncodedColorLightState (supplier.getAsInt (), stateToColorFunction);
    final Consumer<? extends InternalHardwareLightState> hardwareUpdater = state -> {
        final HardwareLightVisualState visualState = state == null ? null : state.getVisualState ();
        final int encodedColorState = visualState == null ? 0 : supplier.getAsInt ();
        sendValueConsumer.accept (encodedColorState);
    };

    final HwLightImpl lightImpl = new HwLightImpl (this.host, hardwareLight, valueSupplier, hardwareUpdater);
    if (button != null)
        button.addLight (lightImpl);
    return lightImpl;
}
 
源代码4 项目: antsdb   文件: FishString.java
public final static int compare(long xAddr, long yAddr) {
    IntSupplier scanx = scan(xAddr);
    IntSupplier scany = scan(yAddr);
    for (;;) {
        int chx = scanx.getAsInt();
        int chy = scany.getAsInt();
        if ((chx == -1) && (chy == -1)) {
            break;
        }
        int result = chx - chy;
        if (result != 0) {
            return result;
        }
    }
    return 0;
}
 
源代码5 项目: antsdb   文件: FishUtf8.java
public static int compare(long pX, long pY) {
    IntSupplier scannerX = new FishUtf8(pX).scan();
    IntSupplier scannerY = new FishUtf8(pY).scan();
    for (;;) {
        int x = scannerX.getAsInt();
        int y = scannerY.getAsInt();
        int result = x - y;
        if (result != 0) {
            return result;
        }
        if ((x == -1) && (y == -1)) {
            break;
        }
    }
    return 0;
}
 
源代码6 项目: besu   文件: VertxPeerDiscoveryAgent.java
private IntSupplier pendingTaskCounter(final EventLoopGroup eventLoopGroup) {
  return () ->
      StreamSupport.stream(eventLoopGroup.spliterator(), false)
          .filter(eventExecutor -> eventExecutor instanceof SingleThreadEventExecutor)
          .mapToInt(eventExecutor -> ((SingleThreadEventExecutor) eventExecutor).pendingTasks())
          .sum();
}
 
源代码7 项目: antsdb   文件: Iso8859.java
@Override
public IntSupplier mapDecode(IntSupplier input) {
    IntSupplier result = new IntSupplier() {
        @Override
        public int getAsInt() {
            int ch = get(input);
            return ch;
        }
    };
    return result;
}
 
源代码8 项目: x-pipe   文件: DefaultCommandStoreDelay.java
public DefaultCommandStoreDelay(CommandStore commandStore, IntSupplier delayLogLimitMicro){
	
	this.commandStore = commandStore;
	this.delayLogLimitMicro = delayLogLimitMicro;
	
	for(int i=0;i<offsetDelays.length;i++){
		offsetDelays[i] = new OffsetDelay();
	}
}
 
private void waitForResult(int expect, IntSupplier supplier) {
  for (; ; ) {
    int actual = supplier.getAsInt();
    if (expect == actual) {
      return;
    }

    LOGGER.info("waiting for thread result, expect:{}, actual: {}.", expect, actual);
    try {
      TimeUnit.MILLISECONDS.sleep(100);
    } catch (InterruptedException e) {
      throw new IllegalStateException(e);
    }
  }
}
 
@Test public void testSupplierPerson() {
	IntSupplier supplier = () -> {
		 Person manager1 = new Person(Title.MR, "James", "Wilks", 55);
		 return manager1.getAge();
	};
	assertEquals(55, supplier.getAsInt());
}
 
源代码11 项目: antsdb   文件: Utf8.java
public String decode(IntSupplier supplier) {
    StringBuilder buf = new StringBuilder();
    IntSupplier output = mapDecode(supplier);
    for (int ch = output.getAsInt(); ch != -1; ch=output.getAsInt()) {
           buf.append((char)ch); 
    }
    return buf.toString();
}
 
源代码12 项目: antsdb   文件: ExprGenerator.java
static String getString(TerminalNode rule, Decoder decoder) {
    Token token = rule.getSymbol();
    CharStream cs = token.getInputStream();
    int pos = cs.index();
    cs.seek(token.getStartIndex() + 1);
    int len = token.getStopIndex() - token.getStartIndex() - 1;
    IntSupplier supplier = new IntSupplier() {
        int i = 0;
        
        @Override
        public int getAsInt() {
            if (i >= len) {
                return -1;
            }
            int ch = cs.LA(i + 1);
            if (ch == '\\') {
                i++;
                ch = cs.LA(i + 1);
                if (ch == '0') {
                    ch = 0;
                }
                else if (ch == 'n') {
                    ch = '\n';
                }
                else if (ch == 'r') {
                    ch = '\r';
                }
                else if (ch == 'Z') {
                    ch = '\032';
                }
            }
            i++;
            return ch;
        }
    };
    String result = decoder.toString(supplier);
    cs.seek(pos);
    return result;
}
 
源代码13 项目: fastquery   文件: AbstractQueryRepository.java
@Override
public int tx(IntSupplier paramSupplier) {
	int j = 3;
	if (m[j] == null) {
		cache(j, "tx", IntSupplier.class);
	}
	return (Integer) Prepared.excute(m[j], new Object[]{paramSupplier}, this);
}
 
源代码14 项目: x-pipe   文件: DefaultProxyMonitorCollector.java
public DefaultProxyMonitorCollector(ScheduledExecutorService scheduled,
                                    SimpleKeyedObjectPool<Endpoint, NettyClient> keyedObjectPool,
                                    ProxyModel model, IntSupplier checkInterval) {
    this.scheduled = scheduled;
    this.model = model;
    this.objectPool = keyedObjectPool.getKeyPool(new DefaultProxyEndpoint(model.getUri()));
    this.checkInterval = checkInterval;
}
 
源代码15 项目: antsdb   文件: FishString.java
public static final IntSupplier scan(long addr) {
    int format = Value.getFormat(null, addr);
    if (format == Value.FORMAT_UNICODE16) {
        return new Unicode16(addr).scan();
    }
    else if (format == Value.FORMAT_UTF8) {
        return new FishUtf8(addr).scan();
    }
    else {
        throw new IllegalArgumentException();
    }
}
 
源代码16 项目: DrivenByMoss   文件: AbstractHwContinuousControl.java
/** {@inheritDoc} */
@Override
public void addOutput (final IntSupplier supplier, final IntConsumer consumer)
{
    this.supplier = supplier;
    this.consumer = consumer;
}
 
源代码17 项目: antsdb   文件: FishUtf8.java
public static String getString(long pValue) {
    StringBuilder buf = new StringBuilder();
    IntSupplier scan = new FishUtf8(pValue).scan();
    int ch;
    while ((ch=scan.getAsInt()) >= 0) {
        buf.append((char)ch);
    }
    return buf.toString();
}
 
源代码18 项目: DrivenByMoss   文件: AbstractControlSurface.java
/** {@inheritDoc} */
@Override
public IHwLight createLight (final OutputID outputID, final IntSupplier supplier, final IntConsumer sendConsumer, final IntFunction<ColorEx> stateToColorFunction, final IHwButton button)
{
    final IHwLight light = this.surfaceFactory.createLight (this.surfaceID, outputID, supplier, sendConsumer, stateToColorFunction, button);
    if (outputID != null)
        this.lights.put (outputID, light);
    return light;
}
 
源代码19 项目: x-pipe   文件: DefaultProxyEndpointManager.java
public DefaultProxyEndpointManager(IntSupplier checkInterval) {
    this.healthCheckInterval = checkInterval;
    this.scheduled = MoreExecutors.getExitingScheduledExecutorService(
            new ScheduledThreadPoolExecutor(1, XpipeThreadFactory.create("ProxyEndpointManager")),
            THREAD_POOL_TIME_OUT, TimeUnit.SECONDS);
    this.healthChecker = new DefaultProxyEndpointHealthChecker(scheduled);
    start();
}
 
源代码20 项目: openjdk-8-source   文件: StreamSpliterators.java
OfInt(long size, IntSupplier s) {
    super(size);
    this.s = s;
}
 
源代码21 项目: presto   文件: TaskCountEstimator.java
public TaskCountEstimator(IntSupplier numberOfNodes)
{
    this.numberOfNodes = requireNonNull(numberOfNodes, "numberOfNodes is null");
}
 
OfInt(long size, IntSupplier s) {
    super(size);
    this.s = s;
}
 
源代码23 项目: antsdb   文件: Unicode16.java
public IntSupplier scan() {
    return new Scanner(this.addr + HEADER_SIZE, this.length);
}
 
源代码24 项目: lucene-solr   文件: FloatArrayReservation.java
public FloatArrayReservation(FloatConsumer applier, IntConsumer sizeApplier, FloatSupplier extractor, IntSupplier sizeExtractor) {
  super(applier, sizeApplier, extractor, sizeExtractor);
}
 
源代码25 项目: Recaf   文件: SearchCollector.java
IntSupplier getAccess(String owner, String name, String desc) {
	return () -> acc(owner, name, desc, ACC_NOT_FOUND);
}
 
源代码26 项目: dragonwell8_jdk   文件: CheckIndex.java
@Test(dataProvider = "checkFromIndexSizeProvider")
public void testCheckFromIndexSize(int fromIndex, int size, int length, boolean withinBounds) {
    List<Integer> list = Collections.unmodifiableList(Arrays.asList(new Integer[] { fromIndex, size, length }));
    String expectedMessage = withinBounds
                             ? null
                             : Preconditions.outOfBoundsExceptionFormatter(IndexOutOfBoundsException::new).
            apply("checkFromIndexSize", list).getMessage();

    BiConsumer<Class<? extends RuntimeException>, IntSupplier> check = (ec, s) -> {
        try {
            int rIndex = s.getAsInt();
            if (!withinBounds)
                fail(String.format(
                        "Range [%d, %d + %d) is out of bounds of [0, %d), but was reported to be withing bounds", fromIndex, fromIndex, size, length));
            assertEquals(rIndex, fromIndex);
        }
        catch (RuntimeException e) {
            assertTrue(ec.isInstance(e));
            if (withinBounds)
                fail(String.format(
                        "Range [%d, %d + %d) is within bounds of [0, %d), but was reported to be out of bounds", fromIndex, fromIndex, size, length));
            else
                assertEquals(e.getMessage(), expectedMessage);
        }
    };

    check.accept(AssertingOutOfBoundsException.class,
                 () -> Preconditions.checkFromIndexSize(fromIndex, size, length,
                                                        assertingOutOfBounds(expectedMessage, "checkFromIndexSize", fromIndex, size, length)));
    check.accept(IndexOutOfBoundsException.class,
                 () -> Preconditions.checkFromIndexSize(fromIndex, size, length,
                                                        assertingOutOfBoundsReturnNull("checkFromIndexSize", fromIndex, size, length)));
    check.accept(IndexOutOfBoundsException.class,
                 () -> Preconditions.checkFromIndexSize(fromIndex, size, length, null));
    check.accept(ArrayIndexOutOfBoundsException.class,
                 () -> Preconditions.checkFromIndexSize(fromIndex, size, length,
                                                        Preconditions.outOfBoundsExceptionFormatter(ArrayIndexOutOfBoundsException::new)));
    check.accept(StringIndexOutOfBoundsException.class,
                 () -> Preconditions.checkFromIndexSize(fromIndex, size, length,
                                                        Preconditions.outOfBoundsExceptionFormatter(StringIndexOutOfBoundsException::new)));
}
 
源代码27 项目: TencentKona-8   文件: StreamSpliterators.java
OfInt(long size, IntSupplier s) {
    super(size);
    this.s = s;
}
 
源代码28 项目: TencentKona-8   文件: CheckIndex.java
@Test(dataProvider = "checkIndexProvider")
public void testCheckIndex(int index, int length, boolean withinBounds) {
    List<Integer> list = Collections.unmodifiableList(Arrays.asList(new Integer[] { index, length }));
    String expectedMessage = withinBounds
                             ? null
                             : Preconditions.outOfBoundsExceptionFormatter(IndexOutOfBoundsException::new).
            apply("checkIndex", list).getMessage();

    BiConsumer<Class<? extends RuntimeException>, IntSupplier> checker = (ec, s) -> {
        try {
            int rIndex = s.getAsInt();
            if (!withinBounds)
                fail(String.format(
                        "Index %d is out of bounds of [0, %d), but was reported to be within bounds", index, length));
            assertEquals(rIndex, index);
        }
        catch (RuntimeException e) {
            assertTrue(ec.isInstance(e));
            if (withinBounds)
                fail(String.format(
                        "Index %d is within bounds of [0, %d), but was reported to be out of bounds", index, length));
            else
                assertEquals(e.getMessage(), expectedMessage);
        }
    };

    checker.accept(AssertingOutOfBoundsException.class,
                 () -> Preconditions.checkIndex(index, length,
                                                assertingOutOfBounds(expectedMessage, "checkIndex", index, length)));
    checker.accept(IndexOutOfBoundsException.class,
                 () -> Preconditions.checkIndex(index, length,
                                                assertingOutOfBoundsReturnNull("checkIndex", index, length)));
    checker.accept(IndexOutOfBoundsException.class,
                 () -> Preconditions.checkIndex(index, length, null));
    checker.accept(ArrayIndexOutOfBoundsException.class,
                 () -> Preconditions.checkIndex(index, length,
                                                Preconditions.outOfBoundsExceptionFormatter(ArrayIndexOutOfBoundsException::new)));
    checker.accept(StringIndexOutOfBoundsException.class,
                 () -> Preconditions.checkIndex(index, length,
                                                Preconditions.outOfBoundsExceptionFormatter(StringIndexOutOfBoundsException::new)));
}
 
源代码29 项目: lucene-solr   文件: IntDataWriter.java
public IntDataWriter(DataOutput output, IntSupplier extractor) {
  super(output, extractor);
}
 
源代码30 项目: TencentKona-8   文件: CheckIndex.java
@Test(dataProvider = "checkFromIndexSizeProvider")
public void testCheckFromIndexSize(int fromIndex, int size, int length, boolean withinBounds) {
    List<Integer> list = Collections.unmodifiableList(Arrays.asList(new Integer[] { fromIndex, size, length }));
    String expectedMessage = withinBounds
                             ? null
                             : Preconditions.outOfBoundsExceptionFormatter(IndexOutOfBoundsException::new).
            apply("checkFromIndexSize", list).getMessage();

    BiConsumer<Class<? extends RuntimeException>, IntSupplier> check = (ec, s) -> {
        try {
            int rIndex = s.getAsInt();
            if (!withinBounds)
                fail(String.format(
                        "Range [%d, %d + %d) is out of bounds of [0, %d), but was reported to be withing bounds", fromIndex, fromIndex, size, length));
            assertEquals(rIndex, fromIndex);
        }
        catch (RuntimeException e) {
            assertTrue(ec.isInstance(e));
            if (withinBounds)
                fail(String.format(
                        "Range [%d, %d + %d) is within bounds of [0, %d), but was reported to be out of bounds", fromIndex, fromIndex, size, length));
            else
                assertEquals(e.getMessage(), expectedMessage);
        }
    };

    check.accept(AssertingOutOfBoundsException.class,
                 () -> Preconditions.checkFromIndexSize(fromIndex, size, length,
                                                        assertingOutOfBounds(expectedMessage, "checkFromIndexSize", fromIndex, size, length)));
    check.accept(IndexOutOfBoundsException.class,
                 () -> Preconditions.checkFromIndexSize(fromIndex, size, length,
                                                        assertingOutOfBoundsReturnNull("checkFromIndexSize", fromIndex, size, length)));
    check.accept(IndexOutOfBoundsException.class,
                 () -> Preconditions.checkFromIndexSize(fromIndex, size, length, null));
    check.accept(ArrayIndexOutOfBoundsException.class,
                 () -> Preconditions.checkFromIndexSize(fromIndex, size, length,
                                                        Preconditions.outOfBoundsExceptionFormatter(ArrayIndexOutOfBoundsException::new)));
    check.accept(StringIndexOutOfBoundsException.class,
                 () -> Preconditions.checkFromIndexSize(fromIndex, size, length,
                                                        Preconditions.outOfBoundsExceptionFormatter(StringIndexOutOfBoundsException::new)));
}
 
 类所在包
 类方法
 同包方法