本文整理汇总了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);
}
示例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>";
}
}
示例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();
}
示例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;
}
示例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);
}
}
示例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);
}
示例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);
}
}
示例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;
}
示例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);
}
示例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$
}
}
示例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);
}
}
};
}
示例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);
}
}
示例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();
}
示例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;
}
示例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);
}
}