Top Description Fields Constructors Methods
org.apache.commons.lang3.concurrent

public Class ConstantInitializer<T>

extends Object
implements ConcurrentInitializer<T>
Class Inheritance
All Implemented Interfaces
org.apache.commons.lang3.concurrent.ConcurrentInitializer, org.apache.commons.lang3.function.FailableSupplier
Type Parameters
<T>
the type of the object managed by this initializer
Imports
java.util.Objects

A very simple implementation of the ConcurrentInitializer interface which always returns the same object.

An instance of this class is passed a reference to an object when it is constructed. The get() method just returns this object. No synchronization is required.

This class is useful for instance for unit testing or in cases where a specific object has to be passed to an object which expects a ConcurrentInitializer.

Since
3.0

Field Summary

Modifier and TypeField and Description
private static final String
FMT_TO_STRING

Constant for the format of the string representation.

private final T
object

Stores the managed object.

Constructor Summary

AccessConstructor and Description
public
ConstantInitializer(final T
the object to be managed by this initializer
obj
)

Creates a new instance of ConstantInitializer and initializes it with the object to be managed.

Method Summary

Modifier and TypeMethod and Description
public boolean

Returns:

a flag whether the objects are equal
equals
(final Object
the object to compare to
obj
)

Overrides java.lang.Object.equals.

Compares this object with another one.

public T

Returns:

the object managed by this initializer
get
()

Implements org.apache.commons.lang3.function.FailableSupplier.get.

Gets the object managed by this initializer.

public final T

Returns:

the object managed by this initializer
getObject
()

Directly returns the object that was passed to the constructor.

public int

Returns:

a hash code for this object
hashCode
()

Overrides java.lang.Object.hashCode.

Returns a hash code for this object.

public boolean

Returns:

true.
isInitialized
()

As a ConstantInitializer is initialized on construction this will always return true.

public String

Returns:

a string for this object
toString
()

Overrides java.lang.Object.toString.

Returns a string representation for this object.

Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAllwaitwaitwait

Field Detail

FMT_TO_STRINGback to summary
private static final String FMT_TO_STRING

Constant for the format of the string representation.

objectback to summary
private final T object

Stores the managed object.

Constructor Detail

ConstantInitializerback to summary
public ConstantInitializer(final T obj)

Creates a new instance of ConstantInitializer and initializes it with the object to be managed. The get() method will always return the object passed here. This class does not place any restrictions on the object. It may be null, then get() will return null, too.

Parameters
obj:T

the object to be managed by this initializer

Method Detail

equalsback to summary
public boolean equals(final Object obj)

Overrides java.lang.Object.equals.

Compares this object with another one. This implementation returns true if and only if the passed in object is an instance of ConstantInitializer which refers to an object equals to the object managed by this instance.

Parameters
obj:Object

the object to compare to

Returns:boolean

a flag whether the objects are equal

Annotations
@Override
getback to summary
public T get() throws ConcurrentException

Implements org.apache.commons.lang3.function.FailableSupplier.get.

Gets the object managed by this initializer. This implementation just returns the object passed to the constructor.

Returns:T

the object managed by this initializer

Annotations
@Override
Exceptions
ConcurrentException:
if an error occurs
getObjectback to summary
public final T getObject()

Directly returns the object that was passed to the constructor. This is the same object as returned by get(). However, this method does not declare that it throws an exception.

Returns:T

the object managed by this initializer

hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code for this object. This implementation returns the hash code of the managed object.

Returns:int

a hash code for this object

Annotations
@Override
isInitializedback to summary
public boolean isInitialized()

As a ConstantInitializer is initialized on construction this will always return true.

Returns:boolean

true.

Since
3.14.0
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Returns a string representation for this object. This string also contains a string representation of the object managed by this initializer.

Returns:String

a string for this object

Annotations
@Override