Java Code Examples for java.nio.ByteBuffer#hashCode()

The following examples show how to use java.nio.ByteBuffer#hashCode() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BitBuffer.java    From zserio with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public int hashCode()
{
    int result = Util.HASH_SEED;

    final int byteSize = getByteSize();
    if (byteSize > 0)
    {
        if (byteSize > 1)
        {
            final ByteBuffer byteBuffer = ByteBuffer.wrap(buffer, 0, byteSize - 1);
            result = Util.HASH_PRIME_NUMBER * result + byteBuffer.hashCode();
        }
        result = Util.HASH_PRIME_NUMBER * result + getMaskedLastByte();
    }

    return result;
}
 
Example 2
Source File: PrefixCodedTerms.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Override
public int hashCode() {
  if (lazyHash == 0) {
    int h = 1;
    for (ByteBuffer bb : content) {
      h = h + 31 * bb.hashCode();
    }
    h = 31 * h + (int) (delGen ^ (delGen >>> 32));
    lazyHash = h;
  }
  return lazyHash;
}
 
Example 3
Source File: Dfu.java    From android-stm32-dfu-programmer with Apache License 2.0 5 votes vote down vote up
private boolean isDeviceBlank() throws Exception {

        byte[] readContent = new byte[dfuFile.elementLength];
        readImage(readContent);
        ByteBuffer read = ByteBuffer.wrap(readContent);    // wrap whole array
        int hash = read.hashCode();
        return (dfuFile.elementLength == Math.abs(hash));
    }
 
Example 4
Source File: TimeRange.java    From tajo with Apache License 2.0 5 votes vote down vote up
@Override
public int hashCode() {
	byte[] array = new byte[8];
	ByteBuffer bb = ByteBuffer.wrap(array);
	bb.putLong(this.begin);
	return bb.hashCode();
}
 
Example 5
Source File: MultiByteBuff.java    From hbase with Apache License 2.0 5 votes vote down vote up
@Override
public int hashCode() {
  int hash = 0;
  for (ByteBuffer b : this.items) {
    hash += b.hashCode();
  }
  return hash;
}
 
Example 6
Source File: TimeRange.java    From incubator-tajo with Apache License 2.0 5 votes vote down vote up
@Override
public int hashCode() {
	byte[] array = new byte[8];
	ByteBuffer bb = ByteBuffer.wrap(array);
	bb.putLong(this.begin);
	return bb.hashCode();
}
 
Example 7
Source File: StreamingGeometryGenerator.java    From BIMserver with GNU Affero General Public License v3.0 5 votes vote down vote up
int hash(ByteBuffer indices, ByteBuffer vertices, ByteBuffer normals, ByteBuffer colors) {
	int hashCode = 0;
	hashCode += indices.hashCode();
	hashCode += vertices.hashCode();
	hashCode += normals.hashCode();
	hashCode += colors.hashCode();
	
	return hashCode;
}
 
Example 8
Source File: SecureBuffer.java    From edslite with GNU General Public License v2.0 4 votes vote down vote up
@Override
public int hashCode()
{
    ByteBuffer d = getByteBuffer();
    return d != null ? d.hashCode() : 0;
}
 
Example 9
Source File: BaseState.java    From incubator-datasketches-memory with Apache License 2.0 4 votes vote down vote up
/**
 * Returns a formatted hex string of an area of this object.
 * Used primarily for testing.
 * @param state the BaseState
 * @param preamble a descriptive header
 * @param offsetBytes offset bytes relative to the Memory start
 * @param lengthBytes number of bytes to convert to a hex string
 * @return a formatted hex string in a human readable array
 */
static final String toHex(final BaseState state, final String preamble, final long offsetBytes,
    final int lengthBytes) {
  final long capacity = state.getCapacity();
  UnsafeUtil.checkBounds(offsetBytes, lengthBytes, capacity);
  final StringBuilder sb = new StringBuilder();
  final Object uObj = state.getUnsafeObject();
  final String uObjStr;
  final long uObjHeader;
  if (uObj == null) {
    uObjStr = "null";
    uObjHeader = 0;
  } else {
    uObjStr =  uObj.getClass().getSimpleName() + ", " + (uObj.hashCode() & 0XFFFFFFFFL);
    uObjHeader = UnsafeUtil.getArrayBaseOffset(uObj.getClass());
  }
  final ByteBuffer bb = state.getByteBuffer();
  final String bbStr = (bb == null) ? "null"
          : bb.getClass().getSimpleName() + ", " + (bb.hashCode() & 0XFFFFFFFFL);
  final MemoryRequestServer memReqSvr = state.getMemoryRequestServer();
  final String memReqStr = (memReqSvr != null)
      ? memReqSvr.getClass().getSimpleName() + ", " + (memReqSvr.hashCode() & 0XFFFFFFFFL)
      : "null";
  final long cumBaseOffset = state.getCumulativeOffset();
  sb.append(preamble).append(LS);
  sb.append("UnsafeObj, hashCode : ").append(uObjStr).append(LS);
  sb.append("UnsafeObjHeader     : ").append(uObjHeader).append(LS);
  sb.append("ByteBuf, hashCode   : ").append(bbStr).append(LS);
  sb.append("RegionOffset        : ").append(state.getRegionOffset()).append(LS);
  sb.append("Capacity            : ").append(capacity).append(LS);
  sb.append("CumBaseOffset       : ").append(cumBaseOffset).append(LS);
  sb.append("MemReq, hashCode    : ").append(memReqStr).append(LS);
  sb.append("Valid               : ").append(state.isValid()).append(LS);
  sb.append("Read Only           : ").append(state.isReadOnly()).append(LS);
  sb.append("Type Byte Order     : ").append(state.getTypeByteOrder().toString()).append(LS);
  sb.append("Native Byte Order   : ").append(nativeByteOrder.toString()).append(LS);
  sb.append("JDK Runtime Version : ").append(UnsafeUtil.JDK).append(LS);
  //Data detail
  sb.append("Data, littleEndian  :  0  1  2  3  4  5  6  7");

  for (long i = 0; i < lengthBytes; i++) {
    final int b = unsafe.getByte(uObj, cumBaseOffset + offsetBytes + i) & 0XFF;
    if ((i % 8) == 0) { //row header
      sb.append(String.format("%n%20s: ", offsetBytes + i));
    }
    sb.append(String.format("%02x ", b));
  }
  sb.append(LS);

  return sb.toString();
}
 
Example 10
Source File: URLSerDe.java    From attic-apex-malhar with Apache License 2.0 4 votes vote down vote up
@Override
public int getPartition(byte[] object)
{
  ByteBuffer bb = ByteBuffer.wrap(object);
  return bb.hashCode();
}