本文整理匯總了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);
}
}