本文整理汇总了Java中com.google.common.primitives.UnsignedBytes.compare方法的典型用法代码示例。如果您正苦于以下问题:Java UnsignedBytes.compare方法的具体用法?Java UnsignedBytes.compare怎么用?Java UnsignedBytes.compare使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.common.primitives.UnsignedBytes
的用法示例。
在下文中一共展示了UnsignedBytes.compare方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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;
}
示例2: 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);
}
}
示例3: 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;
}
示例4: getBinarySubtype
import com.google.common.primitives.UnsignedBytes; //导入方法依赖的package包/类
protected static BinarySubtype getBinarySubtype(byte readByte) {
switch (readByte) {
case 0x00:
return BinarySubtype.GENERIC;
case 0x01:
return BinarySubtype.FUNCTION;
case 0x02:
return BinarySubtype.OLD_BINARY;
case 0x03:
return BinarySubtype.OLD_UUID;
case 0x04:
return BinarySubtype.UUID;
case 0x05:
return BinarySubtype.MD5;
default: {
if (UnsignedBytes.compare(readByte, FIRST_USER_DEFINED) >= 0) {
return BinarySubtype.USER_DEFINED;
} else {
throw new AssertionError(
"Unrecognized binary type 0x" + UnsignedBytes.toString(readByte, 16));
}
}
}
}
示例5: getBinarySubtype
import com.google.common.primitives.UnsignedBytes; //导入方法依赖的package包/类
protected static BinarySubtype getBinarySubtype(byte readByte) {
switch (readByte) {
case 0x00:
return BinarySubtype.GENERIC;
case 0x01:
return BinarySubtype.FUNCTION;
case 0x02:
return BinarySubtype.OLD_BINARY;
case 0x03:
return BinarySubtype.OLD_UUID;
case 0x04:
return BinarySubtype.UUID;
case 0x05:
return BinarySubtype.MD5;
default:
{
if (UnsignedBytes.compare(readByte, FIRST_USER_DEFINED) >= 0) {
return BinarySubtype.USER_DEFINED;
} else {
throw new AssertionError(
"Unrecognized binary type 0x" + UnsignedBytes.toString(readByte, 16));
}
}
}
}
示例6: compareTo
import com.google.common.primitives.UnsignedBytes; //导入方法依赖的package包/类
private static int compareTo(byte[] left, byte[] right) {
if (isEmpty(left)) {
if (isEmpty(right)) {
return 0;
}
return 1;
} else if (isEmpty(right)) {
return -1;
}
int minLength = Math.min(left.length, right.length);
for (int i = 0; i < minLength; i++) {
int result = UnsignedBytes.compare(left[i], right[i]);
if (result != 0) {
return result;
}
}
return left.length - right.length;
}
示例7: compareTo
import com.google.common.primitives.UnsignedBytes; //导入方法依赖的package包/类
@Override
public int compareTo(@Nonnull ComparableByteString other) {
requireNonNull(other, "other is null");
ByteString otherBytes = other.bytes;
int n = Math.min(bytes.size(), otherBytes.size());
for (int i = 0, j = 0; i < n; i++, j++) {
int cmp = UnsignedBytes.compare(bytes.byteAt(i), otherBytes.byteAt(j));
if (cmp != 0) return cmp;
}
// one is the prefix of other then the longer is larger
return bytes.size() - otherBytes.size();
}
示例8: compareTo
import com.google.common.primitives.UnsignedBytes; //导入方法依赖的package包/类
@Override
public int compareTo(IpAddress o) {
// Compare first the version
if (this.version != o.version) {
return this.version.compareTo(o.version);
}
// Compare the bytes, one-by-one
for (int i = 0; i < this.octets.length; i++) {
if (this.octets[i] != o.octets[i]) {
return UnsignedBytes.compare(this.octets[i], o.octets[i]);
}
}
return 0; // Equal
}
示例9: compare
import com.google.common.primitives.UnsignedBytes; //导入方法依赖的package包/类
@Override public int compare(byte[] left, byte[] right) {
int minLength = Math.min(left.length, right.length);
for (int i = 0; i < minLength; i++) {
int result = UnsignedBytes.compare(left[i], right[i]);
if (result != 0) {
return result;
}
}
return left.length - right.length;
}
示例10: compareTo
import com.google.common.primitives.UnsignedBytes; //导入方法依赖的package包/类
@Override
public int compareTo(AtriumIpAddress o) {
// Compare first the version
if (this.version != o.version) {
return this.version.compareTo(o.version);
}
// Compare the bytes, one-by-one
for (int i = 0; i < this.octets.length; i++) {
if (this.octets[i] != o.octets[i]) {
return UnsignedBytes.compare(this.octets[i], o.octets[i]);
}
}
return 0; // Equal
}
示例11: compareTo
import com.google.common.primitives.UnsignedBytes; //导入方法依赖的package包/类
@Override
public int compareTo(KIdentifier o) {
for(int i=0; i<super.binaryValue.length; i++){
int byteComparison=UnsignedBytes.compare(binaryValue[i], o.binaryValue[i]);
if(byteComparison!=0){
return byteComparison;
}
}
return 0;
}
示例12: compareTo
import com.google.common.primitives.UnsignedBytes; //导入方法依赖的package包/类
/**
* Lexicographically compare two arrays.
*
* @param buffer1 left operand
* @param buffer2 right operand
* @param offset1 Where to start comparing in the left buffer
* @param offset2 Where to start comparing in the right buffer
* @param length1 How much to compare from the left buffer
* @param length2 How much to compare from the right buffer
* @return 0 if equal, < 0 if left is less than right, etc.
*/
@Override
public int compareTo(byte[] buffer1, int offset1, int length1,
byte[] buffer2, int offset2, int length2) {
// Short circuit equal case
if (buffer1 == buffer2 &&
offset1 == offset2 &&
length1 == length2) {
return 0;
}
int minLength = Math.min(length1, length2);
int minWords = minLength / Longs.BYTES;
int offset1Adj = offset1 + BYTE_ARRAY_BASE_OFFSET;
int offset2Adj = offset2 + BYTE_ARRAY_BASE_OFFSET;
/*
* Compare 8 bytes at a time. Benchmarking shows comparing 8 bytes at a
* time is no slower than comparing 4 bytes at a time even on 32-bit.
* On the other hand, it is substantially faster on 64-bit.
*/
for (int i = 0; i < minWords * Longs.BYTES; i += Longs.BYTES) {
long lw = theUnsafe.getLong(buffer1, offset1Adj + (long) i);
long rw = theUnsafe.getLong(buffer2, offset2Adj + (long) i);
long diff = lw ^ rw;
if (diff != 0) {
if (!littleEndian) {
return lessThanUnsigned(lw, rw) ? -1 : 1;
}
// Use binary search
int n = 0;
int y;
int x = (int) diff;
if (x == 0) {
x = (int) (diff >>> 32);
n = 32;
}
y = x << 16;
if (y == 0) {
n += 16;
} else {
x = y;
}
y = x << 8;
if (y == 0) {
n += 8;
}
return (int) (((lw >>> n) & 0xFFL) - ((rw >>> n) & 0xFFL));
}
}
// The epilogue to cover the last (minLength % 8) elements.
for (int i = minWords * Longs.BYTES; i < minLength; i++) {
int result = UnsignedBytes.compare(
buffer1[offset1 + i],
buffer2[offset2 + i]);
if (result != 0) {
return result;
}
}
return length1 - length2;
}
示例13: compareTo
import com.google.common.primitives.UnsignedBytes; //导入方法依赖的package包/类
/**
* Lexicographically compare two arrays.
*
* @param buffer1 left operand
* @param buffer2 right operand
* @param offset1 Where to start comparing in the left buffer
* @param offset2 Where to start comparing in the right buffer
* @param length1 How much to compare from the left buffer
* @param length2 How much to compare from the right buffer
* @return 0 if equal, < 0 if left is less than right, etc.
*/
@Override
public int compareTo(final byte[] buffer1, final int offset1, final int length1, final byte[] buffer2,
final int offset2, final int length2) {
// Short circuit equal case
if (buffer1 == buffer2 && offset1 == offset2 && length1 == length2) {
return 0;
}
final int minLength = Math.min(length1, length2);
final int minWords = minLength / Longs.BYTES;
final int offset1Adj = offset1 + BYTE_ARRAY_BASE_OFFSET;
final int offset2Adj = offset2 + BYTE_ARRAY_BASE_OFFSET;
/*
* Compare 8 bytes at a time. Benchmarking shows comparing 8
* bytes at a time is no slower than comparing 4 bytes at a time
* even on 32-bit. On the other hand, it is substantially faster
* on 64-bit.
*/
for (int i = 0; i < minWords * Longs.BYTES; i += Longs.BYTES) {
final long lw = theUnsafe.getLong(buffer1, offset1Adj + (long) i);
final long rw = theUnsafe.getLong(buffer2, offset2Adj + (long) i);
final long diff = lw ^ rw;
if (diff != 0) {
if (!littleEndian) {
return lessThanUnsigned(lw, rw) ? -1 : 1;
}
// Use binary search
int n = 0;
int y;
int x = (int) diff;
if (x == 0) {
x = (int) (diff >>> 32);
n = 32;
}
y = x << 16;
if (y == 0) {
n += 16;
} else {
x = y;
}
y = x << 8;
if (y == 0) {
n += 8;
}
return (int) ((lw >>> n & 0xFFL) - (rw >>> n & 0xFFL));
}
}
// The epilogue to cover the last (minLength % 8) elements.
for (int i = minWords * Longs.BYTES; i < minLength; i++) {
final int result = UnsignedBytes.compare(buffer1[offset1 + i], buffer2[offset2 + i]);
if (result != 0) {
return result;
}
}
return length1 - length2;
}
示例14: compareTo
import com.google.common.primitives.UnsignedBytes; //导入方法依赖的package包/类
@Override
public int compareTo(VlanPcp o) {
return UnsignedBytes.compare(pcp, o.pcp);
}
示例15: compareTo
import com.google.common.primitives.UnsignedBytes; //导入方法依赖的package包/类
@Override
public int compareTo(U8 o) {
return UnsignedBytes.compare(raw, o.raw);
}