Skip to content

Commit

Permalink
Tidy up isSuccessor isPredecessor implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
joniles committed Nov 6, 2024
1 parent 6e0c2f8 commit 7469eee
Showing 1 changed file with 14 additions and 23 deletions.
37 changes: 14 additions & 23 deletions src/main/java/net/sf/mpxj/Task.java
Original file line number Diff line number Diff line change
Expand Up @@ -5604,7 +5604,7 @@ private void set(FieldType field, boolean value)
*/
public boolean isPredecessor(Task task)
{
return isRelated(task, getPredecessors());
return task != null && getPredecessors().stream().anyMatch(p -> p.getPredecessorTask().getUniqueID().intValue() == task.getUniqueID().intValue());
}

/**
Expand All @@ -5613,42 +5613,33 @@ public boolean isPredecessor(Task task)
*
* @param task potential successor task
* @return Boolean flag
* @deprecated use isSuccessor
*/
public boolean isSucessor(Task task)
@Deprecated public boolean isSucessor(Task task)
{
return isRelated(task, getSuccessors());
return task != null && task.isPredecessor(this);
}

/**
* Used to determine if a task has child tasks.
* Utility method used to determine if the supplied task
* is a successor of the current task.
*
* @return true if the task has child tasks
* @param task potential successor task
* @return Boolean flag
*/
public boolean hasChildTasks()
public boolean isSuccessor(Task task)
{
return !m_children.isEmpty();
return task != null && task.isPredecessor(this);
}

/**
* Internal method used to test for the existence of a relationship
* with a task.
* Used to determine if a task has child tasks.
*
* @param task target task
* @param list list of relationships
* @return boolean flag
* @return true if the task has child tasks
*/
private boolean isRelated(Task task, List<Relation> list)
public boolean hasChildTasks()
{
boolean result = false;
for (Relation relation : list)
{
if (relation.getPredecessorTask().getUniqueID().intValue() == task.getUniqueID().intValue())
{
result = true;
break;
}
}
return result;
return !m_children.isEmpty();
}

private Integer calculateParentTaskUniqueID()
Expand Down

0 comments on commit 7469eee

Please sign in to comment.