Record Class ClosePolicyWrapper<T>

java.lang.Object
java.lang.Record
org.aksw.vshell.registry.ClosePolicyWrapper<T>
Type Parameters:
T -
All Implemented Interfaces:
AutoCloseable

public record ClosePolicyWrapper<T>(T entity, AutoCloseable closeAction, boolean doClose) extends Record implements AutoCloseable
Helper class for wrapping entities with a close action for use with try-with-resources blocks. Usage example:
try (ClosePolicyWrapper<T> wrapper = ClosePolicyWrapper.dontClose(entity)) { // Or use .doClose
  // ...
}
  • Constructor Details

    • ClosePolicyWrapper

      public ClosePolicyWrapper(T entity, AutoCloseable closeAction, boolean doClose)
      Creates an instance of a ClosePolicyWrapper record class.
      Parameters:
      entity - the value for the entity record component
      closeAction - the value for the closeAction record component
      doClose - the value for the doClose record component
  • Method Details

    • doClose

      public static <T extends AutoCloseable> ClosePolicyWrapper<T> doClose(T entity)
    • dontClose

      public static <T extends AutoCloseable> ClosePolicyWrapper<T> dontClose(T entity)
    • close

      public void close() throws Exception
      Specified by:
      close in interface AutoCloseable
      Throws:
      Exception
    • 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. Reference components are compared with Objects::equals(Object,Object); primitive components are compared with the compare method from their corresponding wrapper classes.
      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.
    • entity

      public T entity()
      Returns the value of the entity record component.
      Returns:
      the value of the entity record component
    • closeAction

      public AutoCloseable closeAction()
      Returns the value of the closeAction record component.
      Returns:
      the value of the closeAction record component
    • doClose

      public boolean doClose()
      Returns the value of the doClose record component.
      Returns:
      the value of the doClose record component