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


Java UnsignedBytes类代码示例

本文整理汇总了Java中com.google.common.primitives.UnsignedBytes的典型用法代码示例。如果您正苦于以下问题:Java UnsignedBytes类的具体用法?Java UnsignedBytes怎么用?Java UnsignedBytes使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


UnsignedBytes类属于com.google.common.primitives包,在下文中一共展示了UnsignedBytes类的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: dumpEntry

import com.google.common.primitives.UnsignedBytes; //导入依赖的package包/类
private String dumpEntry(int offset) {
    if (DEBUG_SEARCH) {
        StringBuilder sb = new StringBuilder(200);
        for (int i = offset; i < mData.length; i++) {
            if (mData[i] == 0) {
                break;
            }
            char c = (char) UnsignedBytes.toInt(mData[i]);
            sb.append(c);
        }

        return sb.toString();
    } else {
        return "<disabled>";
    }
}
 
开发者ID:evant,项目名称:silent-support,代码行数:17,代码来源:ApiLookup.java

示例3: populateNext

import com.google.common.primitives.UnsignedBytes; //导入依赖的package包/类
private void populateNext() {
  nextKey = null;
  nextValue = null;

  if (!iter.isValid()) {
    return;
  }

  byte[] key = iter.key();
  if (end != null) {
    int comparison = UnsignedBytes.lexicographicalComparator().compare(key, end);
    if ( !(comparison < 0 || (comparison == 0 && endInclusive))) {
      // hit end key.
      return;
    }
  }

  nextKey = key;
  nextValue = iter.value();

}
 
开发者ID:dremio,项目名称:dremio-oss,代码行数:22,代码来源:RocksDBStore.java

示例4: compareToCurrentToken

import com.google.common.primitives.UnsignedBytes; //导入依赖的package包/类
/**
 * Compare only the bytes within the window of the current token
 * @param key
 * @return return -1 if key is lessThan (before) this, 0 if equal, and 1 if key is after
 */
protected int compareToCurrentToken(Cell key) {
  int startIndex = rowLength - currentRowNode.getTokenLength();
  int endIndexExclusive = startIndex + currentRowNode.getTokenLength();
  for (int i = startIndex; i < endIndexExclusive; ++i) {
    if (i >= key.getRowLength()) {// key was shorter, so it's first
      return -1;
    }
    byte keyByte = CellUtil.getRowByte(key, i);
    byte thisByte = rowBuffer[i];
    if (keyByte == thisByte) {
      continue;
    }
    return UnsignedBytes.compare(keyByte, thisByte);
  }
  if (!currentRowNode.hasOccurrences() && rowLength >= key.getRowLength()) { // key was shorter
      return -1;
  }
  return 0;
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:25,代码来源:PrefixTreeArraySearcher.java

示例5: compare

import com.google.common.primitives.UnsignedBytes; //导入依赖的package包/类
@Override
public int compare(ByteBuffer left, ByteBuffer right) {
    int initialLeftPosition = left.position();
    int initialRightPosition = right.position();
    try {
        int minLength = Math.min(left.remaining(), right.remaining());
        for (int i = 0; i < minLength; i++) {
            int result = UnsignedBytes.compare(left.get(), right.get());
            if (result != 0) {
                return result;
            }
        }
        return left.remaining() - right.remaining();
    } finally {
        left.position(initialLeftPosition);
        right.position(initialRightPosition);
    }
}
 
开发者ID:tracingplane,项目名称:tracingplane-java,代码行数:19,代码来源:UnsignedByteBuffer.java

示例6: openClosedBackwardTestWithGuava

import com.google.common.primitives.UnsignedBytes; //导入依赖的package包/类
@Test
public void openClosedBackwardTestWithGuava() {
  final Comparator<byte[]> guava = UnsignedBytes.lexicographicalComparator();
  final Comparator<ByteBuffer> comparator = (bb1, bb2) -> {
    final byte[] array1 = new byte[bb1.remaining()];
    final byte[] array2 = new byte[bb2.remaining()];
    bb1.mark();
    bb2.mark();
    bb1.get(array1);
    bb2.get(array2);
    bb1.reset();
    bb2.reset();
    return guava.compare(array1, array2);
  };
  verify(openClosedBackward(bb(7), bb(2)), comparator, 6, 4, 2);
  verify(openClosedBackward(bb(8), bb(4)), comparator, 6, 4);
}
 
开发者ID:lmdbjava,项目名称:lmdbjava,代码行数:18,代码来源:CursorIteratorTest.java

示例7: writeTo

import com.google.common.primitives.UnsignedBytes; //导入依赖的package包/类
/**
 * Writes this {@code BloomFilter} to an output stream, with a custom format (not Java
 * serialization). This has been measured to save at least 400 bytes compared to regular
 * serialization.
 *
 * <p>Use {@linkplain #readFrom(InputStream, Funnel)} to reconstruct the written BloomFilter.
 */


public void writeTo(OutputStream out) throws IOException {
  // Serial form:
  // 1 signed byte for the strategy
  // 1 unsigned byte for the number of hash functions
  // 1 big endian int, the number of longs in our bitset
  // N big endian longs of our bitset
  DataOutputStream dout = new DataOutputStream(out);
  dout.writeByte(SignedBytes.checkedCast(strategy.ordinal()));
  dout.writeByte(UnsignedBytes.checkedCast(numHashFunctions)); // note: checked at the c'tor
  dout.writeInt(bits.data.length);
  for (long value : bits.data) {
    dout.writeLong(value);
  }
}
 
开发者ID:antlr,项目名称:codebuff,代码行数:24,代码来源:BloomFilter.java

示例8: getHash

import com.google.common.primitives.UnsignedBytes; //导入依赖的package包/类
public Sha256Hash getHash () {
    if (hash != null) {
        return hash;
    }
    //TODO for now we take the two anchor hashes, this works until we have multiple anchors..
    List<byte[]> list = new ArrayList<>();

    list.add(keyServer.getPubKey());
    list.add(keyClient.getPubKey());
    list.sort(UnsignedBytes.lexicographicalComparator());
    ByteBuffer byteBuffer = ByteBuffer.allocate(list.get(0).length + list.get(1).length);
    byteBuffer.put(list.get(0));
    byteBuffer.put(list.get(1));
    hash = Sha256Hash.of(byteBuffer.array());
    return hash;
}
 
开发者ID:blockchain,项目名称:thunder,代码行数:17,代码来源:Channel.java

示例9: testOrderedEncoding

import com.google.common.primitives.UnsignedBytes; //导入依赖的package包/类
@Test
public void testOrderedEncoding() throws Exception {
  List<Long> sortedTimestamps = new ArrayList<>(TEST_TIMESTAMPS);
  Collections.sort(sortedTimestamps);

  List<byte[]> encodings = new ArrayList<>(sortedTimestamps.size());
  for (long timestamp : sortedTimestamps) {
    encodings.add(CoderUtils.encodeToByteArray(TEST_CODER, new Instant(timestamp)));
  }

  // Verify that the encodings were already sorted, since they were generated
  // in the correct order.
  List<byte[]> sortedEncodings = new ArrayList<>(encodings);
  Collections.sort(sortedEncodings, UnsignedBytes.lexicographicalComparator());

  Assert.assertEquals(encodings, sortedEncodings);
}
 
开发者ID:apache,项目名称:beam,代码行数:18,代码来源:InstantCoderTest.java

示例10: dumpEntry

import com.google.common.primitives.UnsignedBytes; //导入依赖的package包/类
private String dumpEntry(int offset) {
    if (DEBUG_SEARCH) {
        StringBuilder sb = new StringBuilder(200);
        for (int i = offset; i < mData.length; i++) {
            if (mData[i] == 0) {
                break;
            }
            char c = (char) UnsignedBytes.toInt(mData[i]);
            sb.append(c);
        }

        return sb.toString();
    } else {
        return "<disabled>"; //$NON-NLS-1$
    }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:17,代码来源:ApiLookup.java

示例11: getByteComparator

import com.google.common.primitives.UnsignedBytes; //导入依赖的package包/类
/**
 * Returns the byte comparator.
 *
 * @return the byte comparator
 */
public static Comparator<String> getByteComparator() {
  return new Comparator<String>() {

    /* see superclass */
    @Override
    public int compare(String o1, String o2) {
      try {
        return UnsignedBytes.lexicographicalComparator()
            .compare(o1.getBytes("UTF-8"), o2.getBytes("UTF-8"));
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    }

  };
}
 
开发者ID:WestCoastInformatics,项目名称:UMLS-Terminology-Server,代码行数:22,代码来源:ConfigUtility.java

示例12: writeTo

import com.google.common.primitives.UnsignedBytes; //导入依赖的package包/类
/**
 * Writes this {@code BloomFilter} to an output stream, with a custom format (not Java
 * serialization). This has been measured to save at least 400 bytes compared to regular
 * serialization.
 *
 * <p>Use {@linkplain #readFrom(InputStream, Funnel)} to reconstruct the written BloomFilter.
 */
public void writeTo(OutputStream out) throws IOException {
  /*
   * Serial form:
   * 1 signed byte for the strategy
   * 1 unsigned byte for the number of hash functions
   * 1 big endian int, the number of longs in our bitset
   * N big endian longs of our bitset
   */
  DataOutputStream dout = new DataOutputStream(out);
  dout.writeByte(SignedBytes.checkedCast(strategy.ordinal()));
  dout.writeByte(UnsignedBytes.checkedCast(numHashFunctions)); // note: checked at the c'tor
  dout.writeInt(bits.data.length);
  for (long value : bits.data) {
    dout.writeLong(value);
  }
}
 
开发者ID:sander120786,项目名称:guava-libraries,代码行数:24,代码来源:BloomFilter.java

示例13: toString

import com.google.common.primitives.UnsignedBytes; //导入依赖的package包/类
@Nonnull
public static String toString(@Nonnull byte[] data, @Nonnegative int start, @Nonnegative int len) {
    StringBuilder buf = new StringBuilder();
    buf.append("Array(start=").append(start).append(", len=").append(len).append(", data=[");
    int count = Math.min(32, len);
    for (int i = 0; i < count; i++) {
        if (i > 0)
            buf.append(", ");
        int idx = start + i;
        if (idx >= data.length) {
            buf.append("OOBE!");
            break;
        }
        buf.append(UnsignedBytes.toString(data[i], 16));
    }
    if (len > 32)
        buf.append(", ...");
    buf.append("])");
    return buf.toString();
}
 
开发者ID:shevek,项目名称:simple-xml-serializers,代码行数:21,代码来源:PersisterUtils.java

示例14: compareToCurrentToken

import com.google.common.primitives.UnsignedBytes; //导入依赖的package包/类
/**
 * Compare only the bytes within the window of the current token
 * @param key
 * @return return -1 if key is lessThan (before) this, 0 if equal, and 1 if key is after
 */
protected int compareToCurrentToken(Cell key) {
  int startIndex = rowLength - currentRowNode.getTokenLength();
  int endIndexExclusive = startIndex + currentRowNode.getTokenLength();
  for (int i = startIndex; i < endIndexExclusive; ++i) {
    if (i >= key.getRowLength()) {// key was shorter, so it's first
      return -1;
    }
    byte keyByte = CellUtil.getRowByte(key, i);
    byte thisByte = rowBuffer[i];
    if (keyByte == thisByte) {
      continue;
    }
    return UnsignedBytes.compare(keyByte, thisByte);
  }
  return 0;
}
 
开发者ID:tenggyut,项目名称:HIndex,代码行数:22,代码来源:PrefixTreeArraySearcher.java

示例15: toWireUnchecked

import com.google.common.primitives.UnsignedBytes; //导入依赖的package包/类
@Override
protected void toWireUnchecked(IpmiPacketContext context, ByteBuffer buffer) {
    buffer.put(messageTag);
    buffer.put(new byte[3]);    // reserved
    toWireIntLE(buffer, systemSessionId);
    buffer.put(consoleRandom);
    buffer.put(Bits.toByte(requestedMaximumPrivilegeLevel, privilegeLookupMode));
    buffer.putChar((char) 0); // reserved
    if (username != null) {
        byte[] usernameBytes = username.getBytes(Charsets.ISO_8859_1);
        buffer.put(UnsignedBytes.checkedCast(usernameBytes.length));    // Max is 0x10.
        buffer.put(usernameBytes);
    } else {
        buffer.put((byte) 0);
    }
}
 
开发者ID:shevek,项目名称:ipmi4j,代码行数:17,代码来源:IpmiRAKPMessage1.java


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