public class ClassList<T>
extends java.lang.Object
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:
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 optionswill 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.
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 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.
|
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.
|
private static final org.slf4j.Logger LOGGER
private static final java.lang.String[] KEYS
private java.lang.Class<T> base
private java.util.List<java.lang.Class<? extends T>> classes
private java.util.Map<java.lang.String,java.lang.String> options
public ClassList(java.lang.Class<T> base)
base
- Base class to which all classes are assignable.public ClassList(java.lang.String file, java.lang.Class<T> base) throws java.io.IOException
file
- Configuration file containing the list of classes.base
- Base class to which all classes are assignable.java.io.IOException
- if the file cannot be read.public ClassList(java.lang.String file, java.lang.Class<T> base, java.lang.Class<?> location) throws java.io.IOException
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.java.io.IOException
- if the file cannot be read.public java.util.Map<java.lang.String,java.lang.String> parseOptions(java.lang.String s)
s
- A string containing a series of options formatted as
key1=value1,key2=value2.public void parseLine(java.lang.String line)
line
- A string containing the class, options and commentspublic void parseFile(java.lang.String file, java.lang.Class<?> location) throws java.io.IOException
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.java.io.IOException
- if the file cannot be read.public void addClass(int index, java.lang.Class<? extends T> c)
public void addClass(java.lang.Class<? extends T> c)
public void removeClass(java.lang.Class<? extends T> c)
public void append(ClassList<T> c)
public void append(java.util.List<java.lang.Class<? extends T>> l)
public void prepend(ClassList<T> c)
public void prepend(java.util.List<java.lang.Class<? extends T>> l)
public java.lang.Class<? extends T>[] getClasses()
public java.util.Map<java.lang.String,java.lang.String> getOptions()
@Deprecated public boolean isWhitelistedKey(java.lang.String s)
isAllowedKey(String)
instead.public boolean isAllowedKey(java.lang.String s)
public void addOption(java.lang.String key, java.lang.String value)
private java.lang.Class<? extends T> cast(java.lang.Class<?> rawClass)
rawClass
- the class to be castCopyright © 2020 Open Microscopy Environment