An immutable hash code of arbitrary bit length. @author Dimitris Andreou @author Kurt Alfred Kluever @since 11.0
| 35 | |
| 36 | |
| 37 | @Beta |
| 38 | public abstract class HashCode { |
| 39 | HashCode() {} |
| 40 | |
| 41 | /** |
| 42 | * Returns the number of bits in this hash code; a positive multiple of 8. |
| 43 | */ |
| 44 | |
| 45 | |
| 46 | public abstract int bits(); |
| 47 | |
| 48 | /** |
| 49 | * Returns the first four bytes of {@linkplain #asBytes() this hashcode's bytes}, converted to an |
| 50 | * {@code int} value in little-endian order. |
| 51 | * |
| 52 | * @throws IllegalStateException if {@code bits() < 32} |
| 53 | */ |
| 54 | |
| 55 | |
| 56 | public abstract int asInt(); |
| 57 | |
| 58 | /** |
| 59 | * Returns the first eight bytes of {@linkplain #asBytes() this hashcode's bytes}, converted to a |
| 60 | * {@code long} value in little-endian order. |
| 61 | * |
| 62 | * @throws IllegalStateException if {@code bits() < 64} |
| 63 | */ |
| 64 | |
| 65 | |
| 66 | public abstract long asLong(); |
| 67 | |
| 68 | /** |
| 69 | * If this hashcode has enough bits, returns {@code asLong()}, otherwise returns a {@code long} |
| 70 | * value with {@code asBytes()} as the least-significant bytes and {@code 0x00} as the remaining |
| 71 | * most-significant bytes. |
| 72 | * |
| 73 | * @since 14.0 (since 11.0 as {@code Hashing.padToLong(HashCode)}) |
| 74 | */ |
| 75 | |
| 76 | |
| 77 | public abstract long padToLong(); |
| 78 | |
| 79 | /** |
| 80 | * Returns the value of this hash code as a byte array. The caller may modify the byte array; |
| 81 | * changes to it will <i>not</i> be reflected in this {@code HashCode} object or any other arrays |
| 82 | * returned by this method. |
| 83 | */ |
| 84 | // TODO(user): consider ByteString here, when that is available |
| 85 | |
| 86 | |
| 87 | public abstract byte[] asBytes(); |
| 88 | |
| 89 | /** |
| 90 | * Copies bytes from this hash code into {@code dest}. |
| 91 | * |
| 92 | * @param dest the byte array into which the hash code will be written |
| 93 | * @param offset the start offset in the data |
| 94 | * @param maxLength the maximum number of bytes to write |
nothing calls this directly
no test coverage detected