From 7469eee0ea8f5f6e403d331621dd59a131d47b80 Mon Sep 17 00:00:00 2001 From: joniles Date: Wed, 6 Nov 2024 15:13:32 +0000 Subject: [PATCH] Tidy up isSuccessor isPredecessor implementation --- src/main/java/net/sf/mpxj/Task.java | 37 +++++++++++------------------ 1 file changed, 14 insertions(+), 23 deletions(-) diff --git a/src/main/java/net/sf/mpxj/Task.java b/src/main/java/net/sf/mpxj/Task.java index b6b5254dff..4a44c28310 100644 --- a/src/main/java/net/sf/mpxj/Task.java +++ b/src/main/java/net/sf/mpxj/Task.java @@ -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()); } /** @@ -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 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()