Record Class Constant<I>

java.lang.Object
java.lang.Record
org.microbean.bean.Constant<I>
All Implemented Interfaces:
Constable, Aggregate, Factory<I>

public record Constant<I>(I singleton) extends Record implements Constable, Factory<I>
  • Constructor Details

    • Constant

      public Constant(I singleton)
      Creates an instance of a Constant record class.
      Parameters:
      singleton - the value for the singleton record component
  • Method Details

    • create

      public final I create(Request<I> r)
      Description copied from interface: Factory
      Creates a new contextual instance, possibly using the supplied Request, if it is non-null, to acquire its dependencies.

      Implementations of this method must not call Factory.singleton().

      Implementations of this method should consider calling Creation.created(Object) on the supplied Request with the contextual instance about to be returned.

      Specified by:
      create in interface Factory<I>
      Parameters:
      r - a Request responsible for the demand for creation and used for acquiring any needed dependencies; may be null in early, uncommon bootstrap-like situations
      Returns:
      a new contextual instance, or null
      See Also:
    • destroys

      public final boolean destroys()
      Description copied from interface: Factory
      Returns true if this Factory implementation destroys its created contextual instances in some way, or false if it does not.

      The default implementation of this method returns true.

      Overrides of this method must be idempotent and return a determinate value.

      Specified by:
      destroys in interface Factory<I>
      Returns:
      true if this Factory implementation destroys its created contextual instances in some way; false otherwise
      See Also:
    • destroy

      public final void destroy(I i, Request<I> request)
      Specified by:
      destroy in interface Factory<I>
    • describeConstable

      Description copied from interface: Factory
      Returns an Optional containing the nominal descriptor for this instance, if one can be constructed, or an empty Optional if one cannot be constructed.

      The default implementation of this method returns an Optional that contains a dynamic constant representing an invocation of the implementation's constructor that takes no arguments. The resolution of this dynamic constant is undefined if the implementation does not declare such a constructor.

      Specified by:
      describeConstable in interface Constable
      Specified by:
      describeConstable in interface Factory<I>
      Returns:
      an Optional containing the nominal descriptor for this instance, if one can be constructed, or an empty Optional if one cannot be constructed
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with Objects::equals(Object,Object).
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • singleton

      public I singleton()
      Returns the value of the singleton record component.
      Specified by:
      singleton in interface Factory<I>
      Returns:
      the value of the singleton record component