Class PiecewiseConstantSpecificDays

java.lang.Object
net.sourceforge.plantuml.project.ngm.math.AbstractPiecewiseConstant
net.sourceforge.plantuml.project.ngm.math.PiecewiseConstantSpecificDays
All Implemented Interfaces:
PiecewiseConstant

public final class PiecewiseConstantSpecificDays extends AbstractPiecewiseConstant
Immutable implementation of PiecewiseConstant that models a workload pattern defined by specific dates.

Each specific LocalDate value is associated with a constant Fraction representing the workload for that day (for example 3/10 for 30%). A zero value is meaningful and represents no allocation on that day.

For any date not explicitly mapped, a default value is returned.

  • Method Details

    • of

      public static PiecewiseConstantSpecificDays of(Fraction value)
      Creates a PiecewiseConstantSpecificDays with the given default value.
      Parameters:
      value - The default workload fraction.
      Returns:
      A new PiecewiseConstantSpecificDays instance.
    • of

      public static PiecewiseConstantSpecificDays of(Fraction defaultValue, Map<LocalDate,Fraction> dayToFraction)
      Creates a PiecewiseConstantSpecificDays with the given default value and a pre-built day-to-fraction mapping.

      This factory method avoids the O(N²) cost of chaining N calls to withDay(LocalDate, Fraction), each of which copies the internal map. Instead, the caller builds the map once and passes it in.

      Parameters:
      defaultValue - The default workload fraction.
      dayToFraction - Mapping of specific dates to their workload fractions.
      Returns:
      A new PiecewiseConstantSpecificDays instance.
    • withDay

      public PiecewiseConstantSpecificDays withDay(LocalDate day, Fraction value)
      Returns a new PiecewiseConstantSpecificDays with the specified day associated with the given fraction.
      Parameters:
      day - The specific date to associate.
      value - The workload fraction for the specified date.
      Returns:
      A new PiecewiseConstantSpecificDays instance with the updated mapping.
    • segmentAt

      public Segment segmentAt(LocalDateTime instant, TimeDirection direction)