loci.formats

## Class ClassList<T>

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

-     public class ClassList<T>
      extends java.lang.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 Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `private java.lang.Class<T>` | `base` Base class to which all classes are assignable.
    `private java.util.List<java.lang.Class<? extends T>>` | `classes` List of classes.
    `private static java.lang.String[]` | `KEYS`
    `private static org.slf4j.Logger` | `LOGGER`
    `private java.util.Map<java.lang.String,java.lang.String>` | `options` List of options.

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `ClassList(java.lang.Class<T> base)` Constructs a list of classes, initially empty.
    `ClassList(java.lang.String file, java.lang.Class<T> base)` Constructs a list of classes from the given configuration file.
    `ClassList(java.lang.String file, java.lang.Class<T> base, java.lang.Class<?> location)` Constructs a list of classes from the given configuration file.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods Deprecated Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `addClass(java.lang.Class<? extends T> c)` Adds the given class, which must be assignable to the base class, to the list.
    `void` | `addClass(int index, java.lang.Class<? extends T> c)` Adds the given class, which must be assignable to the base class, to the list.
    `void` | `addOption(java.lang.String key, java.lang.String value)` Add a key/value pair to the list of options.
    `void` | `append(ClassList<T> c)` Appends a class list which must be assignable to the base class
    `void` | `append(java.util.List<java.lang.Class<? extends T>> l)` Appends a list of classes which must be assignable to the base class
    `private java.lang.Class<? extends T>` | `cast(java.lang.Class<?> rawClass)` Cast the given class to something that extends the base class.
    `java.lang.Class<? extends T>[]` | `getClasses()` Gets the list of classes as an array.
    `java.util.Map<java.lang.String,java.lang.String>` | `getOptions()` Gets the list of options as a map.
    `boolean` | `isAllowedKey(java.lang.String s)` Returns whether a given key is an allowed option.
    `boolean` | `isWhitelistedKey(java.lang.String s)` Deprecated. Use `isAllowedKey(String)` instead.
    `void` | `parseFile(java.lang.String file, java.lang.Class<?> location)` Parses a list of classes from a configuration file.
    `void` | `parseLine(java.lang.String line)` Parses a class from a string including options and comments.
    `java.util.Map<java.lang.String,java.lang.String>` | `parseOptions(java.lang.String s)` Parses one or more options from a string.
    `void` | `prepend(ClassList<T> c)` Prepends a class list which must be assignable to the base class
    `void` | `prepend(java.util.List<java.lang.Class<? extends T>> l)` Prepends a list of classes which must be assignable to the base class
    `void` | `removeClass(java.lang.Class<? extends T> c)` Removes the given class from the list.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### LOGGER

          private static final org.slf4j.Logger LOGGER

    - #### KEYS

          private static final java.lang.String[] KEYS

    - #### base

          private java.lang.Class<T> base

      Base class to which all classes are assignable.

    - #### classes

          private java.util.List<java.lang.Class<? extends T>> classes

      List of classes.

    - #### options

          private java.util.Map<java.lang.String,java.lang.String> options

      List of options.

  - ### Constructor Detail

    - #### ClassList

          public ClassList(java.lang.Class<T> base)

      Constructs a list of classes, initially empty.
      Parameters:
        `base` - Base class to which all classes are assignable.

    - #### ClassList

          public ClassList(java.lang.String file,
                           java.lang.Class<T> base)
                    throws java.io.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:
        `java.io.IOException` - if the file cannot be read.

    - #### ClassList

          public ClassList(java.lang.String file,
                           java.lang.Class<T> base,
                           java.lang.Class<?> location)
                    throws java.io.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:
        `java.io.IOException` - if the file cannot be read.

  - ### Method Detail

    - #### parseOptions

          public java.util.Map<java.lang.String,java.lang.String> parseOptions(java.lang.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(java.lang.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(java.lang.String file,
                                java.lang.Class<?> location)
                         throws java.io.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:
        `java.io.IOException` - if the file cannot be read.

    - #### addClass

          public void addClass(int index,
                               java.lang.Class<? extends T> c)

      Adds the given class, which must be assignable to the base class, to the list.

    - #### addClass

          public void addClass(java.lang.Class<? extends T> c)

      Adds the given class, which must be assignable to the base class, to the list.

    - #### removeClass

          public void removeClass(java.lang.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(java.util.List<java.lang.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(java.util.List<java.lang.Class<? extends T>> l)

      Prepends a list of classes which must be assignable to the base class

    - #### getClasses

          public java.lang.Class<? extends T>[] getClasses()

      Gets the list of classes as an array.

    - #### getOptions

          public java.util.Map<java.lang.String,java.lang.String> getOptions()

      Gets the list of options as a map.

    - #### isWhitelistedKey

          @Deprecated
          public boolean isWhitelistedKey(java.lang.String s)

      Deprecated. Use `isAllowedKey(String)` instead.
      Returns whether a given key is an allowed option.

    - #### isAllowedKey

          public boolean isAllowedKey(java.lang.String s)

      Returns whether a given key is an allowed option.

    - #### addOption

          public void addOption(java.lang.String key,
                                java.lang.String value)

      Add a key/value pair to the list of options.

    - #### cast

          private java.lang.Class<? extends T> cast(java.lang.Class<?> rawClass)

      Cast the given class to something that extends the base class.
      Parameters:
        `rawClass` - the class to be cast

Copyright © 2026 Open Microscopy Environment