GanttUtils.javaPaquetage : org.projectforge.business.gantt
Classes : GanttUtils
Méthodes (7) : compare, getCalculatedStartDate, getCalculatedStartDate, getPredecessorRelDate, getCalculatedEndDate, getCalculatedEndDate, calculateDate
Champs (1) : GANTT_OBJECT_COMPARATOR
Importations : 12 paquetages
package org.projectforge.business.gantt;
import org.apache.commons.lang3.StringUtils;
import org.projectforge.common.StringHelper;
import org.projectforge.framework.time.PFDay;
import org.projectforge.framework.time.PFDayUtils;
import org.projectforge.framework.utils.NumberHelper;
import java.io.Serializable;
import java.math.RoundingMode;
import java.time.LocalDate;
import java.util.Comparator;
import java.util.HashSet;
import java.util.Objects;
import java.util.Set;
public class GanttUtils {
private static final org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(GanttUtils.class);
public static Comparator<GanttTask> GANTT_OBJECT_COMPARATOR = new Comparator<GanttTask>() {
@Override
public int compare(final GanttTask o1, final GanttTask o2) {
if (Objects.equals(o1.getId(), o2.getId())) {
return 0;
}
final LocalDate start1 = o1.getCalculatedStartDate();
final LocalDate start2 = o2.getCalculatedStartDate();
if (start1 == null) {
if (start2 != null) {
return 1;
}
} else if (start2 == null) {
return -1;
} else {
final int result = start1.compareTo(start2);
if (result != 0) {
return result;
}
}
final LocalDate end1 = o1.getCalculatedEndDate();
final LocalDate end2 = o2.getCalculatedEndDate();
if (end1 == null) {
if (end2 != null) {
return 1;
}
} else if (end2 == null) {
return -1;
} else {
final int result = end1.compareTo(end2);
if (result != 0) {
return result;
}
}
if (!StringUtils.equals(o1.getTitle(), o2.getTitle())) {
return StringHelper.compareTo(o1.getTitle(), o2.getTitle());
}
return StringHelper.compareTo(String.valueOf(o1.getId()), String.valueOf(o2.getId()));
}
};
/**
* Veuillez noter : si la date de début est postérieure à la date de début de la tâche la plus précoce d’un enfant,
* alors la date de début de cet enfant est renvoyée. Sinon, la date de début définie ou, si elle n’est pas définie,
* la date de début calculée est renvoyée.
*
* @param node
*/
public static LocalDate getCalculatedStartDate(final GanttTask node) {
final LocalDate start = getCalculatedStartDate(node, new HashSet<>(), new HashSet<>());
return start;
}
private static LocalDate getCalculatedStartDate(final GanttTask node, final Set<Serializable> startDateSet, final Set<Serializable> endDateSet) {
if (node == null) {
return null;
}
if (node.getStartDate() != null) {
return node.getStartDate();
}
if (node.isStartDateCalculated()) {
return node.getCalculatedStartDate();
}
final int durationDays = node.getDuration() != null ? node.getDuration().setScale(0, RoundingMode.HALF_UP).intValue() : 0;
if (node.getDuration() != null && node.getEndDate() != null) {
final LocalDate startDate = calculateDate(node.getEndDate(), -durationDays);
node.setCalculatedStartDate(startDate).setStartDateCalculated(true);
if (log.isDebugEnabled()) {
log.debug("date de début calculée =" + startDate + " pour : " + node);
}
return startDate;
}
if (startDateSet.contains(node.getId())) {
log.error("Détection de référence circulaire (impossible de calculer la date de début : " + node);
return null;
} else {
startDateSet.add(node.getId());
}
LocalDate startDate = null;
final GanttTask predecessor = node.getPredecessor();
if (predecessor != null) {
startDate = getPredecessorRelDate(node.getRelationType(), predecessor, startDateSet, endDateSet);
if (startDate != null) {
if (NumberHelper.isNotZero(node.getPredecessorOffset())) {
startDate = calculateDate(startDate, node.getPredecessorOffset());
}
if (node.getRelationType() == GanttRelationType.START_FINISH || node.getRelationType() == GanttRelationType.FINISH_FINISH) {
if (durationDays > 0) {
startDate = calculateDate(startDate, -durationDays);
}
}
}
}
if ((predecessor == null || (node.getRelationType() != null && node.getRelationType().isIn(GanttRelationType.FINISH_FINISH,
GanttRelationType.START_FINISH)))
&& node.getChildren() != null) {
// Calcule la date de début à partir de l’enfant le plus précoce.
for (final GanttTask child : node.getChildren()) {
final LocalDate date = getCalculatedStartDate(child, startDateSet, endDateSet);
if (startDate == null) {
startDate = date;
// ... (tronqué, total 236 lignes)
868d6abb7 2025 -> 2026 63081666f En-têtes des fichiers source : 2024 -> 2025. b6092df09 Copyright 2023 -> 2024 ab45d51fa Copyright 2001-2022 -> 2001-2023. 5f7ef41b8 Copyright 2021 -> 2022