Package com.evanv.taskapp.logic
Class Task
- java.lang.Object
-
- com.evanv.taskapp.logic.Task
-
- All Implemented Interfaces:
java.lang.Comparable<Task>
public class Task extends java.lang.Object implements java.lang.Comparable<Task>
Represents a single task. Conceptually a Task is a node on a large task dependency graph that spans the entire list of tasks. Tasks that aren't connected can be done in any order, tasks that are connected must be done in an order specified by the child/parent relationships -> children require their parents to complete before they can be started. Definitely overengineered, but this Task class is designed to make the Optimizer work.- Author:
- Evan Voogd
-
-
Field Summary
Fields Modifier and Type Field Description static org.threeten.bp.format.DateTimeFormatter
dateFormat
static java.lang.String
EXTRA_VAL_TASK
private java.util.ArrayList<Task>
mChildren
private org.threeten.bp.LocalDate
mDoDate
private org.threeten.bp.LocalDate
mDueDate
private org.threeten.bp.LocalDate
mEarlyDate
private long
mID
private java.util.ArrayList<java.lang.Long>
mLabelIDs
private java.util.List<Label>
mLabels
private java.lang.String
mName
private java.util.ArrayList<java.lang.Long>
mParentArr
private java.util.ArrayList<Task>
mParents
private int
mPriority
private Project
mProject
private long
mProjectID
private int
mTimeToComplete
private java.util.ArrayList<Task>
mWorkingChildren
private org.threeten.bp.LocalDate
mWorkingDoDate
private org.threeten.bp.LocalDate
mWorkingEarlyDate
private java.util.ArrayList<Task>
mWorkingParents
-
Constructor Summary
Constructors Constructor Description Task(java.lang.String name, org.threeten.bp.LocalDate early, org.threeten.bp.LocalDate due, int time, int priority)
Initializes an object representing a taskTask(java.lang.String name, org.threeten.bp.LocalDate earlyDate, org.threeten.bp.LocalDate dueDate, org.threeten.bp.LocalDate doDate, int timeToComplete, java.util.ArrayList<java.lang.Long> parentArr, int priority, long projectID, java.util.ArrayList<java.lang.Long> labelIDs)
Initializes an object representing a task
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addChild(Task child)
Add a task that depends on this taskvoid
addLabel(Label label)
Add a Label to this Task.void
addParent(Task parent)
Add a prerequisite task for this taskstatic java.util.Date
clearDate(java.util.Date toClear)
Clears time information from Date, as LocalDate wasn't implemented until API 26.int
compareTo(Task other)
Compares this task with another given taskjava.util.ArrayList<Task>
getChildren()
Returns the tasks dependent on the completion of the taskstatic int
getDiff(org.threeten.bp.LocalDate endDate, org.threeten.bp.LocalDate startDate)
Get the difference (in days) between two dates.static int
getDiff(org.threeten.bp.LocalDateTime endDate, org.threeten.bp.LocalDate startDate)
Get the difference (in days) between two dates.org.threeten.bp.LocalDate
getDoDate()
Returns the currently scheduled completion date (by the optimizer) for the taskorg.threeten.bp.LocalDate
getDueDate()
Returns the due date for the taskorg.threeten.bp.LocalDate
getEarlyDate()
Returns the earliest completion date for the tasklong
getID()
Returns the id of this task.java.util.ArrayList<java.lang.Long>
getLabelIDs()
Get a List of IDs of the current Labels.java.util.List<Label>
getLabels()
Get the labels that the Task is associated with.java.lang.String
getName()
Returns the name of the taskjava.util.ArrayList<java.lang.Long>
getParentArr()
Get list of parent idsjava.util.ArrayList<Task>
getParents()
Returns the prerequisite tasks for the taskint
getPriority()
Get the priority of the task.Project
getProject()
Get the project the Task is associated with.long
getProjectID()
Get the ID of the current Project.int
getTimeToComplete()
Returns the amount of time (in minutes) it takes to complete the taskjava.util.ArrayList<Task>
getWorkingChildren()
Returns the "working" children list.org.threeten.bp.LocalDate
getWorkingDoDate()
Get the working copy of the do date for the taskorg.threeten.bp.LocalDate
getWorkingEarlyDate()
Returns the working copy of the earliest completion date for the taskjava.util.ArrayList<Task>
getWorkingParents()
Returns the "working" parents list.void
initializeForOptimization()
Copies children into working children and parents into working parents, so the optimizer can utilize the inherent dependency tree.void
initializeLabels(java.util.List<Label> labels)
Synchronize the list of Label IDs with the List of Labels.void
initializeProject(java.util.List<Project> projects)
Update Project from Project ID as the DB cannot store references.void
removeChild(Task child)
Remove a task that depends on this taskvoid
removeLabel(Label label)
Remove a Label from this Task.void
removeParent(Task parent)
Remove a prerequisite task for this taskvoid
removeProject()
void
removeWorkingParent(Task parent)
Remove a prerequisite task for this task in the optimizer's working task dependency graphvoid
setDoDate(org.threeten.bp.LocalDate doDate)
Changes the currently scheduled completion date for the task.void
setDueDate(org.threeten.bp.LocalDate dueDate)
Changes the due date for the task.void
setEarlyDate(org.threeten.bp.LocalDate earlyDate)
Changes the earliest completion date for a task.void
setID(long id)
Sets the id of this task.void
setName(java.lang.String name)
Changes the name of the taskvoid
setPriority(int priority)
Update the priority of the task.void
setProject(Project project)
Change the Task's Project.void
setTimeToComplete(int timeToComplete)
Changes the amount of time it takes to complete the task.void
setWorkingDoDate(org.threeten.bp.LocalDate workingDoDate)
Change the working copy of the earliest completion date for the taskvoid
setWorkingEarlyDate(org.threeten.bp.LocalDate earlyDate)
Changes the working copy of the earliest completion date for a task.
-
-
-
Field Detail
-
mID
private long mID
-
mName
@NonNull private java.lang.String mName
-
mEarlyDate
@NonNull private org.threeten.bp.LocalDate mEarlyDate
-
mDoDate
private org.threeten.bp.LocalDate mDoDate
-
mDueDate
@NonNull private org.threeten.bp.LocalDate mDueDate
-
mTimeToComplete
private int mTimeToComplete
-
mPriority
private int mPriority
-
mProject
private Project mProject
-
mLabels
private final java.util.List<Label> mLabels
-
mProjectID
private long mProjectID
-
mLabelIDs
private final java.util.ArrayList<java.lang.Long> mLabelIDs
-
mParentArr
@NonNull private final java.util.ArrayList<java.lang.Long> mParentArr
-
mParents
private final java.util.ArrayList<Task> mParents
-
mChildren
private final java.util.ArrayList<Task> mChildren
-
mWorkingParents
private java.util.ArrayList<Task> mWorkingParents
-
mWorkingChildren
private java.util.ArrayList<Task> mWorkingChildren
-
mWorkingEarlyDate
private org.threeten.bp.LocalDate mWorkingEarlyDate
-
mWorkingDoDate
private org.threeten.bp.LocalDate mWorkingDoDate
-
dateFormat
public static final org.threeten.bp.format.DateTimeFormatter dateFormat
-
EXTRA_VAL_TASK
public static final java.lang.String EXTRA_VAL_TASK
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
Task
public Task(@NonNull java.lang.String name, @NonNull org.threeten.bp.LocalDate early, @NonNull org.threeten.bp.LocalDate due, int time, int priority)
Initializes an object representing a task- Parameters:
name
- The name of the taskearly
- The earliest possible day to complete the task (e.g. when it's assigned)due
- When the task is due
-
Task
public Task(@NonNull java.lang.String name, @NonNull org.threeten.bp.LocalDate earlyDate, @NonNull org.threeten.bp.LocalDate dueDate, org.threeten.bp.LocalDate doDate, int timeToComplete, @NonNull java.util.ArrayList<java.lang.Long> parentArr, int priority, long projectID, @NonNull java.util.ArrayList<java.lang.Long> labelIDs)
Initializes an object representing a task- Parameters:
name
- The name of the taskparentArr
- Array of id's for the prioritypriority
- Priority of the taskdoDate
- When the task is scheduled to be completed.dueDate
- When the task is due.earlyDate
- Earliest date the task can be completed.timeToComplete
- Amount of time in minutes the task is estimated to complete.projectID
- ID for the project.labelIDs
- List of IDs for the labels.
-
-
Method Detail
-
getID
public long getID()
Returns the id of this task.- Returns:
- id of the task
-
setID
public void setID(long id)
Sets the id of this task.- Parameters:
id
- id of the task
-
getName
public java.lang.String getName()
Returns the name of the task- Returns:
- The name of the task
-
setName
public void setName(@NonNull java.lang.String name)
Changes the name of the task- Parameters:
name
- THe new name of the task
-
getEarlyDate
public org.threeten.bp.LocalDate getEarlyDate()
Returns the earliest completion date for the task- Returns:
- The earliest completion date for the task
-
setEarlyDate
public void setEarlyDate(org.threeten.bp.LocalDate earlyDate)
Changes the earliest completion date for a task.- Parameters:
earlyDate
- The new earliest completion date for the task.
-
getDoDate
public org.threeten.bp.LocalDate getDoDate()
Returns the currently scheduled completion date (by the optimizer) for the task- Returns:
- The currently scheduled completion date (by the optimizer) for the task
-
setDoDate
public void setDoDate(org.threeten.bp.LocalDate doDate)
Changes the currently scheduled completion date for the task.- Parameters:
doDate
- The new completion date for the task.
-
getDueDate
public org.threeten.bp.LocalDate getDueDate()
Returns the due date for the task- Returns:
- The due date for the task
-
setDueDate
public void setDueDate(org.threeten.bp.LocalDate dueDate)
Changes the due date for the task.- Parameters:
dueDate
- The new due date for the task.
-
getTimeToComplete
public int getTimeToComplete()
Returns the amount of time (in minutes) it takes to complete the task- Returns:
- The amount of time (in minutes) it takes to complete the task
-
setTimeToComplete
public void setTimeToComplete(int timeToComplete)
Changes the amount of time it takes to complete the task.- Parameters:
timeToComplete
- The new amount of time it takes to complete the task.
-
getParents
public java.util.ArrayList<Task> getParents()
Returns the prerequisite tasks for the task- Returns:
- The prerequisite tasks for the task
-
addParent
public void addParent(Task parent)
Add a prerequisite task for this task- Parameters:
parent
- The task that whose completion is required for the completion of the task
-
removeParent
public void removeParent(Task parent)
Remove a prerequisite task for this task- Parameters:
parent
- The prerequisite task to remove
-
getChildren
public java.util.ArrayList<Task> getChildren()
Returns the tasks dependent on the completion of the task- Returns:
- The tasks dependent on the completion of the task
-
addChild
public void addChild(Task child)
Add a task that depends on this task- Parameters:
child
- The dependent task to add
-
removeChild
public void removeChild(Task child)
Remove a task that depends on this task- Parameters:
child
- The dependent task to remove
-
getParentArr
@NonNull public java.util.ArrayList<java.lang.Long> getParentArr()
Get list of parent ids- Returns:
- parent array
-
getWorkingDoDate
public org.threeten.bp.LocalDate getWorkingDoDate()
Get the working copy of the do date for the task- Returns:
- The working copy of the do date for the task
-
setWorkingDoDate
public void setWorkingDoDate(org.threeten.bp.LocalDate workingDoDate)
Change the working copy of the earliest completion date for the task- Parameters:
workingDoDate
- The new working copy of the earliest completion date for the task
-
getWorkingEarlyDate
public org.threeten.bp.LocalDate getWorkingEarlyDate()
Returns the working copy of the earliest completion date for the task- Returns:
- The working copy of the earliest completion date for the task
-
setWorkingEarlyDate
public void setWorkingEarlyDate(org.threeten.bp.LocalDate earlyDate)
Changes the working copy of the earliest completion date for a task.- Parameters:
earlyDate
- The new working copy of the earliest completion date for the task.
-
getWorkingParents
public java.util.ArrayList<Task> getWorkingParents()
Returns the "working" parents list. The working list exists so the optimizer can remove parents from children as they are completed, so checking if all prerequisite tasks are completed is as easy as getWorkingParents().size() == 0.- Returns:
- The working parents list.
-
removeWorkingParent
public void removeWorkingParent(Task parent)
Remove a prerequisite task for this task in the optimizer's working task dependency graph- Parameters:
parent
- The prerequisite task to remove
-
getWorkingChildren
public java.util.ArrayList<Task> getWorkingChildren()
Returns the "working" children list. Exists mostly for symmetry with workingParents.- Returns:
- The working children list.
-
initializeForOptimization
public void initializeForOptimization()
Copies children into working children and parents into working parents, so the optimizer can utilize the inherent dependency tree.
-
compareTo
public int compareTo(Task other)
Compares this task with another given task- Specified by:
compareTo
in interfacejava.lang.Comparable<Task>
- Parameters:
other
- The other task to compare it with- Returns:
- Returns a positive number if this task is greater, negative if the other task is greater, and 0 if they are equal
-
clearDate
public static java.util.Date clearDate(java.util.Date toClear)
Clears time information from Date, as LocalDate wasn't implemented until API 26. Very useful for Tasks as Tasks have no inherent time information.- Parameters:
toClear
- The date to return without a time- Returns:
- toClear but at the time 00:00:00.0000
-
setPriority
public void setPriority(int priority)
Update the priority of the task. 3 = highest priority, 0 = minimum priority- Parameters:
priority
- new priority
-
getPriority
public int getPriority()
Get the priority of the task. 3 = highest priority, 0 = minimum priority- Returns:
- priority number
-
getProject
public Project getProject()
Get the project the Task is associated with.- Returns:
- the Project for the task.
-
getLabels
public java.util.List<Label> getLabels()
Get the labels that the Task is associated with.- Returns:
- a List of Labels the task is associated with.
-
getProjectID
public long getProjectID()
Get the ID of the current Project.- Returns:
- the ID of the Project.
-
getLabelIDs
public java.util.ArrayList<java.lang.Long> getLabelIDs()
Get a List of IDs of the current Labels.- Returns:
- the ID of the Labels.
-
setProject
public void setProject(Project project)
Change the Task's Project.- Parameters:
project
- The new project for the task.
-
addLabel
public void addLabel(Label label)
Add a Label to this Task.- Parameters:
label
- The new label for the Task.
-
removeLabel
public void removeLabel(Label label)
Remove a Label from this Task.- Parameters:
label
- The label to remove from this Task.
-
initializeProject
public void initializeProject(java.util.List<Project> projects)
Update Project from Project ID as the DB cannot store references.- Parameters:
projects
- List of projects.
-
initializeLabels
public void initializeLabels(java.util.List<Label> labels)
Synchronize the list of Label IDs with the List of Labels.- Parameters:
labels
- List of labels.
-
getDiff
public static int getDiff(org.threeten.bp.LocalDate endDate, org.threeten.bp.LocalDate startDate)
Get the difference (in days) between two dates. Often used to find index into taskSchedule List, so is included as a static field here.- Parameters:
endDate
- The later date in the calculationstartDate
- The earlier date in the calculation- Returns:
- How many days between start and end dates. E.g. 8/21, 8/20 will return 1.
-
getDiff
public static int getDiff(org.threeten.bp.LocalDateTime endDate, org.threeten.bp.LocalDate startDate)
Get the difference (in days) between two dates. Often used to find index into taskSchedule List, so is included as a static field here.- Parameters:
endDate
- The later date in the calculationstartDate
- The earlier date in the calculation- Returns:
- How many days between start and end dates. E.g. 8/21, 8/20 will return 1.
-
removeProject
public void removeProject()
-
-