All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.google.common.hash.AbstractHashFunction Maven / Gradle / Ivy

Go to download

This artifact provides a single jar that contains all classes required to use remote EJB and JMS, including all dependencies. It is intended for use by those not using maven, maven users should just import the EJB and JMS BOM's instead (shaded JAR's cause lots of problems with maven, as it is very easy to inadvertently end up with different versions on classes on the class path).

The newest version!
/*
 * Copyright (C) 2017 The Guava Authors
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
 * in compliance with the License. You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software distributed under the License
 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
 * or implied. See the License for the specific language governing permissions and limitations under
 * the License.
 */

package com.google.common.hash;

import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkPositionIndexes;

import com.google.errorprone.annotations.Immutable;
import java.nio.ByteBuffer;
import java.nio.charset.Charset;
import org.checkerframework.checker.nullness.qual.Nullable;

/**
 * Skeleton implementation of {@link HashFunction} in terms of {@link #newHasher()}.
 *
 * 

TODO(lowasser): make public */ @Immutable @ElementTypesAreNonnullByDefault abstract class AbstractHashFunction implements HashFunction { @Override public HashCode hashObject( @ParametricNullness T instance, Funnel funnel) { return newHasher().putObject(instance, funnel).hash(); } @Override public HashCode hashUnencodedChars(CharSequence input) { int len = input.length(); return newHasher(len * 2).putUnencodedChars(input).hash(); } @Override public HashCode hashString(CharSequence input, Charset charset) { return newHasher().putString(input, charset).hash(); } @Override public HashCode hashInt(int input) { return newHasher(4).putInt(input).hash(); } @Override public HashCode hashLong(long input) { return newHasher(8).putLong(input).hash(); } @Override public HashCode hashBytes(byte[] input) { return hashBytes(input, 0, input.length); } @Override public HashCode hashBytes(byte[] input, int off, int len) { checkPositionIndexes(off, off + len, input.length); return newHasher(len).putBytes(input, off, len).hash(); } @Override public HashCode hashBytes(ByteBuffer input) { return newHasher(input.remaining()).putBytes(input).hash(); } @Override public Hasher newHasher(int expectedInputSize) { checkArgument( expectedInputSize >= 0, "expectedInputSize must be >= 0 but was %s", expectedInputSize); return newHasher(); } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy