The FileReader class is a part of the package org.noahspoling.Models
and is an implementation of the IFileReader interface. The main purpose of this class is to read from text files, generate templates from them, and create files from those templates.
readFromTxt(String filename)
: Reads from a text file and generates templates from the lines in the file.generateTemplate(String[] entries)
: Generates a template based on the entries provided.createFiles(List<Template> templates)
: Creates files from the provided list of templates.outputFromTemplate(Template template, String filetype)
: Creates a file of the specified filetype from the provided template.replaceText(String replaceText, List<String> entries)
: Replaces placeholders in the text with the provided entries.
The TemplateA class extends the Template class and is also a part of the org.noahspoling.Models
package. This class serves as a concrete implementation of the abstract Template class. It has additional attributes specific to the "TemplateA" type, including name
, item
, replacedItem
, and priceDifference
.
getEntries()
: Returns a list of all the entries in the template, which includes the values of all the fields of this class.
The TemplateB class extends the Template class and is a part of the org.noahspoling.Models
package. This class serves as a concrete implementation of the abstract Template class. It has additional attributes specific to the "TemplateB" type, including name
, item
, date
, reward
, and numOfWinners
.
getEntries()
: Returns a list of all the entries in the template, which includes the values of all the fields of this class.
- Instantiate a new TemplateB with the necessary parameters.
- Use
getEntries
to get a list of all the entries in the template.
- Instantiate a new FileReader with a text file name or a list of templates.
- Use
readFromTxt
to read the contents of a text file. - Use
createFiles
to create files from the templates.
- Instantiate a new TemplateA with the necessary parameters.
- Use
getEntries
to get a list of all the entries in the template.
Please note that you'll need to adjust paths and inputs to fit your specific use case. It's also worth noting that this project includes exception handling to ensure that errors are dealt with appropriately.
- Instantiate a new TemplateA with the necessary parameters.
- Use
getEntries
to get a list of all the entries in the template.
Note: The FileReader's constructor will automatically call readFromTxt
to read the contents of the text file and generate templates. These templates will be stored in the templates
list which is a member of the FileReader class.
This template child extends the abstract Template class and specializes it to the "TemplateA" type. Its attributes include name
, item
, replacedItem
, and priceDifference
. It also overrides the getEntries
method from the parent class to return a list of the values of its fields. This list can then be used to fill in placeholders in a document.