Package loci.formats

Class ClassList<T>

java.lang.Object
loci.formats.ClassList<T>

public class ClassList<T> extends Object
ClassList is a list of classes for use with ImageReader or ImageWriter, parsed from a configuration file such as readers.txt or writers.txt.

When constructing a ClassList object, each line of the configuration file is parsed using the following rules:

  • all text following a hash symbol # is interpreted as comments and ignored
  • a key-value pair options can be specified for a given class by using the square brackets [] and an equal separator =
  • multiple options can be passed for each class and need to be separated using a comma,

For instance, constructing a ClassList object using the absolute path to a configuration file containing the following lines:

 # List of classes
 package1.class1
 package2.class2 # a simple class
 package3.class3[key1=value1,key2=value2] # a class with options
 
will attempt to create a list of three classes . Additionally, if the last class is added, two key/value pairs will be stored in the options map: package3.class3.key1=value and package3.class3.key2=value2.
Author:
Curtis Rueden ctrueden at wisc.edu
  • Field Details

    • LOGGER

      private static final org.slf4j.Logger LOGGER
    • KEYS

      private static final String[] KEYS
    • base

      private Class<T> base
      Base class to which all classes are assignable.
    • classes

      private List<Class<? extends T>> classes
      List of classes.
    • options

      private Map<String,String> options
      List of options.
  • Constructor Details

    • ClassList

      public ClassList(Class<T> base)
      Constructs a list of classes, initially empty.
      Parameters:
      base - Base class to which all classes are assignable.
    • ClassList

      public ClassList(String file, Class<T> base) throws IOException
      Constructs a list of classes from the given configuration file.
      Parameters:
      file - Configuration file containing the list of classes.
      base - Base class to which all classes are assignable.
      Throws:
      IOException - if the file cannot be read.
    • ClassList

      public ClassList(String file, Class<T> base, Class<?> location) throws IOException
      Constructs a list of classes from the given configuration file.
      Parameters:
      file - Configuration file containing the list of classes.
      base - Base class to which all classes are assignable.
      location - Class indicating which package to search for the file. If null, 'file' is interpreted as an absolute path name.
      Throws:
      IOException - if the file cannot be read.
  • Method Details

    • parseOptions

      public Map<String,String> parseOptions(String s)
      Parses one or more options from a string.
      Parameters:
      s - A string containing a series of options formatted as key1=value1,key2=value2.
      Returns:
      a map populated with the parsed key/value pairs
    • parseLine

      public void parseLine(String line)
      Parses a class from a string including options and comments. This function assumes the string is formatted as package.class[key1=value1,key2=value2] # comments. Options will be parsed and stored in a local map. If the class can be loaded, then each key/value pair will be stored in the options as package.class.key/value.
      Parameters:
      line - A string containing the class, options and comments
    • parseFile

      public void parseFile(String file, Class<?> location) throws IOException
      Parses a list of classes from a configuration file.
      Parameters:
      file - Configuration file containing the list of classes.
      location - Class indicating which package to search for the file. If null, 'file' is interpreted as an absolute path name.
      Throws:
      IOException - if the file cannot be read.
    • addClass

      public void addClass(int index, Class<? extends T> c)
      Adds the given class, which must be assignable to the base class, to the list.
    • addClass

      public void addClass(Class<? extends T> c)
      Adds the given class, which must be assignable to the base class, to the list.
    • removeClass

      public void removeClass(Class<? extends T> c)
      Removes the given class from the list.
    • append

      public void append(ClassList<T> c)
      Appends a class list which must be assignable to the base class
    • append

      public void append(List<Class<? extends T>> l)
      Appends a list of classes which must be assignable to the base class
    • prepend

      public void prepend(ClassList<T> c)
      Prepends a class list which must be assignable to the base class
    • prepend

      public void prepend(List<Class<? extends T>> l)
      Prepends a list of classes which must be assignable to the base class
    • getClasses

      public Class<? extends T>[] getClasses()
      Gets the list of classes as an array.
    • getOptions

      public Map<String,String> getOptions()
      Gets the list of options as a map.
    • isWhitelistedKey

      @Deprecated public boolean isWhitelistedKey(String s)
      Deprecated.
      Returns whether a given key is an allowed option.
    • isAllowedKey

      public boolean isAllowedKey(String s)
      Returns whether a given key is an allowed option.
    • addOption

      public void addOption(String key, String value)
      Add a key/value pair to the list of options.
    • cast

      private Class<? extends T> cast(Class<?> rawClass)
      Cast the given class to something that extends the base class.
      Parameters:
      rawClass - the class to be cast