java.lang.Byte.compare()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(8.1k)|赞(0)|评价(0)|浏览(87)

本文整理了Java中java.lang.Byte.compare()方法的一些代码示例,展示了Byte.compare()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Byte.compare()方法的具体详情如下:
包路径:java.lang.Byte
类名称:Byte
方法名:compare

Byte.compare介绍

[英]Compares two byte values.
[中]比较两个字节的值。

代码示例

代码示例来源:origin: org.apache.commons/commons-lang3

/**
 * Appends to the <code>builder</code> the comparison of
 * two <code>byte</code>s.
 *
 * @param lhs  left-hand value
 * @param rhs  right-hand value
 * @return this - used to chain append calls
 */
public CompareToBuilder append(final byte lhs, final byte rhs) {
  if (comparison != 0) {
    return this;
  }
  comparison = Byte.compare(lhs, rhs);
  return this;
}

代码示例来源:origin: wildfly/wildfly

@Override
public int compareTo(SessionID id) {
  int result = this.encodedForm.length - id.encodedForm.length;
  for (int i = 0; (result == 0) && (i < this.encodedForm.length); ++i) {
    result = Byte.compare(this.encodedForm[i], id.encodedForm[i]);
  }
  return result;
}

代码示例来源:origin: robovm/robovm

/**
 * Compares this object to the specified byte object to determine their
 * relative order.
 *
 * @param object
 *            the byte object to compare this object to.
 * @return a negative value if the value of this byte is less than the value
 *         of {@code object}; 0 if the value of this byte and the value of
 *         {@code object} are equal; a positive value if the value of this
 *         byte is greater than the value of {@code object}.
 * @see java.lang.Comparable
 * @since 1.2
 */
public int compareTo(Byte object) {
  return compare(value, object.value);
}

代码示例来源:origin: apache/flink

@Override
public int compareTo(ValueArray<ByteValue> o) {
  ByteValueArray other = (ByteValueArray) o;
  int min = Math.min(position, other.position);
  for (int i = 0; i < min; i++) {
    int cmp = Byte.compare(data[i], other.data[i]);
    if (cmp != 0) {
      return cmp;
    }
  }
  return Integer.compare(position, other.position);
}

代码示例来源:origin: apache/flink

@Override
public int compareTo(ValueArray<StringValue> o) {
  StringValueArray other = (StringValueArray) o;
  // sorts first on number of data in the array, then comparison between
  // the first non-equal element in the arrays
  int cmp = Integer.compare(position, other.position);
  if (cmp != 0) {
    return cmp;
  }
  for (int i = 0; i < position; i++) {
    cmp = Byte.compare(data[i], other.data[i]);
    if (cmp != 0) {
      return cmp;
    }
  }
  return 0;
}

代码示例来源:origin: prestodb/presto

@Override
public int compareTo(Block leftBlock, int leftPosition, Block rightBlock, int rightPosition)
{
  // WARNING: the correctness of InCodeGenerator is dependent on the implementation of this
  // function being the equivalence of internal long representation.
  byte leftValue = leftBlock.getByte(leftPosition, 0);
  byte rightValue = rightBlock.getByte(rightPosition, 0);
  return Byte.compare(leftValue, rightValue);
}

代码示例来源:origin: prestodb/presto

@Override
public int compareTo(Block leftBlock, int leftPosition, Block rightBlock, int rightPosition)
{
  // WARNING: the correctness of InCodeGenerator is dependent on the implementation of this
  // function being the equivalence of internal long representation.
  byte leftValue = leftBlock.getByte(leftPosition, 0);
  byte rightValue = rightBlock.getByte(rightPosition, 0);
  return Byte.compare(leftValue, rightValue);
}

代码示例来源:origin: sleekbyte/tailor

/**
 * Checks whether a file is terminated with exactly one trailing newline.
 *
 * @param inputFile the file to check for a trailing newline
 * @return true if file is terminated with exactly one newline
 * @throws IOException if the file cannot be read
 */
public static boolean singleNewlineTerminated(File inputFile) throws IOException {
  RandomAccessFile randomAccessFile = new RandomAccessFile(inputFile, READ_ONLY_MODE);
  // Zero terminating newlines
  if (inputFile.length() < 1) {
    return true;
  }
  randomAccessFile.seek(inputFile.length() - 1);
  if (Byte.compare(randomAccessFile.readByte(), NEWLINE_DELIMITER) != 0) {
    return false;
  }
  // File contains a single newline character and nothing else
  if (inputFile.length() < 2) {
    return true;
  }
  // More than one terminating newline
  randomAccessFile.seek(inputFile.length() - 2);
  return (Byte.compare(randomAccessFile.readByte(), NEWLINE_DELIMITER) != 0);
}

代码示例来源:origin: neo4j/neo4j

private int byteArrayCompare( byte[] a, byte[] b, int fromPos )
{
  assert a != null && b != null : "Null arrays not supported.";
  if ( a == b )
  {
    return 0;
  }
  int length = Math.min( a.length, b.length );
  for ( int i = fromPos; i < length; i++ )
  {
    int compare = Byte.compare( a[i], b[i] );
    if ( compare != 0 )
    {
      return compare;
    }
  }
  return Integer.compare( a.length, b.length );
}

代码示例来源:origin: speedment/speedment

@Override
default int compare(T first, T second) {
  return Byte.compare(
    applyAsByte(first),
    applyAsByte(second)
  );
}

代码示例来源:origin: apache/flink

@Override
public int compareSerialized(DataInputView firstSource, DataInputView secondSource) throws IOException {
  int firstCount = firstSource.readInt();
  int secondCount = secondSource.readInt();
  int minCount = Math.min(firstCount, secondCount);
  while (minCount-- > 0) {
    byte firstValue = firstSource.readByte();
    byte secondValue = secondSource.readByte();
    int cmp = Byte.compare(firstValue, secondValue);
    if (cmp != 0) {
      return ascendingComparison ? cmp : -cmp;
    }
  }
  int cmp = Integer.compare(firstCount, secondCount);
  return ascendingComparison ? cmp : -cmp;
}

代码示例来源:origin: apache/ignite

/** {@inheritDoc} */
@Override protected int compare(final BPlusIO<IndexItem> io, final long pageAddr, final int idx,
  final IndexItem row) throws IgniteCheckedException {
  final int off = ((IndexIO)io).getOffset(pageAddr, idx);
  int shift = 0;
  // Compare index names.
  final int len = PageUtils.getUnsignedByte(pageAddr, off + shift);
  shift += BYTE_LEN;
  for (int i = 0; i < len && i < row.idxName.length; i++) {
    final int cmp = Byte.compare(PageUtils.getByte(pageAddr, off + i + shift), row.idxName[i]);
    if (cmp != 0)
      return cmp;
  }
  return Integer.compare(len, row.idxName.length);
}

代码示例来源:origin: real-logic/agrona

public int compareTo(final DirectBuffer that)
{
  final int thisCapacity = this.capacity;
  final int thatCapacity = that.capacity();
  final byte[] thisByteArray = this.byteArray;
  final byte[] thatByteArray = that.byteArray();
  final long thisOffset = this.addressOffset;
  final long thatOffset = that.addressOffset();
  for (int i = 0, length = Math.min(thisCapacity, thatCapacity); i < length; i++)
  {
    final int cmp = Byte.compare(
      UNSAFE.getByte(thisByteArray, thisOffset + i),
      UNSAFE.getByte(thatByteArray, thatOffset + i));
    if (0 != cmp)
    {
      return cmp;
    }
  }
  if (thisCapacity != thatCapacity)
  {
    return thisCapacity - thatCapacity;
  }
  return 0;
}

代码示例来源:origin: konsoletyper/teavm

@Override
public int compareTo(TByteBuffer other) {
  if (this == other) {
    return 0;
  }
  int sz = Math.min(remaining(), other.remaining());
  int a = position + start;
  int b = other.position + other.start;
  for (int i = 0; i < sz; ++i) {
    int r = Byte.compare(array[a++], other.array[b++]);
    if (r != 0) {
      return r;
    }
  }
  return Integer.compare(remaining(), other.remaining());
}

代码示例来源:origin: real-logic/agrona

public int compareTo(final DirectBuffer that)
{
  final int thisCapacity = this.capacity();
  final int thatCapacity = that.capacity();
  final byte[] thisByteArray = this.byteArray;
  final byte[] thatByteArray = that.byteArray();
  final long thisOffset = this.addressOffset();
  final long thatOffset = that.addressOffset();
  for (int i = 0, length = Math.min(thisCapacity, thatCapacity); i < length; i++)
  {
    final int cmp = Byte.compare(
      UNSAFE.getByte(thisByteArray, thisOffset + i),
      UNSAFE.getByte(thatByteArray, thatOffset + i));
    if (0 != cmp)
    {
      return cmp;
    }
  }
  if (thisCapacity != thatCapacity)
  {
    return thisCapacity - thatCapacity;
  }
  return 0;
}

代码示例来源:origin: real-logic/agrona

public int compareTo(final DirectBuffer that)
{
  final int thisCapacity = this.capacity();
  final int thatCapacity = that.capacity();
  final byte[] thisByteArray = null;
  final byte[] thatByteArray = that.byteArray();
  final long thisOffset = this.addressOffset();
  final long thatOffset = that.addressOffset();
  for (int i = 0, length = Math.min(thisCapacity, thatCapacity); i < length; i++)
  {
    final int cmp = Byte.compare(
      UNSAFE.getByte(thisByteArray, thisOffset + i),
      UNSAFE.getByte(thatByteArray, thatOffset + i));
    if (0 != cmp)
    {
      return cmp;
    }
  }
  if (thisCapacity != thatCapacity)
  {
    return thisCapacity - thatCapacity;
  }
  return 0;
}

代码示例来源:origin: speedment/speedment

@Override
public int compare(T first, T second) {
  final boolean f = isNull(first);
  final boolean s = isNull(second);
  if (f && s) return 0;
  else if (f) return 1;
  else if (s) return -1;
  else return Byte.compare(
    original.applyAsByte(first),
    original.applyAsByte(second)
  );
}

代码示例来源:origin: speedment/speedment

@Override
public int compare(ENTITY first, ENTITY second) {
  requireNonNulls(first, second);
  final byte a = field.getAsByte(first);
  final byte b = field.getAsByte(second);
  return applyReversed(Byte.compare(a, b));
}

代码示例来源:origin: speedment/speedment

@Override
default int compare(T first, T second) {
  if (isNull(first)) {
    return isNull(second) ? 0 : 1;
  } else if (isNull(second)) {
    return -1;
  } else {
    return Byte.compare(
      applyAsByte(first),
      applyAsByte(second)
    );
  }
}

代码示例来源:origin: apache/ignite

byte secondByte = second.arr[secondDataStart + i];
res = Byte.compare(firstByte, secondByte);

相关文章