001package edu.pdx.cs410J.grader.poa;
002
003import java.time.LocalDateTime;
004
005public class POASubmission {
006
007  private final String subject;
008  private final String submitter;
009  private final LocalDateTime submitTime;
010  private final String content;
011  private final String contentType;
012
013  private POASubmission(String subject, String submitter, LocalDateTime submitTime, String content, String contentType) {
014    this.subject = subject;
015    this.submitter = submitter;
016    this.submitTime = submitTime;
017    this.content = content;
018    this.contentType = contentType;
019  }
020
021  public static Builder builder() {
022    return new Builder();
023  }
024
025  public String getSubject() {
026    return subject;
027  }
028
029  public String getSubmitter() {
030    return submitter;
031  }
032
033  public LocalDateTime getSubmitTime() {
034    return submitTime;
035  }
036
037  @Override
038  public String toString() {
039    return String.format("POA from %s with subject %s on %s with %d characters of content",
040      getSubmitter(), getSubject(), getSubmitTime(), getContentLength());
041  }
042
043  private int getContentLength() {
044    String content = getContent();
045    if (content == null) {
046      return 0;
047
048    } else {
049      return content.length();
050    }
051  }
052
053  public String getContent() {
054    return content;
055  }
056
057  public String getContentType() {
058    return contentType;
059  }
060
061  public static class Builder {
062    private String subject;
063    private String submitter;
064    private LocalDateTime submitTime;
065    private String content;
066    private String contentType;
067
068    public POASubmission create() {
069      assertNotNull("subject", subject);
070      assertNotNull("submitter", submitter);
071      assertNotNull("submitTime", submitTime);
072      assertNotNull("content", content);
073      assertNotNull("contentType", contentType);
074
075      return new POASubmission(subject, submitter, submitTime, content, contentType);
076    }
077
078    private void assertNotNull(String description, Object object) {
079      if (object == null) {
080        throw new IllegalStateException(description + " cannot be null");
081      }
082    }
083
084    public Builder setSubject(String subject) {
085      this.subject = subject;
086      return this;
087    }
088
089    public Builder setSubmitter(String submitter) {
090      this.submitter = submitter;
091      return this;
092    }
093
094    public Builder setSubmitTime(LocalDateTime submitTime) {
095      this.submitTime = submitTime;
096      return this;
097    }
098
099    public Builder setContent(String content) {
100      this.content = content;
101      return this;
102    }
103
104    public Builder setContentType(String contentType) {
105      this.contentType = contentType;
106      return this;
107    }
108  }
109}