Record Class ContractScheduleData

java.lang.Object
java.lang.Record
mekhq.campaign.mission.contract.contractData.ContractScheduleData
Record Components:
startDate - the day the contract begins, or null when not yet settled
endDate - the day the contract ends, or null when open-ended
lengthInMonths - the contract's length in months

public record ContractScheduleData(@Nullable LocalDate startDate, @Nullable LocalDate endDate, int lengthInMonths) extends Record
When a contract runs.

Either endpoint may be absent: a contract can be held without a settled schedule, and a save need not carry both dates. isActiveOn(LocalDate) treats a missing endpoint as unbounded on that side, matching the convention used when sorting missions - an active contract with no start date is treated as starting today.

  • Constructor Details

    • ContractScheduleData

      public ContractScheduleData(@Nullable LocalDate startDate, @Nullable LocalDate endDate, int lengthInMonths)
      Creates an instance of a ContractScheduleData record class.
      Parameters:
      startDate - the value for the startDate record component
      endDate - the value for the endDate record component
      lengthInMonths - the value for the lengthInMonths record component
  • Method Details

    • withStartDate

      public ContractScheduleData withStartDate(LocalDate startDate)
      Returns a copy with startDate replaced.

      lengthInMonths is recomputed from the resulting dates, so it always describes the span the contract actually runs for rather than a separately agreed figure. Moving only the start date therefore shortens or lengthens the contract; a caller that means to shift the whole contract unchanged must move both endpoints (as chaining withStartDate(...).withEndDate(...) does, where the final recomputed length comes back identical). The length is left untouched when either resulting date is absent, since there is no span to measure.

      Parameters:
      startDate - the replacement start date
      Returns:
      a copy of this schedule with startDate replaced and the length recomputed
    • withEndDate

      public ContractScheduleData withEndDate(LocalDate endDate)
      Returns a copy with endDate replaced. As with withStartDate(LocalDate), the length is recomputed from the resulting dates - pushing the end date back is what lengthens (or an extension shortens) the contract.
      Parameters:
      endDate - the replacement end date
      Returns:
      a copy of this schedule with endDate replaced and the length recomputed
    • isActiveOn

      public boolean isActiveOn(LocalDate date)
      Parameters:
      date - the day to test
      Returns:
      whether the contract runs on date, inclusive of both endpoints. An absent start date counts as already begun and an absent end date as not yet over, so a contract with neither is active on any day.
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. Reference components are compared with Objects::equals(Object,Object); primitive components are compared with '=='.
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • startDate

      @Nullable public LocalDate startDate()
      Returns the value of the startDate record component.
      Returns:
      the value of the startDate record component
    • endDate

      @Nullable public LocalDate endDate()
      Returns the value of the endDate record component.
      Returns:
      the value of the endDate record component
    • lengthInMonths

      public int lengthInMonths()
      Returns the value of the lengthInMonths record component.
      Returns:
      the value of the lengthInMonths record component