當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。