Task.java

package hhn.temp.project;

import hhn.temp.project.expections.TaskHasNoWorkerException;

public class Task {

  private String name;
  private String description;
  private TaskStatus taskStatus;
  private int taskID;
  private static int idCounter = 0;
  private String workername;

  public Task(String name, String description) {


    this.name = name;
    this.description = description;
    this.taskStatus = TaskStatus.OPEN;
    //TODO when DB then auto IDs
    this.taskID = idCounter++;
  }

  public int getTaskID() {
    return this.taskID;
  }

  public String getName() {
    return this.name;
  }

  public String getDescription() {
    return description;
  }

  public TaskStatus getStatus() {
    return taskStatus;
  }

  public void setDescription(String description) {
    if (description == null ) {

      throw new IllegalArgumentException("Description is null!");
    }

    this.description = description;
  }

  public void setStatus(TaskStatus taskStatus) {
    if (taskStatus == null ) {

      throw new IllegalArgumentException("TaskStatus is null!");
    }

    this.taskStatus = taskStatus;
  }

  public void setWorker(String workerName) {
    if(workerName == null || workerName.isEmpty()) {
      throw new IllegalArgumentException("There is nothing in this variable.");
    }
    if(!checkOnlyLetter(workerName)){
      throw new IllegalArgumentException("Only Lettery as Worker Name!");
    }
    this.workername = workerName;
    this.setStatus(TaskStatus.INPROCESS);
  }

  public String getWorker() {
    if(this.workername == null) {
      throw new TaskHasNoWorkerException("Please set first a Worker");
    }
    return this.workername;
  }

  private boolean checkOnlyLetter(String text) {
    boolean result = true;

    for(int i = 0; i < text.length(); i++) {
      char c = text.charAt(i);
      if(!Character.isLetter(c)) {
        result = false;
        break;
      }
    }
    return result;
  }
}