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


Java UnsignedBytes.checkedCast方法代码示例

本文整理汇总了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);

}
 
开发者ID:MineboxOS,项目名称:minebox,代码行数:20,代码来源:SiaSeedServiceTest.java

示例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;
}
 
开发者ID:ME-Corp,项目名称:SolderCraft,代码行数:20,代码来源:CapeConfigManager.java

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

示例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;
}
 
开发者ID:kaspersorensen,项目名称:kafka-record-updater,代码行数:12,代码来源:SegmentFileUpdater.java

示例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;
}
 
开发者ID:SchrodingersSpy,项目名称:TRHS_Club_Mod_2016,代码行数:31,代码来源:EntityRegistry.java

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

示例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;
}
 
开发者ID:Wehavecookies56,项目名称:Kingdom-Keys-Re-Coded,代码行数:15,代码来源:CapeConfigManager.java

示例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);
}
 
开发者ID:opendaylight,项目名称:bgpcep,代码行数:32,代码来源:Layer2AttributesExtCom.java

示例9: Type

import com.google.common.primitives.UnsignedBytes; //导入方法依赖的package包/类
Type(int code) {
    this.code = UnsignedBytes.checkedCast(code);
}
 
开发者ID:CalebFenton,项目名称:apkfile,代码行数:4,代码来源:ResourceValue.java

示例10: Type

import com.google.common.primitives.UnsignedBytes; //导入方法依赖的package包/类
Type(int code) {
  this.code = UnsignedBytes.checkedCast(code);
}
 
开发者ID:madisp,项目名称:android-chunk-utils,代码行数:4,代码来源:ResourceValue.java

示例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;
}
 
开发者ID:shevek,项目名称:ipmi4j,代码行数:5,代码来源:GenericOffset.java

示例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;
}
 
开发者ID:shevek,项目名称:ipmi4j,代码行数:5,代码来源:SensorSpecificOffset.java

示例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;
}
 
开发者ID:shevek,项目名称:ipmi4j,代码行数:5,代码来源:SensorSpecificOffset.java

示例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);
}
 
开发者ID:shevek,项目名称:ipmi4j,代码行数:5,代码来源:SensorSpecificOffset.java

示例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;
}
 
开发者ID:shevek,项目名称:ipmi4j,代码行数:5,代码来源:GenericOffset.java


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