本文整理汇总了Java中java.util.function.IntSupplier.getAsInt方法的典型用法代码示例。如果您正苦于以下问题:Java IntSupplier.getAsInt方法的具体用法?Java IntSupplier.getAsInt怎么用?Java IntSupplier.getAsInt使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.function.IntSupplier
的用法示例。
在下文中一共展示了IntSupplier.getAsInt方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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."
);
}
}
};
}
示例2: 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 );
}
示例3: 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 ){} }
}
}
示例4: 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() + "]";
}
};
}
示例5: applyColor
import java.util.function.IntSupplier; //导入方法依赖的package包/类
private void applyColor(GL2 g, IntSupplier func, boolean dot) {
float color;
if (Globals.floor>=0) {
color = ((float)func.getAsInt() - minElevation) / diffElevation;
}
else if (!dot) {
color = ((float)func.getAsInt() - minCaveElevation) / diffCaveElevation;
}
else {
color = ((float)func.getAsInt() - minCaveSize) / diffCaveSize;
}
if (Float.isNaN(color)) {
color = 0.5f;
}
if (!Properties.colorblind) {
g.glColor3f(color, 1-color, 0);
}
else {
g.glColor3f(color, 0, 1-color);
}
}
示例6: create
import java.util.function.IntSupplier; //导入方法依赖的package包/类
/**
* <p>Creates a binding using the passed supplier and list of dependencies.</p>
*
* <p>Note that this method requires manual implementation of the respective binding logic. For
* most cases, however, the static methods provided by this interface do suffice however and
* require far less manually programmed logic.</p>
*/
@Nonnull
static IntegerBinding create(@Nonnull IntSupplier supplier,
ReadOnlyObservable<?>... observables) {
return new AbstractIntegerBinding(new HashSet<>(Arrays.asList(observables))) {
@Override
protected Integer compute() {
return supplier.getAsInt();
}
};
}
示例7: execute
import java.util.function.IntSupplier; //导入方法依赖的package包/类
@Override
public int execute(VirtualFrame frame) {
partialEvaluationConstantAndEquals(finalWeakRefInteger.get(), Integer.valueOf(0));
partialEvaluationConstantAndEquals(finalWeakRefNull.get(), null);
IntSupplier supplier = finalWeakRef.get();
if (supplier != null) {
return supplier.getAsInt();
} else {
return 0xdead;
}
}
示例8: compactIntFromBytes
import java.util.function.IntSupplier; //导入方法依赖的package包/类
public static int compactIntFromBytes(IntSupplier unsignedByteSupplier) {
int output = 0;
boolean signed = false;
for (int i = 0; i < 5; i++) {
int x = unsignedByteSupplier.getAsInt();
if (i == 0) {
if ((x & 0x80) > 0)
signed = true;
output |= (x & 0x3F);
if ((x & 0x40) == 0)
break;
} else if (i == 4) {
output |= (x & 0x1F) << (6 + (3 * 7));
} else {
output |= (x & 0x7F) << (6 + ((i - 1) * 7));
if ((x & 0x80) == 0)
break;
}
}
if (signed) {
if (output == 0)
return Integer.MIN_VALUE;
else
return -output;
} else {
return output;
}
}
示例9: F
import java.util.function.IntSupplier; //导入方法依赖的package包/类
F(IntSupplier intSupplier) {
this((Supplier<R>) new Supplier<Integer>() {
@Override
public Integer get() {
return intSupplier.getAsInt();
}
});
}
示例10: getCompleteTracker
import java.util.function.IntSupplier; //导入方法依赖的package包/类
private CompactionCompleteTracker getCompleteTracker(CompactionLifeCycleTracker tracker,
IntSupplier numberOfStores) {
if (tracker == CompactionLifeCycleTracker.DUMMY) {
// a simple optimization to avoid creating unnecessary objects as usually we do not care about
// the life cycle of a compaction.
return DUMMY_COMPLETE_TRACKER;
} else {
return new AggregatingCompleteTracker(tracker, numberOfStores.getAsInt());
}
}
示例11: send2Queue
import java.util.function.IntSupplier; //导入方法依赖的package包/类
public void send2Queue(Path inputFile, LongSupplier sleep, IntSupplier sendCnt) throws IOException {
Jedis jedis = new Jedis(host, port);
int counter = 0;
try (BufferedReader reader = Files.newBufferedReader(inputFile)) {
String line = null;
int toSendCnt = 0;
while (line != null || (line = reader.readLine()) != null) {
if (toSendCnt > 0) {
toSendCnt--;
} else {
long ms = sleep.getAsLong();
if (ms > 0) {
Utils.sleep(ms);
}
toSendCnt = sendCnt.getAsInt();
}
if (jedis.llen(queueName) < maxPaddingSize) {
String data = counter++ + "|" + System.currentTimeMillis() + "|" + line;
jedis.rpush(queueName, data);
line = null;
}
}
} finally {
jedis.quit();
}
}
示例12: readLocked
import java.util.function.IntSupplier; //导入方法依赖的package包/类
/**
* Execute the provided callable in a read lock.
*
* @param aSupplier
* Callable to be executed. May not be <code>null</code>.
* @return The return value of the callable. May be <code>null</code>.
*/
public int readLocked (@Nonnull final IntSupplier aSupplier)
{
readLock ().lock ();
try
{
return aSupplier.getAsInt ();
}
finally
{
readLock ().unlock ();
}
}
示例13: writeLocked
import java.util.function.IntSupplier; //导入方法依赖的package包/类
/**
* Execute the provided callable in a write lock.
*
* @param aSupplier
* Callable to be executed. May not be <code>null</code>.
* @return The return value of the callable. May be <code>null</code>.
*/
public int writeLocked (@Nonnull final IntSupplier aSupplier)
{
writeLock ().lock ();
try
{
return aSupplier.getAsInt ();
}
finally
{
writeLock ().unlock ();
}
}
示例14: locked
import java.util.function.IntSupplier; //导入方法依赖的package包/类
/**
* Execute the provided callable in a read lock.
*
* @param aSupplier
* Callable to be executed. May not be <code>null</code>.
* @return The return value of the callable. May be <code>null</code>.
*/
public int locked (@Nonnull final IntSupplier aSupplier)
{
ValueEnforcer.notNull (aSupplier, "Supplier");
lock ();
try
{
return aSupplier.getAsInt ();
}
finally
{
unlock ();
}
}
示例15: getInteger
import java.util.function.IntSupplier; //导入方法依赖的package包/类
/**
* Get the integer value associated with the given key, using the given supplier to obtain a default value if there is no such
* key-value pair.
*
* @param key the key for the configuration property
* @param defaultValueSupplier the supplier for the default value; may be null
* @return the integer value, or null if the key is null, there is no such key-value pair in the configuration, the
* {@code defaultValueSupplier} reference is null, or there is a key-value pair in the configuration but the value
* could not be parsed as an integer
*/
default public Integer getInteger(String key, IntSupplier defaultValueSupplier) {
String value = getString(key);
if (value != null) {
try {
return Integer.parseInt(value);
} catch (NumberFormatException e) {
}
}
return defaultValueSupplier != null ? defaultValueSupplier.getAsInt() : null;
}