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

public final Class Interners

extends Object
Class Inheritance
Annotations
@J2ktIncompatible
@GwtIncompatible
@ElementTypesAreNonnullByDefault
Static Imports
com.google.common.base.Preconditions.checkNotNull

Contains static methods pertaining to instances of Interner.
Author
Kevin Bourrillion
Since
3.0

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class
Interners.InternerBuilder

Builder for Interner instances.

private static class
pack-priv static class

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static <E> Function<E, E>
asFunction(Interner<E> interner)

Returns a function that delegates to the Interner#intern method of the given interner.

public static Interners.InternerBuilder
newBuilder()

Returns a fresh InternerBuilder instance.

public static <E> Interner<E>
newStrongInterner()

Returns a new thread-safe interner which retains a strong reference to each instance it has interned, thus preventing these instances from being garbage-collected.

public static <E> Interner<E>
newWeakInterner()

Returns a new thread-safe interner which retains a weak reference to each instance it has interned, and so does not prevent these instances from being garbage-collected.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

Internersback to summary
private Interners()

Method Detail

asFunctionback to summary
public static <E> Function<E, E> asFunction(Interner<E> interner)

Returns a function that delegates to the Interner#intern method of the given interner.

Since
8.0
newBuilderback to summary
public static Interners.InternerBuilder newBuilder()

Returns a fresh InternerBuilder instance.

newStrongInternerback to summary
public static <E> Interner<E> newStrongInterner()

Returns a new thread-safe interner which retains a strong reference to each instance it has interned, thus preventing these instances from being garbage-collected. If this retention is acceptable, this implementation may perform better than newWeakInterner.

newWeakInternerback to summary
public static <E> Interner<E> newWeakInterner()

Returns a new thread-safe interner which retains a weak reference to each instance it has interned, and so does not prevent these instances from being garbage-collected. This most likely does not perform as well as newStrongInterner, but is the best alternative when the memory usage of that implementation is unacceptable.

Annotations
@GwtIncompatible:WeakReference
com.google.common.collect back to summary

public Class Interners.InternerBuilder

extends Object
Class Inheritance

Builder for Interner instances.
Since
21.0

Field Summary

Modifier and TypeField and Description
private final MapMaker
private boolean

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public <E> Interner<E>
public Interners.InternerBuilder
concurrencyLevel(int concurrencyLevel)

Sets the concurrency level that will be used by the to-be-built Interner.

public Interners.InternerBuilder
strong()

Instructs the InternerBuilder to build a strong interner.

public Interners.InternerBuilder
weak()

Instructs the InternerBuilder to build a weak interner.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

mapMakerback to summary
private final MapMaker mapMaker
strongback to summary
private boolean strong

Constructor Detail

InternerBuilderback to summary
private InternerBuilder()

Method Detail

buildback to summary
public <E> Interner<E> build()
concurrencyLevelback to summary
public Interners.InternerBuilder concurrencyLevel(int concurrencyLevel)

Sets the concurrency level that will be used by the to-be-built Interner.

See Also
MapMaker#concurrencyLevel(int)
strongback to summary
public Interners.InternerBuilder strong()

Instructs the InternerBuilder to build a strong interner.

See Also
Interners#newStrongInterner()
weakback to summary
public Interners.InternerBuilder weak()

Instructs the InternerBuilder to build a weak interner.

Annotations
@GwtIncompatible:WeakReference
See Also
Interners#newWeakInterner()
com.google.common.collect back to summary

private Class Interners.InternerFunction<E>

extends Object
implements Function<E, E>
Class Inheritance
All Implemented Interfaces
com.google.common.base.Function, java.util.function.Function

Field Summary

Modifier and TypeField and Description
private final Interner<E>

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public E
apply(E
the function argument
input
)

Implements com.google.common.base.Function.apply.

Applies this function to the given argument.
public boolean
equals(Object
the reference object with which to compare.
other
)

Overrides java.lang.Object.equals.

Implements com.google.common.base.Function.equals.

May return true if object is a Function that behaves identically to this function.
public int
hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for this object.
Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAlltoStringwaitwaitwait

Field Detail

internerback to summary
private final Interner<E> interner

Constructor Detail

InternerFunctionback to summary
public InternerFunction(Interner<E> interner)

Method Detail

applyback to summary
public E apply(E input)

Implements com.google.common.base.Function.apply.

Doc from java.util.function.Function.apply.

Applies this function to the given argument.

Parameters
input:E

the function argument

Returns:E

the function result

Annotations
@Override
equalsback to summary
public boolean equals(Object other)

Overrides java.lang.Object.equals.

Implements com.google.common.base.Function.equals.

Doc from com.google.common.base.Function.equals.

May return true if object is a Function that behaves identically to this function.

Warning: do not depend on the behavior of this method.

Historically, Function instances in this library have implemented this method to recognize certain cases where distinct Function instances would in fact behave identically. However, as code migrates to java.util.function, that behavior will disappear. It is best not to depend on it.

Parameters
other:Object

Doc from java.lang.Object.equals.

the reference object with which to compare.

Returns:boolean

Doc from java.lang.Object.equals.

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

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
com.google.common.collect back to summary

pack-priv final Class Interners.InternerImpl<E>

extends Object
implements Interner<E>
Class Inheritance
All Implemented Interfaces
com.google.common.collect.Interner
Annotations
@VisibleForTesting

Field Summary

Modifier and TypeField and Description
pack-priv final MapMakerInternalMap<E, MapMaker.Dummy, ?, ?>

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public E
intern(E sample)

Implements com.google.common.collect.Interner.intern.

Chooses and returns the representative instance for any of a collection of instances that are equal to each other.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

mapback to summary
pack-priv final MapMakerInternalMap<E, MapMaker.Dummy, ?, ?> map
Annotations
@VisibleForTesting

Constructor Detail

InternerImplback to summary
private InternerImpl(MapMaker mapMaker)

Method Detail

internback to summary
public E intern(E sample)

Implements com.google.common.collect.Interner.intern.

Doc from com.google.common.collect.Interner.intern.

Chooses and returns the representative instance for any of a collection of instances that are equal to each other. If two equal inputs are given to this method, both calls will return the same instance. That is, intern(a).equals(a) always holds, and intern(a) == intern(b) if and only if a.equals(b). Note that intern(a) is permitted to return one instance now and a different instance later if the original interned instance was garbage-collected.

Warning

do not use with mutable objects.

Annotations
@Override