Top Description Inners Constructors Methods
com.google.common.hash

public final Class Funnels

extends Object
Class Inheritance
Annotations
@Beta
@ElementTypesAreNonnullByDefault
Imports
com.google.common.annotations.Beta, com.google.common.base.Preconditions, java.io.InvalidObjectException, .ObjectInputStream, .OutputStream, .Serializable, java.nio.charset.Charset, javax.annotation.CheckForNull, org.checkerframework.checker.nullness.qual.Nullable

Funnels for common types. All implementations are serializable.
Author
Dimitris Andreou
Since
11.0

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static enum
private static enum
private static enum
private static class
private static class
private static class
private static enum

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static OutputStream
asOutputStream(PrimitiveSink sink)

Wraps a PrimitiveSink as an OutputStream, so it is easy to funnel an object to a PrimitiveSink if there is already a way to write the contents of the object to an OutputStream.

public static Funnel<byte[]>
byteArrayFunnel()

Returns a funnel that extracts the bytes from a byte array.

public static Funnel<Integer>
integerFunnel()

Returns a funnel for integers.

public static Funnel<Long>
longFunnel()

Returns a funnel for longs.

public static <E extends @Nullable Object> Funnel<Iterable<? extends E>>
sequentialFunnel(Funnel<E> elementFunnel)

Returns a funnel that processes an Iterable by funneling its elements in iteration order with the specified funnel.

public static Funnel<CharSequence>
stringFunnel(Charset charset)

Returns a funnel that encodes the characters of a CharSequence with the specified Charset.

public static Funnel<CharSequence>
unencodedCharsFunnel()

Returns a funnel that extracts the characters from a CharSequence, a character at a time, without performing any encoding.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

Funnelsback to summary
private Funnels()

Method Detail

asOutputStreamback to summary
public static OutputStream asOutputStream(PrimitiveSink sink)

Wraps a PrimitiveSink as an OutputStream, so it is easy to funnel an object to a PrimitiveSink if there is already a way to write the contents of the object to an OutputStream.

The close and flush methods of the returned OutputStream do nothing, and no method throws IOException.

Since
13.0
byteArrayFunnelback to summary
public static Funnel<byte[]> byteArrayFunnel()

Returns a funnel that extracts the bytes from a byte array.

integerFunnelback to summary
public static Funnel<Integer> integerFunnel()

Returns a funnel for integers.

Since
13.0
longFunnelback to summary
public static Funnel<Long> longFunnel()

Returns a funnel for longs.

Since
13.0
sequentialFunnelback to summary
public static <E extends @Nullable Object> Funnel<Iterable<? extends E>> sequentialFunnel(Funnel<E> elementFunnel)

Returns a funnel that processes an Iterable by funneling its elements in iteration order with the specified funnel. No separators are added between the elements.

Since
15.0
stringFunnelback to summary
public static Funnel<CharSequence> stringFunnel(Charset charset)

Returns a funnel that encodes the characters of a CharSequence with the specified Charset.

Since
15.0
unencodedCharsFunnelback to summary
public static Funnel<CharSequence> unencodedCharsFunnel()

Returns a funnel that extracts the characters from a CharSequence, a character at a time, without performing any encoding. If you need to use a specific encoding, use Funnels#stringFunnel(Charset) instead.

Since
15.0 (since 11.0 as Funnels.stringFunnel().
com.google.common.hash back to summary

private final Enum Funnels.ByteArrayFunnel

extends Enum<Funnels.ByteArrayFunnel>
implements Funnel<byte[]>
Class Inheritance
All Implemented Interfaces
com.google.common.hash.Funnel, java.io.Serializable

Field Summary

Modifier and TypeField and Description
public static final Funnels.ByteArrayFunnel

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public void
funnel(byte[] from, PrimitiveSink into)

Implements com.google.common.hash.Funnel.funnel.

Sends a stream of data from the from object into the sink into.
public String
toString()

Overrides java.lang.Enum.toString.

Returns the name of this enum constant, as contained in the declaration.
public static Funnels.ByteArrayFunnel
public static Funnels.ByteArrayFunnel[]
Inherited from java.lang.Enum:
clonecompareTodescribeConstableequalsfinalizegetDeclaringClasshashCodenameordinalvalueOf

Field Detail

INSTANCEback to summary
public static final Funnels.ByteArrayFunnel INSTANCE

Constructor Detail

ByteArrayFunnelback to summary
private ByteArrayFunnel()

Method Detail

funnelback to summary
public void funnel(byte[] from, PrimitiveSink into)

Implements com.google.common.hash.Funnel.funnel.

Doc from com.google.common.hash.Funnel.funnel.

Sends a stream of data from the from object into the sink into. There is no requirement that this data be complete enough to fully reconstitute the object later.

Annotations
@Override
toStringback to summary
public String toString()

Overrides java.lang.Enum.toString.

Doc from java.lang.Enum.toString.

Returns the name of this enum constant, as contained in the declaration. This method may be overridden, though it typically isn't necessary or desirable. An enum class should override this method when a more "programmer-friendly" string form exists.

Returns:String

the name of this enum constant

Annotations
@Override
valueOfback to summary
public static Funnels.ByteArrayFunnel valueOf(String name)
valuesback to summary
public static Funnels.ByteArrayFunnel[] values()
com.google.common.hash back to summary

private final Enum Funnels.IntegerFunnel

extends Enum<Funnels.IntegerFunnel>
implements Funnel<Integer>
Class Inheritance
All Implemented Interfaces
com.google.common.hash.Funnel, java.io.Serializable

Field Summary

Modifier and TypeField and Description
public static final Funnels.IntegerFunnel

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public void
funnel(Integer from, PrimitiveSink into)

Implements com.google.common.hash.Funnel.funnel.

Sends a stream of data from the from object into the sink into.
public String
toString()

Overrides java.lang.Enum.toString.

Returns the name of this enum constant, as contained in the declaration.
public static Funnels.IntegerFunnel
public static Funnels.IntegerFunnel[]
Inherited from java.lang.Enum:
clonecompareTodescribeConstableequalsfinalizegetDeclaringClasshashCodenameordinalvalueOf

Field Detail

INSTANCEback to summary
public static final Funnels.IntegerFunnel INSTANCE

Constructor Detail

IntegerFunnelback to summary
private IntegerFunnel()

Method Detail

funnelback to summary
public void funnel(Integer from, PrimitiveSink into)

Implements com.google.common.hash.Funnel.funnel.

Doc from com.google.common.hash.Funnel.funnel.

Sends a stream of data from the from object into the sink into. There is no requirement that this data be complete enough to fully reconstitute the object later.

Annotations
@Override
toStringback to summary
public String toString()

Overrides java.lang.Enum.toString.

Doc from java.lang.Enum.toString.

Returns the name of this enum constant, as contained in the declaration. This method may be overridden, though it typically isn't necessary or desirable. An enum class should override this method when a more "programmer-friendly" string form exists.

Returns:String

the name of this enum constant

Annotations
@Override
valueOfback to summary
public static Funnels.IntegerFunnel valueOf(String name)
valuesback to summary
public static Funnels.IntegerFunnel[] values()
com.google.common.hash back to summary

private final Enum Funnels.LongFunnel

extends Enum<Funnels.LongFunnel>
implements Funnel<Long>
Class Inheritance
All Implemented Interfaces
com.google.common.hash.Funnel, java.io.Serializable

Field Summary

Modifier and TypeField and Description
public static final Funnels.LongFunnel

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public void
funnel(Long from, PrimitiveSink into)

Implements com.google.common.hash.Funnel.funnel.

Sends a stream of data from the from object into the sink into.
public String
toString()

Overrides java.lang.Enum.toString.

Returns the name of this enum constant, as contained in the declaration.
public static Funnels.LongFunnel
public static Funnels.LongFunnel[]
Inherited from java.lang.Enum:
clonecompareTodescribeConstableequalsfinalizegetDeclaringClasshashCodenameordinalvalueOf

Field Detail

INSTANCEback to summary
public static final Funnels.LongFunnel INSTANCE

Constructor Detail

LongFunnelback to summary
private LongFunnel()

Method Detail

funnelback to summary
public void funnel(Long from, PrimitiveSink into)

Implements com.google.common.hash.Funnel.funnel.

Doc from com.google.common.hash.Funnel.funnel.

Sends a stream of data from the from object into the sink into. There is no requirement that this data be complete enough to fully reconstitute the object later.

Annotations
@Override
toStringback to summary
public String toString()

Overrides java.lang.Enum.toString.

Doc from java.lang.Enum.toString.

Returns the name of this enum constant, as contained in the declaration. This method may be overridden, though it typically isn't necessary or desirable. An enum class should override this method when a more "programmer-friendly" string form exists.

Returns:String

the name of this enum constant

Annotations
@Override
valueOfback to summary
public static Funnels.LongFunnel valueOf(String name)
valuesback to summary
public static Funnels.LongFunnel[] values()
com.google.common.hash back to summary

private Class Funnels.SequentialFunnel<E extends @Nullable Object>

extends Object
implements Funnel<Iterable<? extends E extends @Nullable Object>>, Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable, com.google.common.hash.Funnel

Field Summary

Modifier and TypeField and Description
private final Funnel<E>

Constructor Summary

AccessConstructor and Description
pack-priv
SequentialFunnel(Funnel<E> elementFunnel)

Method Summary

Modifier and TypeMethod and Description
public boolean
equals(Object
the reference object with which to compare.
o
)

Overrides java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.
public void
funnel(Iterable<? extends E> from, PrimitiveSink into)

Implements com.google.common.hash.Funnel.funnel.

Sends a stream of data from the from object into the sink into.
public int
hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for this object.
public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.
Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAllwaitwaitwait

Field Detail

elementFunnelback to summary
private final Funnel<E> elementFunnel

Constructor Detail

SequentialFunnelback to summary
pack-priv SequentialFunnel(Funnel<E> elementFunnel)

Method Detail

equalsback to summary
public boolean equals(Object o)

Overrides java.lang.Object.equals.

Doc from java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

The equals method implements an equivalence relation on non-null object references:

  • It is reflexive: for any non-null reference value x, x.equals(x) should return true.
  • It is symmetric: for any non-null reference values x and y, x.equals(y) should return true if and only if y.equals(x) returns true.
  • It is transitive: for any non-null reference values x, y, and z, if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.
  • It is consistent: for any non-null reference values x and y, multiple invocations of x.equals(y) consistently return true or consistently return false, provided no information used in equals comparisons on the objects is modified.
  • For any non-null reference value x, x.equals(null) should return false.

An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes.

Parameters
o:Object

the reference object with which to compare.

Returns:boolean

true if this object is the same as the obj argument; false otherwise.

Annotations
@Override
funnelback to summary
public void funnel(Iterable<? extends E> from, PrimitiveSink into)

Implements com.google.common.hash.Funnel.funnel.

Doc from com.google.common.hash.Funnel.funnel.

Sends a stream of data from the from object into the sink into. There is no requirement that this data be complete enough to fully reconstitute the object later.

Annotations
@Override
hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Doc from java.lang.Object.hashCode.

Returns a hash code value for this object. This method is supported for the benefit of hash tables such as those provided by java.util.HashMap.

The general contract of hashCode is:

  • Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
  • If two objects are equal according to the equals method, then calling the hashCode method on each of the two objects must produce the same integer result.
  • It is not required that if two objects are unequal according to the equals method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.
Returns:int

a hash code value for this object

Annotations
@Override
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object.

Returns:String

a string representation of the object

Annotations
@Override
com.google.common.hash back to summary

private Class Funnels.SinkAsStream

extends OutputStream
Class Inheritance

Field Summary

Modifier and TypeField and Description
pack-priv final PrimitiveSink

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.
public void
write(int
the byte.
b
)

Implements abstract java.io.OutputStream.write.

Writes the specified byte to this output stream.
public void
write(byte[]
the data.
bytes
)

Overrides java.io.OutputStream.write.

Writes b.length bytes from the specified byte array to this output stream.
public void
write(byte[]
the data.
bytes
,
int
the start offset in the data.
off
,
int
the number of bytes to write.
len
)

Overrides java.io.OutputStream.write.

Writes len bytes from the specified byte array starting at offset off to this output stream.
Inherited from java.io.OutputStream:
closeflushnullOutputStream

Field Detail

sinkback to summary
pack-priv final PrimitiveSink sink

Constructor Detail

SinkAsStreamback to summary
pack-priv SinkAsStream(PrimitiveSink sink)

Method Detail

toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object.

Returns:String

a string representation of the object

Annotations
@Override
writeback to summary
public void write(int b)

Implements abstract java.io.OutputStream.write.

Doc from java.io.OutputStream.write.

Writes the specified byte to this output stream. The general contract for write is that one byte is written to the output stream. The byte to be written is the eight low-order bits of the argument b. The 24 high-order bits of b are ignored.

Parameters
b:int

the byte.

Annotations
@Override
writeback to summary
public void write(byte[] bytes)

Overrides java.io.OutputStream.write.

Doc from java.io.OutputStream.write.

Writes b.length bytes from the specified byte array to this output stream. The general contract for write(b) is that it should have exactly the same effect as the call write(b, 0, b.length).

Parameters
bytes:byte[]

the data.

Annotations
@Override
writeback to summary
public void write(byte[] bytes, int off, int len)

Overrides java.io.OutputStream.write.

Doc from java.io.OutputStream.write.

Writes len bytes from the specified byte array starting at offset off to this output stream. The general contract for write(b, off, len) is that some of the bytes in the array b are written to the output stream in order; element b[off] is the first byte written and b[off+len-1] is the last byte written by this operation.

If b is null, a NullPointerException is thrown.

If off is negative, or len is negative, or off+len is greater than the length of the array b, then an IndexOutOfBoundsException is thrown.

Parameters
bytes:byte[]

the data.

off:int

the start offset in the data.

len:int

the number of bytes to write.

Annotations
@Override
com.google.common.hash back to summary

private Class Funnels.StringCharsetFunnel

extends Object
implements Funnel<CharSequence>, Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable, com.google.common.hash.Funnel

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class

Field Summary

Modifier and TypeField and Description
private final Charset

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public boolean
equals(Object
the reference object with which to compare.
o
)

Overrides java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.
public void
funnel(CharSequence from, PrimitiveSink into)

Implements com.google.common.hash.Funnel.funnel.

Sends a stream of data from the from object into the sink into.
public int
hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for this object.
private void
public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.
pack-priv Object
Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAllwaitwaitwait

Field Detail

charsetback to summary
private final Charset charset

Constructor Detail

StringCharsetFunnelback to summary
pack-priv StringCharsetFunnel(Charset charset)

Method Detail

equalsback to summary
public boolean equals(Object o)

Overrides java.lang.Object.equals.

Doc from java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

The equals method implements an equivalence relation on non-null object references:

  • It is reflexive: for any non-null reference value x, x.equals(x) should return true.
  • It is symmetric: for any non-null reference values x and y, x.equals(y) should return true if and only if y.equals(x) returns true.
  • It is transitive: for any non-null reference values x, y, and z, if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.
  • It is consistent: for any non-null reference values x and y, multiple invocations of x.equals(y) consistently return true or consistently return false, provided no information used in equals comparisons on the objects is modified.
  • For any non-null reference value x, x.equals(null) should return false.

An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes.

Parameters
o:Object

the reference object with which to compare.

Returns:boolean

true if this object is the same as the obj argument; false otherwise.

Annotations
@Override
funnelback to summary
public void funnel(CharSequence from, PrimitiveSink into)

Implements com.google.common.hash.Funnel.funnel.

Doc from com.google.common.hash.Funnel.funnel.

Sends a stream of data from the from object into the sink into. There is no requirement that this data be complete enough to fully reconstitute the object later.

Annotations
@Override
hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Doc from java.lang.Object.hashCode.

Returns a hash code value for this object. This method is supported for the benefit of hash tables such as those provided by java.util.HashMap.

The general contract of hashCode is:

  • Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
  • If two objects are equal according to the equals method, then calling the hashCode method on each of the two objects must produce the same integer result.
  • It is not required that if two objects are unequal according to the equals method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.
Returns:int

a hash code value for this object

Annotations
@Override
readObjectback to summary
private void readObject(ObjectInputStream stream) throws InvalidObjectException
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object.

Returns:String

a string representation of the object

Annotations
@Override
writeReplaceback to summary
pack-priv Object writeReplace()
com.google.common.hash back to summary

private Class Funnels.StringCharsetFunnel.SerializedForm

extends Object
implements Serializable
Class Inheritance
  • java.lang.Object
  • com.google.common.hash.Funnels.StringCharsetFunnel.SerializedForm
All Implemented Interfaces
java.io.Serializable

Field Summary

Modifier and TypeField and Description
private final String
private static final long

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
private Object
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

charsetCanonicalNameback to summary
private final String charsetCanonicalName
serialVersionUIDback to summary
private static final long serialVersionUID

Constructor Detail

SerializedFormback to summary
pack-priv SerializedForm(Charset charset)

Method Detail

readResolveback to summary
private Object readResolve()
com.google.common.hash back to summary

private final Enum Funnels.UnencodedCharsFunnel

extends Enum<Funnels.UnencodedCharsFunnel>
implements Funnel<CharSequence>
Class Inheritance
All Implemented Interfaces
com.google.common.hash.Funnel, java.io.Serializable

Field Summary

Modifier and TypeField and Description
public static final Funnels.UnencodedCharsFunnel

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public void
funnel(CharSequence from, PrimitiveSink into)

Implements com.google.common.hash.Funnel.funnel.

Sends a stream of data from the from object into the sink into.
public String
toString()

Overrides java.lang.Enum.toString.

Returns the name of this enum constant, as contained in the declaration.
public static Funnels.UnencodedCharsFunnel
public static Funnels.UnencodedCharsFunnel[]
Inherited from java.lang.Enum:
clonecompareTodescribeConstableequalsfinalizegetDeclaringClasshashCodenameordinalvalueOf

Field Detail

INSTANCEback to summary
public static final Funnels.UnencodedCharsFunnel INSTANCE

Constructor Detail

UnencodedCharsFunnelback to summary
private UnencodedCharsFunnel()

Method Detail

funnelback to summary
public void funnel(CharSequence from, PrimitiveSink into)

Implements com.google.common.hash.Funnel.funnel.

Doc from com.google.common.hash.Funnel.funnel.

Sends a stream of data from the from object into the sink into. There is no requirement that this data be complete enough to fully reconstitute the object later.

Annotations
@Override
toStringback to summary
public String toString()

Overrides java.lang.Enum.toString.

Doc from java.lang.Enum.toString.

Returns the name of this enum constant, as contained in the declaration. This method may be overridden, though it typically isn't necessary or desirable. An enum class should override this method when a more "programmer-friendly" string form exists.

Returns:String

the name of this enum constant

Annotations
@Override
valueOfback to summary
public static Funnels.UnencodedCharsFunnel valueOf(String name)
valuesback to summary
public static Funnels.UnencodedCharsFunnel[] values()