本文整理匯總了Java中com.google.common.primitives.Ints.checkedCast方法的典型用法代碼示例。如果您正苦於以下問題:Java Ints.checkedCast方法的具體用法?Java Ints.checkedCast怎麽用?Java Ints.checkedCast使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.google.common.primitives.Ints
的用法示例。
在下文中一共展示了Ints.checkedCast方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: rebuffer
import com.google.common.primitives.Ints; //導入方法依賴的package包/類
@Override
public BufferHolder rebuffer(long position)
{
bufferHolder = wrapped.rebuffer(position);
buffer = bufferHolder.buffer();
offset = bufferHolder.offset();
int posInBuffer = Ints.checkedCast(position - offset);
int remaining = buffer.limit() - posInBuffer;
if (remaining == 0)
return this;
if (remaining > limitQuant)
{
buffer.limit(posInBuffer + limitQuant); // certainly below current limit
remaining = limitQuant;
}
limiter.acquire(remaining);
return this;
}
示例2: TopConf
import com.google.common.primitives.Ints; //導入方法依賴的package包/類
public TopConf(Configuration conf) {
isEnabled = conf.getBoolean(DFSConfigKeys.NNTOP_ENABLED_KEY,
DFSConfigKeys.NNTOP_ENABLED_DEFAULT);
String[] periodsStr = conf.getTrimmedStrings(
DFSConfigKeys.NNTOP_WINDOWS_MINUTES_KEY,
DFSConfigKeys.NNTOP_WINDOWS_MINUTES_DEFAULT);
nntopReportingPeriodsMs = new int[periodsStr.length];
for (int i = 0; i < periodsStr.length; i++) {
nntopReportingPeriodsMs[i] = Ints.checkedCast(
TimeUnit.MINUTES.toMillis(Integer.parseInt(periodsStr[i])));
}
for (int aPeriodMs: nntopReportingPeriodsMs) {
Preconditions.checkArgument(aPeriodMs >= TimeUnit.MINUTES.toMillis(1),
"minimum reporting period is 1 min!");
}
}
示例3: setUp
import com.google.common.primitives.Ints; //導入方法依賴的package包/類
@BeforeExperiment void setUp() {
// random integers will be generated in this range, then raised to the
// power of (1/concentration) and floor()ed
max = Ints.checkedCast((long) Math.pow(distinctKeys, concentration));
cache = CacheBuilder.newBuilder()
.concurrencyLevel(segments)
.maximumSize(maximumSize)
.build(
new CacheLoader<Integer, Integer>() {
@Override public Integer load(Integer from) {
return (int) misses.incrementAndGet();
}
});
// To start, fill up the cache.
// Each miss both increments the counter and causes the map to grow by one,
// so until evictions begin, the size of the map is the greatest return
// value seen so far
while (cache.getUnchecked(nextRandomKey()) < maximumSize) {}
requests.set(0);
misses.set(0);
}
示例4: read
import com.google.common.primitives.Ints; //導入方法依賴的package包/類
@Override
public ByteBuffer read(final long offset, final int length) throws IOException {
read.mark(length);
final ByteBuffer origMessage = ByteBuffer.allocate(length);
for (Integer bucketIndex : getBuckets(offset, length)) { //eventually make parallel
Bucket bucket = getBucketFromIndex(bucketIndex);
final long absoluteOffsetForThisBucket = Math.max(offset, bucket.getBaseOffset());
final int lengthForBucket = Ints.checkedCast(Math.min(bucket.getUpperBound() + 1, offset + length) - absoluteOffsetForThisBucket); //todo this threw an exception
final int dataOffset = Ints.checkedCast(Math.max(0, bucket.getBaseOffset() - offset));
final ByteBuffer pseudoCopy = bufferForBucket(origMessage, lengthForBucket, dataOffset);
bucket.getBytes(pseudoCopy, absoluteOffsetForThisBucket, lengthForBucket);
}
return origMessage;
}
示例5: getElement
import com.google.common.primitives.Ints; //導入方法依賴的package包/類
long getElement(long idx) {
long elt = 0;
long bitpos = ELEMENT_BITS * idx;
int tabpos = Ints.checkedCast(bitpos / 64);
long slotpos = bitpos % 64;
long spillbits = (slotpos + ELEMENT_BITS) - 64;
elt = (table[tabpos] >>> slotpos) & ELEMENT_MASK;
if (spillbits > 0) {
++tabpos;
long x = table[tabpos] & LOW_MASK(spillbits);
elt |= x << (ELEMENT_BITS - spillbits);
}
return elt;
}
示例6: setElement
import com.google.common.primitives.Ints; //導入方法依賴的package包/類
void setElement(long idx, long elt) {
long bitpos = ELEMENT_BITS * idx;
int tabpos = Ints.checkedCast(bitpos / 64);
long slotpos = bitpos % 64;
long spillbits = (slotpos + ELEMENT_BITS) - 64;
elt &= ELEMENT_MASK;
table[tabpos] &= ~(ELEMENT_MASK << slotpos);
table[tabpos] |= elt << slotpos;
if (spillbits > 0) {
++tabpos;
table[tabpos] &= ~LOW_MASK(spillbits);
table[tabpos] |= elt >>> (ELEMENT_BITS - spillbits);
}
}
示例7: testBitSize
import com.google.common.primitives.Ints; //導入方法依賴的package包/類
@AndroidIncompatible // slow
public void testBitSize() {
double fpp = 0.03;
for (int i = 1; i < 10000; i++) {
long numBits = BloomFilter.optimalNumOfBits(i, fpp);
int arraySize = Ints.checkedCast(LongMath.divide(numBits, 64, RoundingMode.CEILING));
assertEquals(
arraySize * Long.SIZE,
BloomFilter.create(Funnels.unencodedCharsFunnel(), i, fpp).bitSize());
}
}
示例8: getExpForLevel
import com.google.common.primitives.Ints; //導入方法依賴的package包/類
/**
* How much exp points at least needed to reach this level.
* i.e. getLevel() = level && getExp() == 0
*/
public static int getExpForLevel(int level) {
if (level < 0) throw new IllegalArgumentException();
else if (level <= 16) return (level + 6) * level;
else if (level < 32) return Ints.checkedCast(Math.round(2.5 * level * level - 40.5 * level + 360));
else return Ints.checkedCast(Math.round(4.5 * level * level - 162.5 * level + 2220));
}
示例9: unixTimestampInSec
import com.google.common.primitives.Ints; //導入方法依賴的package包/類
/**
* @param uuid
* @return seconds since Unix epoch
*/
public static int unixTimestampInSec(UUID uuid)
{
return Ints.checkedCast(TimeUnit.MILLISECONDS.toSeconds(unixTimestamp(uuid)));
}
示例10: addIndexBlock
import com.google.common.primitives.Ints; //導入方法依賴的package包/類
private void addIndexBlock() throws IOException
{
IndexInfo cIndexInfo = new IndexInfo(firstClustering,
lastClustering,
startPosition,
currentPosition() - startPosition,
openMarker);
// indexOffsets is used for both shallow (ShallowIndexedEntry) and non-shallow IndexedEntry.
// For shallow ones, we need it to serialize the offsts in finish().
// For non-shallow ones, the offsts are passed into IndexedEntry, so we don't have to
// calculate the offsets again.
// indexOffsets contains the offsets of the serialized IndexInfo objects.
// I.e. indexOffsets[0] is always 0 so we don't have to deal with a special handling
// for index #0 and always subtracting 1 for the index (which could be error-prone).
if (indexOffsets == null)
indexOffsets = new int[10];
else
{
if (columnIndexCount >= indexOffsets.length)
indexOffsets = Arrays.copyOf(indexOffsets, indexOffsets.length + 10);
//the 0th element is always 0
if (columnIndexCount == 0)
{
indexOffsets[columnIndexCount] = 0;
}
else
{
indexOffsets[columnIndexCount] =
buffer != null
? Ints.checkedCast(buffer.position())
: indexSamplesSerializedSize;
}
}
columnIndexCount++;
// First, we collect the IndexInfo objects until we reach Config.column_index_cache_size_in_kb in an ArrayList.
// When column_index_cache_size_in_kb is reached, we switch to byte-buffer mode.
if (buffer == null)
{
indexSamplesSerializedSize += idxSerializer.serializedSize(cIndexInfo);
if (indexSamplesSerializedSize + columnIndexCount * TypeSizes.sizeof(0) > DatabaseDescriptor.getColumnIndexCacheSize())
{
buffer = reuseOrAllocateBuffer();
for (IndexInfo indexSample : indexSamples)
{
idxSerializer.serialize(indexSample, buffer);
}
}
else
{
indexSamples.add(cIndexInfo);
}
}
// don't put an else here...
if (buffer != null)
{
idxSerializer.serialize(cIndexInfo, buffer);
}
firstClustering = null;
}
示例11: bucketFromOffset
import com.google.common.primitives.Ints; //導入方法依賴的package包/類
private int bucketFromOffset(long offset) {
return Ints.checkedCast(offset / getBucketSize());
}
示例12: BitArray
import com.google.common.primitives.Ints; //導入方法依賴的package包/類
BitArray(long bits) {
this(new long[Ints.checkedCast(LongMath.divide(bits, 64, RoundingMode.CEILING))]);
}
示例13: maxSaslEncryptedBlockSize
import com.google.common.primitives.Ints; //導入方法依賴的package包/類
/**
* Maximum number of bytes to be encrypted at a time when SASL encryption is enabled.
*/
public int maxSaslEncryptedBlockSize() {
return Ints.checkedCast(JavaUtils.byteStringAsBytes(
conf.get("spark.network.sasl.maxEncryptedBlockSize", "64k")));
}
示例14: TABLE_SIZE
import com.google.common.primitives.Ints; //導入方法依賴的package包/類
static int TABLE_SIZE(int quotientBits, int remainderBits) {
long bits = (1 << quotientBits) * (remainderBits + 3);
long longs = bits / 64;
return Ints.checkedCast((bits % 64) > 0 ? (longs + 1) : longs);
}
示例15: getSlotIdx
import com.google.common.primitives.Ints; //導入方法依賴的package包/類
/**
* Get the Slot index.
*
* @return The index of this slot.
*/
public int getSlotIdx() {
return Ints.checkedCast(
(slotAddress - baseAddress) / BYTES_PER_SLOT);
}