当前位置: 首页>>代码示例>>Java>>正文


Java IntSupplier类代码示例

本文整理汇总了Java中java.util.function.IntSupplier的典型用法代码示例。如果您正苦于以下问题:Java IntSupplier类的具体用法?Java IntSupplier怎么用?Java IntSupplier使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


IntSupplier类属于java.util.function包,在下文中一共展示了IntSupplier类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: shouldRequireNonNullCache

import java.util.function.IntSupplier; //导入依赖的package包/类
/**
 *
 */
@Test
@SuppressWarnings(CompilerWarnings.UNUSED)
public void shouldRequireNonNullCache() {
    // given
    final ConcurrentMap<String, Integer> cache = null;
    final Supplier<String> keySupplier = () -> "key";
    final IntSupplier supplier = () -> 123;

    // when
    thrown.expect(NullPointerException.class);
    thrown.expectMessage("Provide an empty map instead of NULL.");

    // then
    new ConcurrentMapBasedIntSupplierMemoizer<>(cache, keySupplier, supplier);
}
 
开发者ID:sebhoss,项目名称:memoization.java,代码行数:19,代码来源:ConcurrentMapBasedIntSupplierMemoizerTest.java

示例2: of

import java.util.function.IntSupplier; //导入依赖的package包/类
/**
 * Create a new {@code Random64} instance, where the random numbers are
 * generated by the given long {@code supplier}.
 *
 * @param supplier the random number supplier
 * @return a new {@code Random64} instance
 * @throws java.lang.NullPointerException if the given {@code supplier} is
 *         {@code null}.
 */
public static Random32 of(final IntSupplier supplier) {
	Objects.requireNonNull(supplier);

	return new Random32() {
		private static final long serialVersionUID = 1L;

		private final Boolean _sentry = Boolean.TRUE;

		@Override
		public int nextInt() {
			return supplier.getAsInt();
		}

		@Override
		public void setSeed(final long seed) {
			if (_sentry != null) {
				throw new UnsupportedOperationException(
					"The 'setSeed(long)' method is not supported."
				);
			}
		}
	};
}
 
开发者ID:jenetics,项目名称:prngine,代码行数:33,代码来源:Random32.java

示例3: canCastClassToKnownInterfaceAndUsePackageName

import java.util.function.IntSupplier; //导入依赖的package包/类
@Test
public void canCastClassToKnownInterfaceAndUsePackageName() throws Exception {
    String classDef = "package com.acme.util;" +
            "import java.util.function.IntSupplier;" +
            "public class ZeroSupplier implements IntSupplier {" +
            "public int getAsInt() { return 0; }" +
            "}";

    Class<?> cls = javacService.compileJavaClass( DefaultClassLoaderContext.INSTANCE,
            "com.acme.util.ZeroSupplier", classDef )
            .orElseThrow( () -> new AssertionError( "Failed to compile class" ) );

    IntSupplier instance = ( IntSupplier ) cls.newInstance();

    int zero = instance.getAsInt();

    assertEquals( 0, zero );
}
 
开发者ID:renatoathaydes,项目名称:osgiaas,代码行数:19,代码来源:OsgiaasJavaCompilerServiceTest.java

示例4: makeDataset

import java.util.function.IntSupplier; //导入依赖的package包/类
/**
 * General dataset making recipe.
 * @param fullPath the dataset full path.
 * @param typeIdSupplier type id supplier lambda.
 * @param dimensions array with the dimensions of the data.
 * @param data the data. It must be an array of the appropriate type given the type that is
 *             going to be returned by the {@code typeIdSupplier}.
 * @return true iff the data-set needed to be created (it did not existed previously). It will
 * return false if the data-set existed even if it was modified in the process.
 */
private boolean makeDataset(final String fullPath, final IntSupplier typeIdSupplier, final long[] dimensions, final Object data) {
    checkCanWrite();
    int typeCopyId = -1;
    try {
        typeCopyId = typeIdSupplier.getAsInt();
        final Pair<String, String> pathAndName = splitPathInParentAndName(fullPath);
        final String groupPath = pathAndName.getLeft();
        final String dataSetName = pathAndName.getRight();
        makeGroup(groupPath);
        final int childType = findOutGroupChildType(groupPath, dataSetName, fullPath);
        if (childType == HDF5Constants.H5G_UNKNOWN) {
            createDataset(fullPath, typeCopyId, dimensions);
            writeDataset(fullPath, typeCopyId, data);
            return true;
        } else if (childType == HDF5Constants.H5G_DATASET) {
            writeDataset(fullPath, typeCopyId, data);
            return false;
        } else {
            throw new HDF5LibException(String.format("problem trying to write dataset %s in file %s: there is a collision with a non-dataset object", fullPath, file));
        }
    } finally {
        if (typeCopyId != -1) { try { H5.H5Tclose(typeCopyId); } catch (final HDF5Exception ex ){} }
    }
}
 
开发者ID:broadinstitute,项目名称:hdf5-java-bindings,代码行数:35,代码来源:HDF5File.java

示例5: shouldRequireNonNullKeySupplier

import java.util.function.IntSupplier; //导入依赖的package包/类
/**
 *
 */
@Test
@SuppressWarnings(CompilerWarnings.UNUSED)
public void shouldRequireNonNullKeySupplier() {
    // given
    final ConcurrentMap<String, Integer> cache = new ConcurrentHashMap<>();
    final Supplier<String> keySupplier = null;
    final IntSupplier supplier = () -> 123;

    // when
    thrown.expect(NullPointerException.class);
    thrown.expectMessage("Provide a key function, might just be 'MemoizationDefaults.defaultKeySupplier()'.");

    // then
    new ConcurrentMapBasedIntSupplierMemoizer<>(cache, keySupplier, supplier);
}
 
开发者ID:sebhoss,项目名称:memoization.java,代码行数:19,代码来源:ConcurrentMapBasedIntSupplierMemoizerTest.java

示例6: shouldRequireNonNullValueSupplier

import java.util.function.IntSupplier; //导入依赖的package包/类
/**
 *
 */
@Test
@SuppressWarnings(CompilerWarnings.UNUSED)
public void shouldRequireNonNullValueSupplier() {
    // given
    final ConcurrentMap<String, Integer> cache = new ConcurrentHashMap<>();
    final Supplier<String> keySupplier = () -> "key";
    final IntSupplier supplier = null;

    // when
    thrown.expect(NullPointerException.class);
    thrown.expectMessage("Cannot memoize a NULL Supplier - provide an actual Supplier to fix this.");

    // then
    new ConcurrentMapBasedIntSupplierMemoizer<>(cache, keySupplier, supplier);
}
 
开发者ID:sebhoss,项目名称:memoization.java,代码行数:19,代码来源:ConcurrentMapBasedIntSupplierMemoizerTest.java

示例7: shouldUseSuppliedKey

import java.util.function.IntSupplier; //导入依赖的package包/类
/**
 *
 */
@Test
public void shouldUseSuppliedKey() {
    // given
    final ConcurrentMap<String, Integer> cache = new ConcurrentHashMap<>();
    final Supplier<String> keySupplier = () -> "key";
    final IntSupplier supplier = () -> 123;

    // when
    final ConcurrentMapBasedIntSupplierMemoizer<String> memoizer = new ConcurrentMapBasedIntSupplierMemoizer<>(
            cache, keySupplier, supplier);

    // then
    Assert.assertTrue("Cache is not empty before memoization", memoizer.viewCacheForTest().isEmpty());
    Assert.assertEquals("Memoized value does not match expectations", 123, memoizer.getAsInt());
    Assert.assertFalse("Cache is still empty after memoization", memoizer.viewCacheForTest().isEmpty());
    Assert.assertEquals("Memoization key does not match expectations", "key",
            memoizer.viewCacheForTest().keySet().iterator().next());
}
 
开发者ID:sebhoss,项目名称:memoization.java,代码行数:22,代码来源:ConcurrentMapBasedIntSupplierMemoizerTest.java

示例8: shouldTriggerOnce

import java.util.function.IntSupplier; //导入依赖的package包/类
/**
 *
 */
@Test
@SuppressWarnings(CompilerWarnings.BOXING)
public void shouldTriggerOnce() {
    // given
    final ConcurrentMap<String, Integer> cache = new ConcurrentHashMap<>();
    final Supplier<String> keySupplier = () -> "key";
    final IntSupplier supplier = mock(IntSupplier.class);
    given(supplier.getAsInt()).willReturn(123);

    // when
    final ConcurrentMapBasedIntSupplierMemoizer<String> memoizer = new ConcurrentMapBasedIntSupplierMemoizer<>(
            cache, keySupplier, supplier);

    // then
    Assert.assertEquals("Memoized value does not match expectations", 123, memoizer.getAsInt()); // triggers
    Assert.assertEquals("Memoized value does not match expectations", 123, memoizer.getAsInt()); // memoized
    Assert.assertEquals("Memoized value does not match expectations", 123, memoizer.getAsInt()); // memoized
    Assert.assertEquals("Memoized value does not match expectations", 123, memoizer.getAsInt()); // memoized
    verify(supplier, times(1)).getAsInt(); // real supplier triggered once, all other calls were memoized
}
 
开发者ID:sebhoss,项目名称:memoization.java,代码行数:24,代码来源:ConcurrentMapBasedIntSupplierMemoizerTest.java

示例9: SheetPane

import java.util.function.IntSupplier; //导入依赖的package包/类
SheetPane() {
    // define row and column ranges and set up segments
    final IntSupplier startColumn = () -> 0;
    final IntSupplier splitColumn = this::getSplitColumn;
    final IntSupplier endColumn = this::getColumnCount;

    final IntSupplier startRow = () -> 0;
    final IntSupplier splitRow = this::getSplitRow;
    final IntSupplier endRow = this::getRowCount;

    topLeftQuadrant = new SwingSegmentView(startRow, splitRow, startColumn, splitColumn);
    topRightQuadrant = new SwingSegmentView(startRow, splitRow, splitColumn, endColumn);
    bottomLeftQuadrant = new SwingSegmentView(splitRow, endRow, startColumn, splitColumn);
    bottomRightQuadrant = new SwingSegmentView(splitRow, endRow, splitColumn, endColumn);

    init();
}
 
开发者ID:xzel23,项目名称:meja,代码行数:18,代码来源:SwingSheetView.java

示例10: JfxSheetView

import java.util.function.IntSupplier; //导入依赖的package包/类
public JfxSheetView() {
    final GridPane gridPane = new GridPane();

    gridPane.setGridLinesVisible(true); // FIXME

    // define row and column ranges
    final IntSupplier startColumn = () -> 0;
    final IntSupplier splitColumn = this::getSplitColumn;
    final IntSupplier endColumn = this::getColumnCount;

    final IntSupplier startRow = () -> 0;
    final IntSupplier splitRow = this::getSplitRow;
    final IntSupplier endRow = this::getRowCount;

    leftTopChart = new JfxSegmentView(this, startRow, splitRow, startColumn, splitColumn);
    rightTopChart = new JfxSegmentView(this, startRow, splitRow, splitColumn, endColumn);
    leftBottomChart = new JfxSegmentView(this, splitRow, endRow, startColumn, splitColumn);
    rightBottomChart = new JfxSegmentView(this, splitRow, endRow, splitColumn, endColumn);

    gridPane.addRow(1, leftTopChart, rightTopChart);
    gridPane.addRow(2, leftBottomChart, rightBottomChart);

    getChildren().setAll(gridPane);
}
 
开发者ID:xzel23,项目名称:meja,代码行数:25,代码来源:JfxSheetView.java

示例11: shouldReplyToOnNotLeaderWith

import java.util.function.IntSupplier; //导入依赖的package包/类
private void shouldReplyToOnNotLeaderWith(
    final IntSupplier libraryId,
    final LongSupplier connectCorrelationId,
    final String... channels)
{
    whenPolled()
        .then(
            (inv) ->
            {
                library.onNotLeader(libraryId.getAsInt(), connectCorrelationId.getAsLong(), LEADER_CHANNEL);
                return 1;
            })
        .then(replyWithApplicationHeartbeat())
        .then(noReply());

    newLibraryPoller(CLUSTER_CHANNELS);

    library.startConnecting();

    pollTwice();

    poll();

    attemptToConnectTo(channels);
    verify(connectHandler).onConnect(fixLibrary);
}
 
开发者ID:real-logic,项目名称:artio,代码行数:27,代码来源:LibraryPollerTest.java

示例12: QueryProcessor

import java.util.function.IntSupplier; //导入依赖的package包/类
protected QueryProcessor(
    MetricMaker metricMaker,
    SchemaDefinitions<T> schemaDef,
    IndexConfig indexConfig,
    IndexCollection<?, T, ? extends Index<?, T>> indexes,
    IndexRewriter<T> rewriter,
    String limitField,
    IntSupplier permittedLimit) {
  this.metrics = new Metrics(metricMaker);
  this.schemaDef = schemaDef;
  this.indexConfig = indexConfig;
  this.indexes = indexes;
  this.rewriter = rewriter;
  this.limitField = limitField;
  this.permittedLimit = permittedLimit;
  this.used = new AtomicBoolean(false);
}
 
开发者ID:gerrit-review,项目名称:gerrit,代码行数:18,代码来源:QueryProcessor.java

示例13: bitsToSet

import java.util.function.IntSupplier; //导入依赖的package包/类
static <T extends Enum<T> & IntSupplier> Set<T> bitsToSet(int bits, Class<T> tClass) {
    EnumSet<T> ret = EnumSet.noneOf(tClass);
    //  Internal/Unsafe
    T[] enums;
    if (useSharedSecrets) {
        enums = SharedSecrets.getJavaLangAccess().getEnumConstantsShared(tClass);
    } else {
        enums = tClass.getEnumConstants();
    }
    tClass.getEnumConstants();
    for (T t : enums) {
        if ((bits & t.getAsInt()) != 0) {
            ret.add(t);
        }
    }
    return ret;
}
 
开发者ID:vincentzhang96,项目名称:DDS4J,代码行数:18,代码来源:InternalUtils.java

示例14: rowReadBuilderTest

import java.util.function.IntSupplier; //导入依赖的package包/类
@Test
public void rowReadBuilderTest() throws SQLException {
    final RowReadBuilder lrb = RowReadBuilder.create();
    final IntSupplier id = lrb.addInt(sql("id"));
    final Supplier<String> name = lrb.add(sql("name"), String.class);

    m.execute(sql("insert into person (id, name) values (1, 'Max')"));
    m.execute(sql("insert into person (id, name) values (2, 'John')"));

    final List<List<Object>> rows = m.queryList(sql("select ", lrb.buildColumns(), " from person order by id"), lrb.build());
    assertEquals(2, rows.size());

    lrb.bindSuppliers(rows.get(0));
    assertEquals(1, id.getAsInt());
    assertEquals("Max", name.get());

    lrb.bindSuppliers(rows.get(1));
    assertEquals(2, id.getAsInt());
    assertEquals("John", name.get());
}
 
开发者ID:batterseapower,项目名称:mdbi,代码行数:21,代码来源:MDBITest.java

示例15: from

import java.util.function.IntSupplier; //导入依赖的package包/类
/** Creates a `Box.Int` from a `IntSupplier` and a `IntConsumer`. */
public static Int from(IntSupplier getter, IntConsumer setter) {
	return new Int() {
		@Override
		public int getAsInt() {
			return getter.getAsInt();
		}

		@Override
		public void set(int value) {
			setter.accept(value);
		}

		@Override
		public String toString() {
			return "Box.Int.from[" + get() + "]";
		}
	};
}
 
开发者ID:diffplug,项目名称:durian,代码行数:20,代码来源:Box.java


注:本文中的java.util.function.IntSupplier类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。