Class ConstantInitializer<T>

  • Type Parameters:
    T - the type of the object managed by this initializer
    All Implemented Interfaces:
    ConcurrentInitializer<T>, FailableSupplier<T,​ConcurrentException>

    public class ConstantInitializer<T>
    extends java.lang.Object
    implements ConcurrentInitializer<T>
    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
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean equals​(java.lang.Object obj)
      Compares this object with another one.
      T get()
      Returns the object managed by this initializer.
      T getObject()
      Directly returns the object that was passed to the constructor.
      int hashCode()
      Returns a hash code for this object.
      boolean isInitialized()
      As a ConstantInitializer is initialized on construction this will always return true.
      java.lang.String toString()
      Returns a string representation for this object.
      • Methods inherited from class java.lang.Object

        getClass, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • ConstantInitializer

        public ConstantInitializer​(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 - the object to be managed by this initializer
    • Method Detail

      • equals

        public boolean equals​(java.lang.Object obj)
        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.
        Overrides:
        equals in class java.lang.Object
        Parameters:
        obj - the object to compare to
        Returns:
        a flag whether the objects are equal
      • getObject

        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:
        the object managed by this initializer
      • hashCode

        public int hashCode()
        Returns a hash code for this object. This implementation returns the hash code of the managed object.
        Overrides:
        hashCode in class java.lang.Object
        Returns:
        a hash code for this object
      • isInitialized

        public boolean isInitialized()
        As a ConstantInitializer is initialized on construction this will always return true.
        Returns:
        true.
        Since:
        3.14.0
      • toString

        public java.lang.String toString()
        Returns a string representation for this object. This string also contains a string representation of the object managed by this initializer.
        Overrides:
        toString in class java.lang.Object
        Returns:
        a string for this object