Package edu.kit.datamanager.takita.model
Record Class PartialDate
java.lang.Object
java.lang.Record
edu.kit.datamanager.takita.model.PartialDate
- Record Components:
year- mandatory year as integermonth- optional month as integerday- 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 Summary
ConstructorsConstructorDescriptionPartialDate(int year, Integer month, Integer day) Creates an instance of aPartialDaterecord class. -
Method Summary
Modifier and TypeMethodDescriptionintCompares this object with the specified object for order.day()Returns the value of thedayrecord component.final booleanIndicates whether some other object is "equal to" this one.final inthashCode()Returns a hash code value for this object.month()Returns the value of themonthrecord component.static PartialDateParses a string into a partial date Expected string pattern: (-)YYYY-MM-DD with optional month and/or dayfinal StringtoString()Returns a string representation of this record class.intyear()Returns the value of theyearrecord component.
-
Constructor Details
-
Method Details
-
toFirstLocalDate
-
toLastLocalDate
-
parse
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
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 allxandy. (This implies thatx.compareTo(y)must throw an exception if and only ify.compareTo(x)throws an exception.)The implementor must also ensure that the relation is transitive:
(x.compareTo(y) > 0 && y.compareTo(z) > 0)impliesx.compareTo(z) > 0.Finally, the implementor must ensure that
x.compareTo(y)==0implies thatsignum(x.compareTo(z)) == signum(y.compareTo(z)), for allz.- Specified by:
compareToin interfaceComparable<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 nullClassCastException- if the specified object's type prevents it from being compared to this object.
-
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. -
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. -
equals
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 withObjects::equals(Object,Object); primitive components are compared with '=='. -
year
public int year()Returns the value of theyearrecord component.- Returns:
- the value of the
yearrecord component
-
month
Returns the value of themonthrecord component.- Returns:
- the value of the
monthrecord component
-
day
Returns the value of thedayrecord component.- Returns:
- the value of the
dayrecord component
-