GanttUtils.javaPaket: org.projectforge.business.gantt
Klassen: GanttUtils
Methoden (7): compare, getCalculatedStartDate, getCalculatedStartDate, getPredecessorRelDate, getCalculatedEndDate, getCalculatedEndDate, calculateDate
Felder (1): GANTT_OBJECT_COMPARATOR
Importe: 12 Pakete
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()));
}
};
/**
* Bitte beachten: Wenn das Startdatum nach dem Startdatum der frühesten Aufgabe eines beliebigen Kindes liegt,
* wird das Startdatum dieses Kindes zurückgegeben. Andernfalls wird das gesetzte Startdatum oder,
* falls nicht gesetzt, das berechnete Startdatum zurückgegeben.
*
* @param knoten
*/
public static LocalDate getCalculatedStartDate(final GanttTask knoten) {
final LocalDate start = getCalculatedStartDate(knoten, new HashSet<>(), new HashSet<>());
return start;
}
private static LocalDate getCalculatedStartDate(final GanttTask knoten, final Set<Serializable> startDateSet, final Set<Serializable> endDateSet) {
if (knoten == null) {
return null;
}
if (knoten.getStartDate() != null) {
return knoten.getStartDate();
}
if (knoten.isStartDateCalculated()) {
return knoten.getCalculatedStartDate();
}
final int durationDays = knoten.getDuration() != null ? knoten.getDuration().setScale(0, RoundingMode.HALF_UP).intValue() : 0;
if (knoten.getDuration() != null && knoten.getEndDate() != null) {
final LocalDate startDate = calculateDate(knoten.getEndDate(), -durationDays);
knoten.setCalculatedStartDate(startDate).setStartDateCalculated(true);
if (log.isDebugEnabled()) {
log.debug("Berechnetes Startdatum=" + startDate + " für: " + knoten);
}
return startDate;
}
if (startDateSet.contains(knoten.getId())) {
log.error("Zyklische Referenz erkannt (Startdatum konnte nicht berechnet werden: " + knoten);
return null;
} else {
startDateSet.add(knoten.getId());
}
LocalDate startDate = null;
final GanttTask vorgaenger = knoten.getPredecessor();
if (vorgaenger != null) {
startDate = getPredecessorRelDate(knoten.getRelationType(), vorgaenger, startDateSet, endDateSet);
if (startDate != null) {
if (NumberHelper.isNotZero(knoten.getPredecessorOffset())) {
startDate = calculateDate(startDate, knoten.getPredecessorOffset());
}
if (knoten.getRelationType() == GanttRelationType.START_FINISH || knoten.getRelationType() == GanttRelationType.FINISH_FINISH) {
if (durationDays > 0) {
startDate = calculateDate(startDate, -durationDays);
}
}
}
}
if ((vorgaenger == null || (knoten.getRelationType() != null && knoten.getRelationType().isIn(GanttRelationType.FINISH_FINISH,
GanttRelationType.START_FINISH)))
&& knoten.getChildren() != null) {
// Startdatum aus dem frühesten Kind berechnen.
for (final GanttTask kind : knoten.getChildren()) {
final LocalDate date = getCalculatedStartDate(kind, startDateSet, endDateSet);
if (startDate == null) {
startDate = date;
// ... (gekürzt, insgesamt 236 Zeilen)
868d6abb7 2025 -> 2026 63081666f Quellcode-Dateiköpfe: 2024 -> 2025. b6092df09 Copyright 2023 -> 2024 ab45d51fa Copyright 2001-2022 -> 2001-2023. 5f7ef41b8 Copyright 2021 -> 2022