Record Class PartialDate

java.lang.Object
java.lang.Record
edu.kit.datamanager.takita.model.PartialDate
Record Components:
year - mandatory year as integer
month - optional month as integer
day - optional day as integer
All Implemented Interfaces:
Comparable<PartialDate>

public record PartialDate(int year, Integer month, Integer day) extends Record implements Comparable<PartialDate>
Date class that acts as a stand in for LocalDate but allows incomplete dates Allowed incomplete: Year, Year+Month Disallowed incomplete: Year+day, month+day, day This is therefore not accepting the full range of date attributes provided by TEI This behaviour allows for comparing /sorting dates, while some incomplete dates are incomparable to others (month + day cannot be compared to years)
  • Constructor Details

    • PartialDate

      public PartialDate(int year, Integer month, Integer day)
      Creates an instance of a PartialDate record class.
      Parameters:
      year - the value for the year record component
      month - the value for the month record component
      day - the value for the day record component
  • Method Details

    • toFirstLocalDate

      public LocalDate toFirstLocalDate()
    • toLastLocalDate

      public LocalDate toLastLocalDate()
    • parse

      public static PartialDate parse(String s)
      Parses a string into a partial date Expected string pattern: (-)YYYY-MM-DD with optional month and/or day
      Parameters:
      s - date string
      Returns:
      parsed date
    • compareTo

      public int compareTo(PartialDate o)
      Compares this object with the specified object for order. Returns a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.

      The implementor must ensure signum(x.compareTo(y)) == -signum(y.compareTo(x)) for all x and y. (This implies that x.compareTo(y) must throw an exception if and only if y.compareTo(x) throws an exception.)

      The implementor must also ensure that the relation is transitive: (x.compareTo(y) > 0 && y.compareTo(z) > 0) implies x.compareTo(z) > 0.

      Finally, the implementor must ensure that x.compareTo(y)==0 implies that signum(x.compareTo(z)) == signum(y.compareTo(z)), for all z.

      Specified by:
      compareTo in interface Comparable<PartialDate>
      Parameters:
      o - the object to be compared.
      Returns:
      a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.
      Throws:
      NullPointerException - if the specified object is null
      ClassCastException - if the specified object's type prevents it from being compared to this object.
    • 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.
    • year

      public int year()
      Returns the value of the year record component.
      Returns:
      the value of the year record component
    • month

      public Integer month()
      Returns the value of the month record component.
      Returns:
      the value of the month record component
    • day

      public Integer day()
      Returns the value of the day record component.
      Returns:
      the value of the day record component