Coverage Summary for Class: AbstractHashFunction (com.google.common.hash)

Class Class, % Method, % Line, %
AbstractHashFunction 0% (0/1) 0% (0/10) 0% (0/13)


1 /* 2  * Copyright (C) 2017 The Guava Authors 3  * 4  * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5  * in compliance with the License. You may obtain a copy of the License at 6  * 7  * http://www.apache.org/licenses/LICENSE-2.0 8  * 9  * Unless required by applicable law or agreed to in writing, software distributed under the License 10  * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11  * or implied. See the License for the specific language governing permissions and limitations under 12  * the License. 13  */ 14  15 package com.google.common.hash; 16  17 import static com.google.common.base.Preconditions.checkArgument; 18 import static com.google.common.base.Preconditions.checkPositionIndexes; 19  20 import com.google.errorprone.annotations.Immutable; 21 import java.nio.ByteBuffer; 22 import java.nio.charset.Charset; 23 import org.checkerframework.checker.nullness.qual.Nullable; 24  25 /** 26  * Skeleton implementation of {@link HashFunction} in terms of {@link #newHasher()}. 27  * 28  * <p>TODO(lowasser): make public 29  */ 30 @Immutable 31 @ElementTypesAreNonnullByDefault 32 abstract class AbstractHashFunction implements HashFunction { 33  @Override 34  public <T extends @Nullable Object> HashCode hashObject( 35  @ParametricNullness T instance, Funnel<? super T> funnel) { 36  return newHasher().putObject(instance, funnel).hash(); 37  } 38  39  @Override 40  public HashCode hashUnencodedChars(CharSequence input) { 41  int len = input.length(); 42  return newHasher(len * 2).putUnencodedChars(input).hash(); 43  } 44  45  @Override 46  public HashCode hashString(CharSequence input, Charset charset) { 47  return newHasher().putString(input, charset).hash(); 48  } 49  50  @Override 51  public HashCode hashInt(int input) { 52  return newHasher(4).putInt(input).hash(); 53  } 54  55  @Override 56  public HashCode hashLong(long input) { 57  return newHasher(8).putLong(input).hash(); 58  } 59  60  @Override 61  public HashCode hashBytes(byte[] input) { 62  return hashBytes(input, 0, input.length); 63  } 64  65  @Override 66  public HashCode hashBytes(byte[] input, int off, int len) { 67  checkPositionIndexes(off, off + len, input.length); 68  return newHasher(len).putBytes(input, off, len).hash(); 69  } 70  71  @Override 72  public HashCode hashBytes(ByteBuffer input) { 73  return newHasher(input.remaining()).putBytes(input).hash(); 74  } 75  76  @Override 77  public Hasher newHasher(int expectedInputSize) { 78  checkArgument( 79  expectedInputSize >= 0, "expectedInputSize must be >= 0 but was %s", expectedInputSize); 80  return newHasher(); 81  } 82 }