|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.mycompany.expense.ReportRegistry
com.mycompany.expense.FileReportRegistry
This class is an implementation of the ReportRegistry for the sample expense report application that uses the file system for permanent storage. It's only intended as an example. For real usage of the sample application, an implementation that uses a database is a better choice.
Field Summary | |
private int |
currentReportId
|
private java.util.Map |
reports
|
Constructor Summary | |
FileReportRegistry()
Creates an instance and loads the current content, if any, from the file system by calling the load() method. |
Method Summary | |
void |
addReport(Report report)
Adds a copy of the report to the registry. |
private void |
checkExists(Report report)
Tries to locate a report with the ID of the provided report, and throws an IllegalStateException if there's no such report. |
Report |
getReport(int id)
Returns a copy of the report with the specified ID, or null if there's no matching report in the registry. |
java.util.List |
getReports(java.lang.String owner,
java.util.Date fromDate,
java.util.Date toDate,
int[] status)
Returns a List with copies of all reports matching the search criteria. |
private java.io.File |
getStore()
Returns a File instance for a file named ".expense/store.ser" in the home directory for the account running the JVM. |
private void |
load()
Loads the registry from the file returned by the getStore() method. |
private boolean |
matchesCriteria(Report report,
java.lang.String owner,
java.util.Date from,
java.util.Date to,
int[] status)
Returns true if the report matches the non-null parameter values. |
void |
removeReport(Report report)
Removes an existing report in the registry with ID of the provided report. |
private void |
save()
Saves the registry to the file returned by the getStore() method. |
void |
updateReport(Report report)
Replaces an existing report in the registry with a copy of the provided report. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
private int currentReportId
private java.util.Map reports
Constructor Detail |
public FileReportRegistry() throws RegistryException
Method Detail |
public void addReport(Report report) throws RegistryException
addReport
in class ReportRegistry
RegistryException
public void updateReport(Report report) throws RegistryException
updateReport
in class ReportRegistry
RegistryException
public void removeReport(Report report) throws RegistryException
removeReport
in class ReportRegistry
RegistryException
public Report getReport(int id)
getReport
in class ReportRegistry
public java.util.List getReports(java.lang.String owner, java.util.Date fromDate, java.util.Date toDate, int[] status)
getReports
in class ReportRegistry
private boolean matchesCriteria(Report report, java.lang.String owner, java.util.Date from, java.util.Date to, int[] status)
private void checkExists(Report report)
private void load() throws java.io.IOException
java.io.IOException
private void save() throws java.io.IOException
java.io.IOException
private java.io.File getStore()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |