edu.uci.ics.inf111.dvdvendor.devices
Class Printer

java.lang.Object
  extended by edu.uci.ics.inf111.dvdvendor.devices.Printer

public class Printer
extends java.lang.Object

This class represents the printer of the system. The output of this printer could be the console or a file.


Field Summary
(package private)  int lineLength
          Contains the maximum length of the printer.
private  Persistence persistence
          Persistence object that will help to persist the information in the Printer.
(package private)  java.lang.String targetFile
          Contains the path of the output file for the printer.
 
Constructor Summary
Printer()
          This constructor creates a printer whose output will be shown in the console screen.
Printer(java.lang.String pTargetFile)
          This constructor creates a printer whose output will be shown in a file.
 
Method Summary
private  boolean checkLength(java.lang.String line)
          Checks that the length of a String does not exceed lineLength.
 int getLineLength()
          Return the value of lineLength
 void print(java.util.ArrayList<java.lang.String> dataToPrint)
          Prints the arrayList of Strings passed as parameter on the screen or file, depending on the constructor used to create the printer object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

persistence

private Persistence persistence
Persistence object that will help to persist the information in the Printer.


lineLength

int lineLength
Contains the maximum length of the printer.


targetFile

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

Constructor Detail

Printer

public Printer()
This constructor creates a printer whose output will be shown in the console screen. It also initializes the variables targetFile.


Printer

public Printer(java.lang.String pTargetFile)
        throws PrinterException,
               PersistenceException
This constructor creates a printer whose output will be shown in a file.

Parameters:
pTargetFile - A String containing the path of the output file. It is recommended to use a relative path (ie "ptr/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:
PrinterException
PersistenceException
Method Detail

print

public void print(java.util.ArrayList<java.lang.String> dataToPrint)
           throws PrinterException,
                  PersistenceException
Prints the arrayList of Strings passed as parameter on the screen or file, depending on the constructor used to create the printer object. The print function will check that the arrayList is not null and that the elements in the arrayList are not null. Also it will check if each String in the arrayList does not exceed the maximum of characters per line, defined by lineLenght. If the String exceeds, the method will only print the first lineLength characters. While printing, 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 printing the data to the file using the Persistence object a Exception is thrown. When the Persistence object is used the maximum of characters per line is not checked.

Parameters:
dataToPrint - ArrayList of Strings that contains the list of Strings that will be printed
Throws:
PrinterException
PersistenceException

getLineLength

public int getLineLength()
Return the value of lineLength

Returns:
lineLength

checkLength

private boolean checkLength(java.lang.String line)
Checks that the length of a String does not exceed lineLength.

Parameters:
line -
Returns:
true if the string length is greater than lineLength; false otherwise.