Class ExclusiveDataProvider<T>
- Type Parameters:
T- type of managed data
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classImplement this parser to use parsed -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final ExclusiveDataProvider.Parser<String> Parser that just returns the received lines. -
Constructor Summary
ConstructorsConstructorDescriptionExclusiveDataProvider(String fileName, boolean filterLineComments, ExclusiveDataProvider.Parser<T> parser) Creates a newExclusiveDataProviderinstance and initializes it with the agent's exclusive data partition loaded from the given data file.ExclusiveDataProvider(String fileName, ExclusiveDataProvider.Parser<T> parser) Creates a newExclusiveDataProviderinstance and initializes it with the agent's exclusive data partition loaded from the given data file.ExclusiveDataProvider(String fileName, String encoding, boolean filterLineComments, ExclusiveDataProvider.Parser<T> parser) Creates a newExclusiveDataProviderinstance and initializes it with the agent's exclusive data partition loaded from the given data file.ExclusiveDataProvider(String fileName, String encoding, ExclusiveDataProvider.Parser<T> parser) Creates a newExclusiveDataProviderinstance and initializes it with the agent's exclusive data partition loaded from the given data file. -
Method Summary
Modifier and TypeMethodDescriptionvoidAdd a new or release a previously received exclusive item.get()Allocate the next available item for exclusive use.static ExclusiveDataProvider.Parser<String> Default parser that just returns the lines it receives.static ExclusiveDataProvider<String> getInstance(String fileName) Returns the exclusive data provider responsible for the given file name.static ExclusiveDataProvider<String> getInstance(String fileName, boolean filterLineComments) Returns the exclusive data provider responsible for the given file name.static <T> ExclusiveDataProvider<T> getInstance(String fileName, boolean filterLineComments, ExclusiveDataProvider.Parser<T> parser) Returns the exclusive data provider responsible for the given file name.static <T> ExclusiveDataProvider<T> getInstance(String fileName, ExclusiveDataProvider.Parser<T> parser) Returns the exclusive data provider responsible for the given file name.static ExclusiveDataProvider<String> getInstance(String fileName, String encoding) Returns the exclusive data provider responsible for the given file name.static <T> ExclusiveDataProvider<T> getInstance(String fileName, String encoding, boolean filterLineComments, ExclusiveDataProvider.Parser<T> parser) Returns the exclusive data provider responsible for the given file name.static <T> ExclusiveDataProvider<T> getInstance(String fileName, String encoding, ExclusiveDataProvider.Parser<T> parser) Returns the exclusive data provider responsible for the given file name.static ExclusiveDataProvider<String> getNewInstance(String fileName) Creates a newExclusiveDataProviderinstance for String data and initializes it with the agent's exclusive data partition loaded from the given data file.static ExclusiveDataProvider<String> getNewInstance(String fileName, String encoding) Creates a newExclusiveDataProviderinstance for String data and initializes it with the agent's exclusive data partition loaded from the given data file.Allocate a random item for exclusive use.protected static <T> List<T> loadData(String fileName, String encoding, boolean filterLineComments, ExclusiveDataProvider.Parser<T> parser) Get the agent's exclusive data partition loaded from the given data file and parse this partition using the given parser.protected static <T> List<T> loadData(String fileName, String encoding, ExclusiveDataProvider.Parser<T> parser) Get the agent's exclusive data partition loaded from the given data file and parse this partition using the given parser.protected static <T> List<T> parse(List<String> lines, ExclusiveDataProvider.Parser<T> parser) Parse the given lines and return the resulting data objects.intsize()Get the number of available items.
-
Field Details
-
DEFAULT_PARSER
Parser that just returns the received lines.
-
-
Constructor Details
-
ExclusiveDataProvider
public ExclusiveDataProvider(String fileName, boolean filterLineComments, ExclusiveDataProvider.Parser<T> parser) throws FileNotFoundException, IOException Creates a newExclusiveDataProviderinstance and initializes it with the agent's exclusive data partition loaded from the given data file. The data file is expected to be saved usingDataProvider.DEFAULT_FILE_ENCODING.- Parameters:
fileName- the name/path of the data filefilterLineComments- whether line comments in given file should be automatically filtered out before content is handed over to given parserparser- parser to parse the content of the given file with- Throws:
FileNotFoundException- if the data file cannot be foundIOException- if the data file cannot be opened or read- See Also:
-
ExclusiveDataProvider
public ExclusiveDataProvider(String fileName, ExclusiveDataProvider.Parser<T> parser) throws FileNotFoundException, IOException Creates a newExclusiveDataProviderinstance and initializes it with the agent's exclusive data partition loaded from the given data file. The data file is expected to be saved usingDataProvider.DEFAULT_FILE_ENCODING.Line comments won't be automatically filtered out and need to be handled by the given parser.
- Parameters:
fileName- the name/path of the data fileparser- parser to parse the content of given file with- Throws:
FileNotFoundException- if the data file cannot be foundIOException- if the data file cannot be opened or read- See Also:
-
ExclusiveDataProvider
public ExclusiveDataProvider(String fileName, String encoding, ExclusiveDataProvider.Parser<T> parser) throws FileNotFoundException, IOException Creates a newExclusiveDataProviderinstance and initializes it with the agent's exclusive data partition loaded from the given data file.Line comments won't be automatically filtered out and need to be handled by the given parser.
- Parameters:
fileName- the name/path of the data fileencoding- the file's encodingparser- parser to parse the content of given file with- Throws:
FileNotFoundException- if the data file cannot be foundIOException- if the data file cannot be opened or read- See Also:
-
ExclusiveDataProvider
public ExclusiveDataProvider(String fileName, String encoding, boolean filterLineComments, ExclusiveDataProvider.Parser<T> parser) throws FileNotFoundException, IOException Creates a newExclusiveDataProviderinstance and initializes it with the agent's exclusive data partition loaded from the given data file.- Parameters:
fileName- the name/path of the data fileencoding- the file's encodingfilterLineComments- whether line comments in given file should be automatically filtered out before content is handed over to given parserparser- parser to parse the content of the given file with- Throws:
FileNotFoundException- if the data file cannot be foundIOException- if the data file cannot be opened or read- See Also:
-
-
Method Details
-
getNewInstance
public static ExclusiveDataProvider<String> getNewInstance(String fileName) throws FileNotFoundException, IOException Creates a newExclusiveDataProviderinstance for String data and initializes it with the agent's exclusive data partition loaded from the given data file. The data file is expected to be saved usingDataProvider.DEFAULT_FILE_ENCODING.Line comments won't be handled in any way.
- Parameters:
fileName- the name/path of the data file- Throws:
FileNotFoundException- if the data file cannot be foundIOException- if the data file cannot be opened or read
-
getNewInstance
public static ExclusiveDataProvider<String> getNewInstance(String fileName, String encoding) throws FileNotFoundException, IOException Creates a newExclusiveDataProviderinstance for String data and initializes it with the agent's exclusive data partition loaded from the given data file. The data file is expected to be saved usingDataProvider.DEFAULT_FILE_ENCODING.Line comments won't be handled in any way.
- Parameters:
fileName- the name/path of the data fileencoding- the encoding the file was saved with- Throws:
FileNotFoundException- if the data file cannot be foundIOException- if the data file cannot be opened or read
-
loadData
protected static <T> List<T> loadData(String fileName, String encoding, boolean filterLineComments, ExclusiveDataProvider.Parser<T> parser) throws FileNotFoundException, IOException Get the agent's exclusive data partition loaded from the given data file and parse this partition using the given parser.- Parameters:
fileName- the name/path of the data fileencoding- the file's encodingfilterLineComments- whether line comments in given file should be automatically filtered out before content is handed over to given parserparser- parser to parse the content of the given file with- Throws:
FileNotFoundException- if the data file cannot be foundIOException- if the data file cannot be opened or read- See Also:
-
loadData
protected static <T> List<T> loadData(String fileName, String encoding, ExclusiveDataProvider.Parser<T> parser) throws FileNotFoundException, IOException Get the agent's exclusive data partition loaded from the given data file and parse this partition using the given parser.Line comments won't be automatically filtered out and need to be handled by the given parser.
- Parameters:
fileName- the name/path of the data fileencoding- the file's encodingparser- parser to parse the content of the given file with- Throws:
FileNotFoundException- if the data file cannot be foundIOException- if the data file cannot be opened or read- See Also:
-
parse
Parse the given lines and return the resulting data objects.- Parameters:
lines- the lines to parseparser- parser to convert the read lines to the desired object
-
getInstance
public static ExclusiveDataProvider<String> getInstance(String fileName) throws FileNotFoundException, IOException Returns the exclusive data provider responsible for the given file name. If an exclusive data provider has not been requested yet for this file name, then a new exclusive data provider is created, otherwise the previously created provider will be returned. Note that the exclusive data providers will be initialized usingDataProvider.DEFAULT_FILE_ENCODINGand the default parser (getDefaultParser()).Use this method to ensure, that only a single exclusive data provider instance is created.
Line comments won't be handled in any way.
- Parameters:
fileName- the file name/path of the data file- Returns:
- the exclusive data provider
- Throws:
FileNotFoundException- if the data file cannot be foundIOException- if the data file cannot be opened or read
-
getInstance
public static ExclusiveDataProvider<String> getInstance(String fileName, boolean filterLineComments) throws FileNotFoundException, IOException Returns the exclusive data provider responsible for the given file name. If an exclusive data provider has not been requested yet for this file name, then a new exclusive data provider is created, otherwise the previously created provider will be returned. Note that the exclusive data providers will be initialized using the default parsergetDefaultParser().Use this method to ensure, that only a single exclusive data provider instance is created.
- Parameters:
fileName- the file name/path of the data filefilterLineComments- whether line comments in given file should be automatically filtered out before content is handed over to given parser- Returns:
- the exclusive data provider
- Throws:
FileNotFoundException- if the data file cannot be foundIOException- if the data file cannot be opened or read
-
getInstance
public static ExclusiveDataProvider<String> getInstance(String fileName, String encoding) throws FileNotFoundException, IOException Returns the exclusive data provider responsible for the given file name. If an exclusive data provider has not been requested yet for this file name, then a new exclusive data provider is created, otherwise the previously created provider will be returned. Note that the exclusive data providers will be initialized using the default parsergetDefaultParser().Use this method to ensure, that only a single exclusive data provider instance is created.
Line comments won't be handled in any way.
- Parameters:
fileName- the file name/path of the data fileencoding- file encoding- Returns:
- the exclusive data provider
- Throws:
FileNotFoundException- if the data file cannot be foundIOException- if the data file cannot be opened or read
-
getInstance
public static <T> ExclusiveDataProvider<T> getInstance(String fileName, String encoding, ExclusiveDataProvider.Parser<T> parser) throws FileNotFoundException, IOException Returns the exclusive data provider responsible for the given file name. If an exclusive data provider has not been requested yet for this file name, then a new exclusive data provider is created, otherwise the previously created provider will be returned.Use this method to ensure, that only a single exclusive data provider instance is created.
Line comments won't be automatically filtered out and need to be handled by the given parser.
- Parameters:
fileName- the file name/path of the data fileencoding- file encodingparser- parser to parse the lines with- Returns:
- the exclusive data provider
- Throws:
FileNotFoundException- if the data file cannot be foundIOException- if the data file cannot be opened or read- See Also:
-
getInstance
public static <T> ExclusiveDataProvider<T> getInstance(String fileName, boolean filterLineComments, ExclusiveDataProvider.Parser<T> parser) throws FileNotFoundException, IOException Returns the exclusive data provider responsible for the given file name. If an exclusive data provider has not been requested yet for this file name, then a new exclusive data provider is created, otherwise the previously created provider will be returned. Note that the exclusive data providers will be initialized usingDataProvider.DEFAULT_FILE_ENCODING.Use this method to ensure, that only a single exclusive data provider instance is created.
- Parameters:
fileName- the file name/path of the data filefilterLineComments- whether line comments in given file should be automatically filtered out before content is handed over to given parserparser- parser to parse the lines with- Returns:
- the exclusive data provider
- Throws:
FileNotFoundException- if the data file cannot be foundIOException- if the data file cannot be opened or read- See Also:
-
getInstance
public static <T> ExclusiveDataProvider<T> getInstance(String fileName, ExclusiveDataProvider.Parser<T> parser) throws FileNotFoundException, IOException Returns the exclusive data provider responsible for the given file name. If an exclusive data provider has not been requested yet for this file name, then a new exclusive data provider is created, otherwise the previously created provider will be returned. Note that the exclusive data providers will be initialized usingDataProvider.DEFAULT_FILE_ENCODING.Use this method to ensure, that only a single exclusive data provider instance is created.
Line comments won't be automatically filtered out and need to be handled by the given parser.
- Parameters:
fileName- the file name/path of the data fileparser- parser to parse the lines with- Returns:
- the exclusive data provider
- Throws:
FileNotFoundException- if the data file cannot be foundIOException- if the data file cannot be opened or read- See Also:
-
getInstance
public static <T> ExclusiveDataProvider<T> getInstance(String fileName, String encoding, boolean filterLineComments, ExclusiveDataProvider.Parser<T> parser) throws FileNotFoundException, IOException Returns the exclusive data provider responsible for the given file name. If an exclusive data provider has not been requested yet for this file name, then a new exclusive data provider is created, otherwise the previously created provider will be returned.Use this method to ensure, that only a single exclusive data provider instance is created.
- Parameters:
fileName- the file name/path of the data fileencoding- file encodingfilterLineComments- whether line comments in given file should be automatically filtered out before content is handed over to given parserparser- parser to parse the lines with- Returns:
- the exclusive data provider
- Throws:
FileNotFoundException- if the data file cannot be foundIOException- if the data file cannot be opened or read- See Also:
-
get
Allocate the next available item for exclusive use.- Returns:
- the first item or
nullif no item is available
-
getRandom
Allocate a random item for exclusive use.- Returns:
- a random item or
nullif no item is available
-
add
Add a new or release a previously received exclusive item.- Parameters:
item- the item to add
-
size
public int size()Get the number of available items.- Returns:
- number of available items
-
getDefaultParser
Default parser that just returns the lines it receives.- Returns:
- list of lines
-