Record Class KiwiIO.CloseableResource

java.lang.Object
java.lang.Record
org.kiwiproject.io.KiwiIO.CloseableResource
Record Components:
object - the resource that can be closed
closeMethodNames - a non-null, non-empty list of close method names
Enclosing class:
KiwiIO

public static record KiwiIO.CloseableResource(@Nullable Object object, List<String> closeMethodNames) extends Record
Represents a resource that can be closed using a "close" method.

Allows multiple close method names to be specified, which can be useful in situations where you want to close several resources that have different "close" methods. For example, any AutoCloseable contains a "close" method while any ExecutorService has both "shutdown" and "shutdownNow" methods.

If you only need a single clsoe method name, or the default close method names, you can use one of the secondary constructors.

  • Constructor Details

    • CloseableResource

      public CloseableResource(@Nullable Object object, List<String> closeMethodNames)
      Creates an instance of a CloseableResource record class.
      Parameters:
      object - the value for the object record component
      closeMethodNames - the value for the closeMethodNames record component
    • CloseableResource

      public CloseableResource(@Nullable Object object)
      Create a new instance with a default set of close method names.
      Parameters:
      object - the resource that can be closed
      See Also:
    • CloseableResource

      public CloseableResource(@Nullable Object object, String closeMethodName)
      Create a new instance with a single close method name.
      Parameters:
      object - the resource that can be closed
      closeMethodName - the single close method name
  • Method Details

    • 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.
    • object

      public @Nullable Object object()
      Returns the value of the object record component.
      Returns:
      the value of the object record component
    • closeMethodNames

      public List<String> closeMethodNames()
      Returns the value of the closeMethodNames record component.
      Returns:
      the value of the closeMethodNames record component