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


Java IntSupplier.getAsInt方法代码示例

本文整理汇总了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."
				);
			}
		}
	};
}
 
开发者ID:jenetics,项目名称:prngine,代码行数:33,代码来源:Random32.java

示例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 );
}
 
开发者ID:renatoathaydes,项目名称:osgiaas,代码行数:19,代码来源:OsgiaasJavaCompilerServiceTest.java

示例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 ){} }
    }
}
 
开发者ID:broadinstitute,项目名称:hdf5-java-bindings,代码行数:35,代码来源:HDF5File.java

示例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() + "]";
		}
	};
}
 
开发者ID:diffplug,项目名称:durian,代码行数:20,代码来源:Box.java

示例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);
    }
}
 
开发者ID:Warlander,项目名称:DeedPlanner-2,代码行数:23,代码来源:Map.java

示例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();
    }
  };
}
 
开发者ID:Torchmind,项目名称:Observables,代码行数:18,代码来源:IntegerBinding.java

示例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;
    }
}
 
开发者ID:graalvm,项目名称:graal-core,代码行数:13,代码来源:CompilationFinalWeakReferencePartialEvaluationTest.java

示例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;
    }
}
 
开发者ID:acmi,项目名称:L2io,代码行数:29,代码来源:ByteUtil.java

示例9: F

import java.util.function.IntSupplier; //导入方法依赖的package包/类
F(IntSupplier intSupplier) {
    this((Supplier<R>) new Supplier<Integer>() {
        @Override
        public Integer get() {
            return intSupplier.getAsInt();
        }
    });
}
 
开发者ID:codebulb,项目名称:LambdaOmega,代码行数:9,代码来源:F.java

示例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());
  }
}
 
开发者ID:apache,项目名称:hbase,代码行数:11,代码来源:CompactSplit.java

示例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();
    }
}
 
开发者ID:ADSC-Resa,项目名称:resa,代码行数:28,代码来源:DataSenderWithTS.java

示例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 ();
  }
}
 
开发者ID:phax,项目名称:ph-commons,代码行数:20,代码来源:SimpleReadWriteLock.java

示例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 ();
  }
}
 
开发者ID:phax,项目名称:ph-commons,代码行数:20,代码来源:SimpleReadWriteLock.java

示例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 ();
  }
}
 
开发者ID:phax,项目名称:ph-commons,代码行数:22,代码来源:SimpleLock.java

示例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;
}
 
开发者ID:rhauch,项目名称:debezium-proto,代码行数:21,代码来源:Configuration.java


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