Top Description Inners Constructors Methods
com.google.inject.util

public final Class Providers

extends Object
Class Inheritance
Annotations
@CheckReturnValue
Static Imports
com.google.common.base.Preconditions.checkNotNull, com.google.common.collect.ImmutableSet.toImmutableSet

Static utility methods for creating and working with instances of Provider.
Author
Kevin Bourrillion ([email protected])
Since
2.0

Nested and Inner Type Summary

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

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static <T> Provider<T>
guicify(Provider<T> provider)

Deprecated Marked as deprecated as a hint to users that calling this is unnecessary, because the provider is already a guice Provider.
Returns itself.
public static <T> Provider<T>
guicify(Provider<T> provider)

Returns a Guice-friendly com.google.inject.Provider for the given jakarta.inject.Provider.

public static <T> Provider<T>
of(final T
the instance that should always be provided. This is also permitted to be null, to enable aggressive testing, although in real life a Guice-supplied Provider will never return null.
instance
)

Returns a provider which always provides instance.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

Providersback to summary
private Providers()

Method Detail

guicifyback to summary
public static <T> Provider<T> guicify(Provider<T> provider)

Deprecated

Marked as deprecated as a hint to users that calling this is unnecessary, because the provider is already a guice Provider.

Returns itself. This exists primarily to avoid ambiguous method reference compile errors when calling guicify with a Guice provider.

Annotations
@Deprecated
Since
6.0
guicifyback to summary
public static <T> Provider<T> guicify(Provider<T> provider)

Returns a Guice-friendly com.google.inject.Provider for the given jakarta.inject.Provider. The converse method is unnecessary, since Guice providers directly implement the jakarta.inject.Provider interface.

Since
6.0
ofback to summary
public static <T> Provider<T> of(final T instance)

Returns a provider which always provides instance. This should not be necessary to use in your application, but is helpful for several types of unit tests.

Parameters
instance:T

the instance that should always be provided. This is also permitted to be null, to enable aggressive testing, although in real life a Guice-supplied Provider will never return null.

com.google.inject.util back to summary

private final Class Providers.ConstantProvider<T>

extends Object
implements Provider<T>
Class Inheritance
All Implemented Interfaces
com.google.inject.Provider, jakarta.inject.Provider

Field Summary

Modifier and TypeField and Description
private final T

Constructor Summary

AccessConstructor and Description
private
ConstantProvider(T instance)

Method Summary

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

Overrides java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.
public T
get()

Implements com.google.inject.Provider.get.

Provides an instance of T.
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

instanceback to summary
private final T instance

Constructor Detail

ConstantProviderback to summary
private ConstantProvider(T instance)

Method Detail

equalsback to summary
public boolean equals(Object obj)

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
obj: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
getback to summary
public T get()

Implements com.google.inject.Provider.get.

Doc from com.google.inject.Provider.get.

Provides an instance of T.

Returns:T

Doc from jakarta.inject.Provider.get.

instance of T.

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.inject.util back to summary

private Class Providers.GuicifiedJakartaProvider<T>

extends Object
implements Provider<T>
Class Inheritance
All Implemented Interfaces
com.google.inject.Provider, jakarta.inject.Provider
Known Direct Subclasses
com.google.inject.util.Providers.GuicifiedJakartaProviderWithDependencies

Field Summary

Modifier and TypeField and Description
protected final Provider<T>

Constructor Summary

AccessConstructor and Description
private

Method Summary

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

Overrides java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.
public T
get()

Implements com.google.inject.Provider.get.

Provides an instance of T.
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

delegateback to summary
protected final Provider<T> delegate

Constructor Detail

GuicifiedJakartaProviderback to summary
private GuicifiedJakartaProvider(Provider<T> delegate)

Method Detail

equalsback to summary
public boolean equals(Object obj)

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
obj: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
getback to summary
public T get()

Implements com.google.inject.Provider.get.

Doc from com.google.inject.Provider.get.

Provides an instance of T.

Returns:T

Doc from jakarta.inject.Provider.get.

instance of T.

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.inject.util back to summary

private final Class Providers.GuicifiedJakartaProviderWithDependencies<T>

extends Providers.GuicifiedJakartaProvider<T>
implements ProviderWithDependencies<T>
Class Inheritance
All Implemented Interfaces
com.google.inject.spi.ProviderWithDependencies, com.google.inject.spi.HasDependencies, com.google.inject.Provider, jakarta.inject.Provider

Field Summary

Modifier and TypeField and Description
private final Set<Dependency<?>>
Inherited from com.google.inject.util.Providers.GuicifiedJakartaProvider:
delegate

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public Set<Dependency<?>>
getDependencies()

Implements com.google.inject.spi.HasDependencies.getDependencies.

Returns the known dependencies for this type.
pack-priv void
initialize(Injector injector)

Inherited from com.google.inject.util.Providers.GuicifiedJakartaProvider:
equalsgethashCodetoString

Field Detail

dependenciesback to summary
private final Set<Dependency<?>> dependencies

Constructor Detail

GuicifiedJakartaProviderWithDependenciesback to summary
private GuicifiedJakartaProviderWithDependencies(Set<Dependency<?>> dependencies, Provider<T> delegate)

Method Detail

getDependenciesback to summary
public Set<Dependency<?>> getDependencies()

Implements com.google.inject.spi.HasDependencies.getDependencies.

Doc from com.google.inject.spi.HasDependencies.getDependencies.

Returns the known dependencies for this type. If this has dependencies whose values are not known statically, a dependency for the Injector will be included in the returned set.

Returns:Set<Dependency<?>>

a possibly empty set

Annotations
@Override
initializeback to summary
pack-priv void initialize(Injector injector)
Annotations
@SuppressWarnings:unused
@Inject