Advertisement
Georgi_Benchev

Untitled

Oct 17th, 2024
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.51 KB | None | 0 0
  1. package BoardR;
  2.  
  3. import java.time.LocalDate;
  4. import java.util.ArrayList;
  5. import java.util.List;
  6.  
  7. public class BoardItem {
  8.     private String title;
  9.     private LocalDate dueDate;
  10.     private Status status;
  11.     private List<EventLog> history;
  12.  
  13.     public BoardItem(String title, LocalDate dueDate) {
  14.         this.title = title;
  15.         this.dueDate = dueDate;
  16.         this.status = Status.Open;
  17.         history = new ArrayList<>();
  18.         history.add(new EventLog("Item created: " + viewInfo()));
  19.     }
  20.  
  21.     public void advanceStatus() {
  22.         if (status.equals(Status.Open)) {
  23.             status = Status.Todo;
  24.             history.add(new EventLog("Status changed from Open to ToDo"));
  25.         } else if (status == Status.Todo) {
  26.             status = Status.InProgress;
  27.             history.add(new EventLog("Status changed from ToDo to In Progress"));
  28.         } else if (status == Status.InProgress) {
  29.             status = Status.Done;
  30.             history.add(new EventLog("Status changed from In Progress to " + this.status));
  31.         } else if (status.equals(Status.Done)) {
  32.             status = Status.Verified;
  33.             history.add(new EventLog("Status changed from Done to " + this.status));
  34.         } else {
  35.             history.add(new EventLog("Can't advance, already at Verified"));
  36.  
  37.         }
  38.  
  39.  
  40.     }
  41.  
  42.     public void revertStatus() {
  43.         if (status.equals(Status.Verified)) {
  44.             status = Status.Done;
  45.             history.add(new EventLog("Status changed from Verified to " + this.status));
  46.         } else if (status.equals(Status.Done)) {
  47.             status = Status.InProgress;
  48.             history.add(new EventLog("Status changed from Done to In Progress"));
  49.         } else if (status == Status.InProgress) {
  50.             status = Status.Todo;
  51.             history.add(new EventLog("Status changed from In Progress to ToDo"));
  52.         } else if (status.equals(Status.Todo)) {
  53.             status = Status.Open;
  54.             history.add(new EventLog("Status changed from ToDo to " + this.status));
  55.         } else {
  56.             history.add(new EventLog("Can't revert, already at Open"));
  57.         }
  58.     }
  59.  
  60.     public String viewInfo() {
  61.         String output = String.format("'%s', [%s | %s]", title, status, dueDate);
  62.  
  63.         return output;
  64.  
  65.     }
  66.  
  67.     public String getTitle() {
  68.         return title;
  69.     }
  70.  
  71.     public void setTitle(String title) {
  72.         if (title.length() >= 5 && title.length() <= 30) {
  73.  
  74.             history.add(new EventLog("Title changed from " + this.title + " to " + title));
  75.             this.title = title;
  76.         } else {
  77.             throw new IllegalArgumentException("Please provide a title with length between 5 and 30 chars");
  78.         }
  79.     }
  80.  
  81.     public LocalDate getDueDate() {
  82.         return dueDate;
  83.     }
  84.  
  85.     public void setDueDate(LocalDate dueDate) {
  86.         if (dueDate.isAfter(this.dueDate)) {
  87.             history.add(new EventLog("DueDate changed from " + this.dueDate + " to " + dueDate));
  88.             this.dueDate = dueDate;
  89.         } else {
  90.             throw new IllegalArgumentException("Date must be in the present");
  91.         }
  92.     }
  93.  
  94.     public Status getStatus() {
  95.         return status;
  96.     }
  97.  
  98.     public void setStatus(Status status) {
  99.         history.add(new EventLog("Status changed from " + this.status + " to " + status));
  100.  
  101.         this.status = status;
  102.     }
  103.  
  104.     public void displayHistory() {
  105.         for (EventLog log : history) {
  106.             System.out.println(log.viewInfo());
  107.         }
  108.  
  109.     }
  110.  
  111. }
  112.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement