java.lang.Object
java.lang.Record
dev.hloth.zgztransport.JourneySummary
- Record Components:
previous- the journey before the current one, absent on the first ever journeylastPaidAt- when the last paid journey happened, which a free transfer leaves pointing at the ride it belongs toconsecutivePayments- the same counter as byte 4 of the current transactioncardType- the product of the cardfree- whether the current journey was a free transferroute- the route of the current journeydirection- the direction of the current journeytransfersLeft-0x63after a paid journey and0x62after a free transfer
- All Implemented Interfaces:
Encodable
public record JourneySummary(Optional<JourneySummary.Leg> previous, JourneySummary.LastPaid lastPaidAt, int consecutivePayments, CardType cardType, boolean free, Route route, Direction direction, int transfersLeft)
extends Record
implements Encodable
Block 10 of a top up card, which the card rewrites on every journey and
leaves alone on a top up. A card that has only ever been topped up holds all
zeroes here, and a personal card holds a constant that
decode(byte[]) rejects, see personalBlock().-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordWhen the last paid journey happened, which the card records to the minute.static final recordA route and the direction travelled along it. -
Constructor Summary
ConstructorsConstructorDescriptionJourneySummary(Optional<JourneySummary.Leg> previous, JourneySummary.LastPaid lastPaidAt, int consecutivePayments, CardType cardType, boolean free, Route route, Direction direction, int transfersLeft) Checks the ranges of the numeric fields and that the others are present. -
Method Summary
Modifier and TypeMethodDescriptioncardType()Returns the value of thecardTyperecord component.intReturns the value of theconsecutivePaymentsrecord component.static JourneySummarydecode(byte[] block) Decodes block 10 of a top up card.Returns the value of thedirectionrecord component.byte[]encode()Encodes this summary into block 10, with its checksum.final booleanIndicates whether some other object is "equal to" this one.booleanfree()Returns the value of thefreerecord component.final inthashCode()Returns a hash code value for this object.Returns the value of thelastPaidAtrecord component.static byte[]The constant block 10 that personal cards hold, which stands for no journey at all.previous()Returns the value of thepreviousrecord component.route()Returns the value of therouterecord component.final StringtoString()Returns a string representation of this record class.intReturns the value of thetransfersLeftrecord component.
-
Constructor Details
-
JourneySummary
public JourneySummary(Optional<JourneySummary.Leg> previous, JourneySummary.LastPaid lastPaidAt, int consecutivePayments, CardType cardType, boolean free, Route route, Direction direction, int transfersLeft) Checks the ranges of the numeric fields and that the others are present.- Throws:
IllegalArgumentException- if a field is outside the range its byte allowsNullPointerException- if a field is null
-
-
Method Details
-
personalBlock
public static byte[] personalBlock()The constant block 10 that personal cards hold, which stands for no journey at all.- Returns:
- the sixteen bytes
-
decode
Decodes block 10 of a top up card.- Parameters:
block- the sixteen bytes- Returns:
- the summary
- Throws:
CardFormatException- if the block is not sixteen bytes, its checksum does not match, the bytes the card keeps at zero are set, or a field is outside its range
-
encode
public byte[] encode()Encodes this summary into block 10, with its checksum. -
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 '=='. -
previous
Returns the value of thepreviousrecord component.- Returns:
- the value of the
previousrecord component
-
lastPaidAt
Returns the value of thelastPaidAtrecord component.- Returns:
- the value of the
lastPaidAtrecord component
-
consecutivePayments
public int consecutivePayments()Returns the value of theconsecutivePaymentsrecord component.- Returns:
- the value of the
consecutivePaymentsrecord component
-
cardType
Returns the value of thecardTyperecord component.- Returns:
- the value of the
cardTyperecord component
-
free
public boolean free()Returns the value of thefreerecord component.- Returns:
- the value of the
freerecord component
-
route
Returns the value of therouterecord component.- Returns:
- the value of the
routerecord component
-
direction
Returns the value of thedirectionrecord component.- Returns:
- the value of the
directionrecord component
-
transfersLeft
public int transfersLeft()Returns the value of thetransfersLeftrecord component.- Returns:
- the value of the
transfersLeftrecord component
-