Package pacman.util

Class ScoreBoardWriter


  • public class ScoreBoardWriter
    extends java.lang.Object

    ScoreBoardWriter

    A ScoreBoardWriter is an object of utility to write a Score to a score board file.

    Usage:

        ScoreBoardWriter scoreBoardWriter = new ScoreBoardWriter(fileName);
        scoreBoardWriter.write(score);
     
    Since:
    1.0
    Version:
    1.0
    Author:
    Song Zhang
    See Also:
    ScoreBoardReader, ScoreBoard, Score
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.lang.String path
      The path of the score board file.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      private static java.lang.String convertToByteString​(Score object)
      Converts a a Score object to a byte string and returns it.
      private void init()
      Initializes the file if it doesn't exist.
      void write​(Score score)
      Writes the given Score to the score board file.
      private void writeNewLine​(java.lang.String line)
      Writes a new line to the file.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • path

        private java.lang.String path
        The path of the score board file.
    • Constructor Detail

      • ScoreBoardWriter

        public ScoreBoardWriter​(java.lang.String fileName)
        Allocates a new ScoreBoardWriter.
        Parameters:
        fileName - the file name of the score board file to be written
    • Method Detail

      • convertToByteString

        private static java.lang.String convertToByteString​(Score object)
                                                     throws java.lang.Exception
        Converts a a Score object to a byte string and returns it.
        Parameters:
        object - a Score to be written in to the file
        Returns:
        a Score object converted from the given byte string
        Throws:
        java.lang.Exception - if anything goes wrong with reading object
      • writeNewLine

        private void writeNewLine​(java.lang.String line)
        Writes a new line to the file.
        Parameters:
        line - a string line to be written.
      • init

        private void init()
        Initializes the file if it doesn't exist.
      • write

        public void write​(Score score)
        Writes the given Score to the score board file.
        Parameters:
        score - a Score to be written to the file.