001package edu.pdx.cs.joy.apptbook;
002
003import edu.pdx.cs.joy.AppointmentBookParser;
004import edu.pdx.cs.joy.ParserException;
005
006import java.io.BufferedReader;
007import java.io.IOException;
008import java.io.Reader;
009
010/**
011 * A skeletal implementation of the <code>TextParser</code> class for Project 2.
012 */
013public class TextParser implements AppointmentBookParser<AppointmentBook> {
014  private final Reader reader;
015
016  public TextParser(Reader reader) {
017    this.reader = reader;
018  }
019
020  @Override
021  public AppointmentBook parse() throws ParserException {
022    try (
023      BufferedReader br = new BufferedReader(this.reader)
024    ) {
025
026      String owner = br.readLine();
027
028      if (owner == null) {
029        throw new ParserException("Missing owner");
030      }
031
032      return new AppointmentBook(owner);
033
034    } catch (IOException e) {
035      throw new ParserException("While parsing appointment book text", e);
036    }
037  }
038}