edu.uci.ics.inf111.dvdvendor.lib
Class Persistence

java.lang.Object
  extended by edu.uci.ics.inf111.dvdvendor.lib.Persistence

public class Persistence
extends java.lang.Object

The Persistence class represents the interface to physically store information in a persistent way. In this case, the persistence is done in a file in the file system.


Field Summary
(package private)  java.lang.String targetFile
          Contains the path of the output file.
 
Constructor Summary
Persistence(java.lang.String pTargetFile)
          This constructor creates a persistance whose output will be shown in a file.
 
Method Summary
 java.util.ArrayList<java.lang.String> read()
          Reads the targetFile line by line and keep all the lines read in an ArrayList of Strings.
 void write(java.util.ArrayList<java.lang.String> dataToPrint)
          Writes in the targetFile the arrayList of Strings passed as parameter.
 void write(java.lang.String dataToPrint)
          Writes in the targetFile the String passed as parameter.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

targetFile

java.lang.String targetFile
Contains the path of the output file.

Constructor Detail

Persistence

public Persistence(java.lang.String pTargetFile)
            throws PersistenceException
This constructor creates a persistance whose output will be shown in a file. This method also checks that the targetFile path exists. In the case that targetFile path does not exist, a PersistenceException is thrown.

Parameters:
pTargetFile - A String containing the path of the output file. It is recommended to use a relative path (ie "prt/PrinterOutput.txt") due to the fact that this will work with both PC and MAC. If you create it using a relative path, the file will be stored in the location of your project (Right click on the project, Properties, see Location).
Throws:
PersistenceException
Method Detail

write

public void write(java.util.ArrayList<java.lang.String> dataToPrint)
           throws PersistenceException
Writes in the targetFile the arrayList of Strings passed as parameter. The write function will check that the arrayList is not null and that the elements in the arrayList are not null. While writing, this method will add a new line character at the end of each String in the arrayList. In the case there would be any problem writing the data to the file, a PersistenceException is thrown.

Parameters:
dataToPrint - ArrayList of Strings that contains the list of Strings that will be stored in the targetFile
Throws:
PersistenceException

write

public void write(java.lang.String dataToPrint)
           throws PersistenceException
Writes in the targetFile the String passed as parameter. This method calls internally the write method that receives a ArrayList as a parameter.

Parameters:
dataToPrint - String that contains the info to be stored in the targetFile
Throws:
PersistenceException

read

public java.util.ArrayList<java.lang.String> read()
                                           throws PersistenceException
Reads the targetFile line by line and keep all the lines read in an ArrayList of Strings.

Throws:
PersistenceException