MCPcopy
hub / github.com/google/guava / AbstractHasher

Class AbstractHasher

android/guava/src/com/google/common/hash/AbstractHasher.java:29–135  ·  view source on GitHub ↗

An abstract implementation of {@link Hasher}, which only requires subtypes to implement {@link #putByte}. Subtypes may provide more efficient implementations, however. @author Dimitris Andreou

Source from the content-addressed store, hash-verified

27 * @author Dimitris Andreou
28 */
29abstract class AbstractHasher implements Hasher {
30 @Override
31 @CanIgnoreReturnValue
32 public final Hasher putBoolean(boolean b) {
33 return putByte(b ? (byte) 1 : (byte) 0);
34 }
35
36 @Override
37 @CanIgnoreReturnValue
38 public final Hasher putDouble(double d) {
39 return putLong(Double.doubleToRawLongBits(d));
40 }
41
42 @Override
43 @CanIgnoreReturnValue
44 public final Hasher putFloat(float f) {
45 return putInt(Float.floatToRawIntBits(f));
46 }
47
48 @Override
49 @CanIgnoreReturnValue
50 public Hasher putUnencodedChars(CharSequence charSequence) {
51 for (int i = 0, len = charSequence.length(); i < len; i++) {
52 putChar(charSequence.charAt(i));
53 }
54 return this;
55 }
56
57 @Override
58 @CanIgnoreReturnValue
59 public Hasher putString(CharSequence charSequence, Charset charset) {
60 return putBytes(charSequence.toString().getBytes(charset));
61 }
62
63 @Override
64 @CanIgnoreReturnValue
65 public Hasher putBytes(byte[] bytes) {
66 return putBytes(bytes, 0, bytes.length);
67 }
68
69 @Override
70 @CanIgnoreReturnValue
71 public Hasher putBytes(byte[] bytes, int off, int len) {
72 Preconditions.checkPositionIndexes(off, off + len, bytes.length);
73 for (int i = 0; i < len; i++) {
74 putByte(bytes[off + i]);
75 }
76 return this;
77 }
78
79 @Override
80 @CanIgnoreReturnValue
81 public Hasher putBytes(ByteBuffer b) {
82 if (b.hasArray()) {
83 putBytes(b.array(), b.arrayOffset() + b.position(), b.remaining());
84 Java8Compatibility.position(b, b.limit());
85 } else {
86 for (int remaining = b.remaining(); remaining > 0; remaining--) {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected