Record Class Constant<I>

java.lang.Object
java.lang.Record
org.microbean.bean.Constant<I>
Type Parameters:
I - the type of the singleton
Record Components:
singleton - the singleton
All Implemented Interfaces:
Constable, Aggregate, Factory<I>

public record Constant<I>(I singleton) extends Record implements Constable, Factory<I>
A Factory that returns its singleton from its create(Request) method.
Author:
Laird Nelson
See Also:
  • Constructor Details

  • Method Details

    • create

      public final I create(Request<I> r)
      Invokes the singleton() method and returns its result.
      Specified by:
      create in interface Factory<I>
      Parameters:
      r - a Request; may be null; ignored
      Returns:
      the result of invoking the singleton() method
      See Also:
    • destroys

      public final boolean destroys()
      Returns true if and only if the return value of an invocation of the singleton() method is AutoCloseable.
      Specified by:
      destroys in interface Factory<I>
      Returns:
      true if and only if the return value of an invocation of the singleton() method is AutoCloseable
      See Also:
    • destroy

      public final void destroy(I i, Request<I> request)
      Description copied from interface: Factory
      Destroys the supplied contextual instance.
      Specified by:
      destroy in interface Factory<I>
      Parameters:
      i - the contextual instance; may be null if this Factory suports returning null from its Factory.create(Request) method
      request - the Request that was present at creation time; may be null if it was null at creation time
    • 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