Class Installable<T>

java.lang.Object
eu.bandm.tools.util.files.Installable<T>
Type Parameters:
T - the type of object to store
All Implemented Interfaces:
Supplier<T>

public class Installable<T> extends Object implements Supplier<T>
Store a reference to an object that may be created at runtime or serialized as a resource.
  • Field Details

  • Constructor Details

    • Installable

      public Installable(Class<?> ownerClass, Class<? extends T> valueClass, String name, @Opt @Opt Supplier<? extends T> creator)
      Create a new instance.

      An attempt is made to load the serialized object as a resource. If that fails, the object is created newly.

      Parameters:
      ownerClass - the class that owns the stored object and the resource
      valueClass - the type of the stored object
      the - simple name of the object and resource
      creator - a function object to create the object on the fly
      Throws:
      IllegalArgumentException - if name is not a valid Java identifier
  • Method Details

    • get

      public T get()
      Return the stored object.
      Specified by:
      get in interface Supplier<T>
    • getResourceName

      public String getResourceName()
      Return the resource name for the stored object.
    • store

      public void store(File targetDirectory) throws IOException
      Store the object in a file.

      The relative file name is the resource name for the stored object.

      To install the file as a resource, place it in the classpath beside the owner class.

      Parameters:
      targetDirectory - the target directory
      Throws:
      IOException - if the object file cannot be written.