本文整理汇总了Java中com.google.common.primitives.UnsignedBytes.checkedCast方法的典型用法代码示例。如果您正苦于以下问题:Java UnsignedBytes.checkedCast方法的具体用法?Java UnsignedBytes.checkedCast怎么用?Java UnsignedBytes.checkedCast使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.common.primitives.UnsignedBytes
的用法示例。
在下文中一共展示了UnsignedBytes.checkedCast方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testBlakeHash
import com.google.common.primitives.UnsignedBytes; //导入方法依赖的package包/类
@Test
public void testBlakeHash() {
Assert.assertEquals(32, TESTVECTOR_UNSIGED_SIA_BYTES.length);
Assert.assertEquals(32, TESTVECTOR_UNSIGNED_BLAKE_HASH.length);
byte[] signedSiaBytes = new byte[32];
for (int i = 0; i < TESTVECTOR_UNSIGED_SIA_BYTES.length; i++) {
signedSiaBytes[i] = UnsignedBytes.checkedCast(TESTVECTOR_UNSIGED_SIA_BYTES[i]);
}
final byte[] result = SiaSeedService.blakeHash(signedSiaBytes);
for (int i = 0; i < result.length; i++) {
byte b = result[i];
Assert.assertEquals(UnsignedBytes.checkedCast(TESTVECTOR_UNSIGNED_BLAKE_HASH[i]), b);
}
final List<String> strings = SiaSeedService.buildSiaWords(signedSiaBytes);
Assert.assertEquals(TEST_VECTOR_WODS, strings);
}
示例2: claimId
import com.google.common.primitives.UnsignedBytes; //导入方法依赖的package包/类
public static int claimId(int id) {
if(id <= 0){
DevCapes.logger.error("The config ID can NOT be negative or 0!");
return id;
}
try {
UnsignedBytes.checkedCast(id);
} catch (IllegalArgumentException e) {
e.printStackTrace();
}
boolean isRegistered = availableIds.get(id);
if (isRegistered) {
DevCapes.logger.error(String.format("The config ID %d is already claimed.", id));
}
availableIds.set(id);
return id;
}
示例3: inc
import com.google.common.primitives.UnsignedBytes; //导入方法依赖的package包/类
/**
* Does constant key length increment.
*
* That is (00 00 00 00).inc() = (00 00 00 01) and so on.
*
* Exceptions: (FF FF FF FF).inc() = Inf for any key length. ( ).inc() =
* (00)
*
* @return The key that is an increment of the current one with constant
* length.
*/
public Key inc() {
if (data.length == 0) {
return new Key((byte) 0);
}
byte[] newData = Arrays.copyOf(data, data.length);
for (int i = newData.length - 1; i >= 0; i--) {
int oldVal = UnsignedBytes.toInt(newData[i]);
//System.out.println(oldVal + " != " + UnsignedBytes.MAX_VALUE);
if (oldVal != BYTE_KEY_SIZE) {
newData[i] = UnsignedBytes.checkedCast(oldVal + 1);
return new Key(newData);
} else {
newData[i] = 0;
}
}
return Key.INF;
}
示例4: getBytes
import com.google.common.primitives.UnsignedBytes; //导入方法依赖的package包/类
protected static byte[] getBytes(long sum, int arraySize) {
final byte[] b = new byte[arraySize];
for (int i = 0; i < b.length; i++) {
final int reverseIndex = b.length - 1 - i;
final long factor = LongMath.pow(256, reverseIndex);
final long base = sum / factor;
b[i] = UnsignedBytes.checkedCast(base);
sum = sum - (base * factor);
}
return b;
}
示例5: validateAndClaimId
import com.google.common.primitives.UnsignedBytes; //导入方法依赖的package包/类
private int validateAndClaimId(int id)
{
// workaround for broken ML
int realId = id;
if (id < Byte.MIN_VALUE)
{
FMLLog.warning("Compensating for modloader out of range compensation by mod : entityId %d for mod %s is now %d", id, Loader.instance().activeModContainer().getModId(), realId);
realId += 3000;
}
if (realId < 0)
{
realId += Byte.MAX_VALUE;
}
try
{
UnsignedBytes.checkedCast(realId);
}
catch (IllegalArgumentException e)
{
FMLLog.log(Level.ERROR, "The entity ID %d for mod %s is not an unsigned byte and may not work", id, Loader.instance().activeModContainer().getModId());
}
if (!availableIndicies.get(realId))
{
FMLLog.severe("The mod %s has attempted to register an entity ID %d which is already reserved. This could cause severe problems", Loader.instance().activeModContainer().getModId(), id);
}
availableIndicies.clear(realId);
return realId;
}
示例6: increment
import com.google.common.primitives.UnsignedBytes; //导入方法依赖的package包/类
/**
* Returns a RandomAccessData that is the smallest value of same length which
* is strictly greater than this. Note that if this is empty or is all 0xFF then
* a token value of positive infinity is returned.
*
* <p>The {@link UnsignedLexicographicalComparator} supports comparing {@link RandomAccessData}
* with support for positive infinitiy.
*/
public RandomAccessData increment() throws IOException {
RandomAccessData copy = copy();
for (int i = copy.size - 1; i >= 0; --i) {
if (copy.buffer[i] != UnsignedBytes.MAX_VALUE) {
copy.buffer[i] = UnsignedBytes.checkedCast(UnsignedBytes.toInt(copy.buffer[i]) + 1);
return copy;
}
}
return POSITIVE_INFINITY;
}
示例7: claimId
import com.google.common.primitives.UnsignedBytes; //导入方法依赖的package包/类
public static int claimId (int id) throws InvalidCapeConfigIdException {
if (id <= 0) throw new InvalidCapeConfigIdException("The config ID must be a positive non-zero integer");
try {
UnsignedBytes.checkedCast(id);
} catch (IllegalArgumentException e) {
e.printStackTrace();
}
boolean isRegistered = availableIds.get(id);
if (isRegistered) throw new InvalidCapeConfigIdException(String.format("The config ID %d is already claimed.", id));
availableIds.set(id);
return id;
}
示例8: serializeExtendedCommunity
import com.google.common.primitives.UnsignedBytes; //导入方法依赖的package包/类
@Override
public void serializeExtendedCommunity(final ExtendedCommunity extendedCommunity, final ByteBuf body) {
Preconditions.checkArgument(extendedCommunity instanceof Layer2AttributesExtendedCommunityCase,
"The extended community %s is not EsImportRouteExtendedCommunityCaseCase type.",
extendedCommunity);
final Layer2AttributesExtendedCommunity extCom = ((Layer2AttributesExtendedCommunityCase) extendedCommunity)
.getLayer2AttributesExtendedCommunity();
final BitArray flags = new BitArray(FLAGS_SIZE);
flags.set(PRIMARY_PE_OFFSET, extCom.isPrimaryPe());
flags.set(BACKUP_PE_OFFSET, extCom.isBackupPe());
flags.set(CONTROL_WORD_OFFSET, extCom.isControlWord());
final byte[] res = flags.array();
byte aux = 0;
final OperationalMode modeOfOperation = extCom.getModeOfOperation();
if (modeOfOperation != null) {
aux = UnsignedBytes.checkedCast(modeOfOperation.getIntValue());
aux = (byte) (aux << THREE_BITS_SHIFT);
res[res.length - 1] = (byte) (res[res.length - 1] | aux);
}
final NormalizationType normalizationType = extCom.getOperatingPer();
if (normalizationType != null) {
aux = UnsignedBytes.checkedCast(normalizationType.getIntValue());
aux = (byte) (aux << FIVE_BITS_SHIFT);
res[res.length - 1] = (byte) (res[res.length - 1] | aux);
}
ByteBufWriteUtil.writeUnsignedShort((int) res[res.length - 1], body);
ByteBufWriteUtil.writeUnsignedShort(extCom.getL2Mtu(), body);
body.writeZero(RESERVED);
}
示例9: Type
import com.google.common.primitives.UnsignedBytes; //导入方法依赖的package包/类
Type(int code) {
this.code = UnsignedBytes.checkedCast(code);
}
示例10: Type
import com.google.common.primitives.UnsignedBytes; //导入方法依赖的package包/类
Type(int code) {
this.code = UnsignedBytes.checkedCast(code);
}
示例11: Availability
import com.google.common.primitives.UnsignedBytes; //导入方法依赖的package包/类
private Availability(@Nonnegative int code, @Nonnull String description) {
this.code = UnsignedBytes.checkedCast(code);
this.description = description;
}
示例12: PowerState
import com.google.common.primitives.UnsignedBytes; //导入方法依赖的package包/类
private PowerState(@Nonnegative int code, @Nonnull String description) {
this.code = UnsignedBytes.checkedCast(code);
this.description = description;
}
示例13: TimestampClockType
import com.google.common.primitives.UnsignedBytes; //导入方法依赖的package包/类
private TimestampClockType(@Nonnegative int code, @Nonnull String description) {
this.code = UnsignedBytes.checkedCast(code);
this.description = description;
}
示例14: decodeEventData3
import com.google.common.primitives.UnsignedBytes; //导入方法依赖的package包/类
/** Contains hex value from 0 to 100 decimal (00h to 64h) representing the % of which the SEL is filled at the time the event was generated: 00h is 0% full (SEL is empty), 64h is 100% full, etc. */
public Object decodeEventData3(byte value) {
return UnsignedBytes.checkedCast(value);
}
示例15: Usage
import com.google.common.primitives.UnsignedBytes; //导入方法依赖的package包/类
private Usage(@Nonnegative int code, @Nonnull String description) {
this.code = UnsignedBytes.checkedCast(code);
this.description = description;
}