java.lang.Object
java.lang.Record
dev.hloth.zgztransport.CardDate
- Record Components:
year-2000to2127month-1to12day-1to31
- All Implemented Interfaces:
Encodable,Comparable<CardDate>
public record CardDate(int year, int month, int day)
extends Record
implements Comparable<CardDate>, Encodable
A date as the card packs it into two bytes: 7 bits of year since 2000, 4 bits
of month and 5 bits of day.
The card does not check the calendar, so a day of 31 is accepted in any
month; this type accepts the same values instead of rejecting dumps that hold
them. Use toLocalDate() to reach a calendar date.
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionCardDate(int year, int month, int day) Checks the ranges of the three fields. -
Method Summary
Modifier and TypeMethodDescriptionintintday()Returns the value of thedayrecord component.static CardDatedecode(byte[] bytes) Decodes the two big-endian bytes of a packed date.byte[]encode()Encodes this date into two big-endian bytes.final booleanIndicates whether some other object is "equal to" this one.final inthashCode()Returns a hash code value for this object.intmonth()Returns the value of themonthrecord component.This date as a calendar date.toString()The date inYYYY-MM-DDform.intyear()Returns the value of theyearrecord component.
-
Field Details
-
BYTES
public static final int BYTESBytes a packed date takes.- See Also:
-
-
Constructor Details
-
CardDate
public CardDate(int year, int month, int day) Checks the ranges of the three fields.- Throws:
IllegalArgumentException- if a field is outside the range the bits allow
-
-
Method Details
-
decode
Decodes the two big-endian bytes of a packed date.- Parameters:
bytes- the two bytes- Returns:
- the date they hold
- Throws:
CardFormatException- if the input is not two bytes or holds a zero month or day
-
encode
public byte[] encode()Encodes this date into two big-endian bytes. -
toLocalDate
This date as a calendar date.- Returns:
- the calendar date, or empty when the card holds a day the month does not have
-
compareTo
- Specified by:
compareToin interfaceComparable<CardDate>
-
toString
The date inYYYY-MM-DDform. -
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. All components in this record class are compared with '=='. -
year
public int year()Returns the value of theyearrecord component.- Returns:
- the value of the
yearrecord component
-
month
public int month()Returns the value of themonthrecord component.- Returns:
- the value of the
monthrecord component
-
day
public int day()Returns the value of thedayrecord component.- Returns:
- the value of the
dayrecord component
-