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 transactionproductId- byte 7, the product that paid for the journey, the same codeTransaction.productId()carriesfree- whether the current journey was a free transferroute- the route of the current journeydirection- the direction of the current journeypaidMarker- byte 13,0x63after a paid journey and0x62after a free transfer on the known card types; other values are unexplained, so it is kept as the card wrote it
- All Implemented Interfaces:
Encodable
public record JourneySummary(Optional<JourneySummary.Leg> previous, JourneySummary.LastPaid lastPaidAt, int consecutivePayments, int productId, boolean free, Route route, Direction direction, int paidMarker)
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 does not maintain the block at all, 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, int productId, boolean free, Route route, Direction direction, int paidMarker) Checks the ranges of the numeric fields and that the others are present. -
Method Summary
Modifier and TypeMethodDescriptionintReturns 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.intReturns the value of thepaidMarkerrecord component.static byte[]The block 10 stamp of one personal card, its only non-zero byte[07]a product id.previous()Returns the value of thepreviousrecord component.intReturns the value of theproductIdrecord component.route()Returns the value of therouterecord component.final StringtoString()Returns a string representation of this record class.
-
Constructor Details
-
JourneySummary
public JourneySummary(Optional<JourneySummary.Leg> previous, JourneySummary.LastPaid lastPaidAt, int consecutivePayments, int productId, boolean free, Route route, Direction direction, int paidMarker) 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 block 10 stamp of one personal card, its only non-zero byte[07]a product id. Another personal card keeps block 10 all zero, so neither value can be relied on.decode(byte[])rejects it.- 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
-
productId
public int productId()Returns the value of theproductIdrecord component.- Returns:
- the value of the
productIdrecord 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
-
paidMarker
public int paidMarker()Returns the value of thepaidMarkerrecord component.- Returns:
- the value of the
paidMarkerrecord component
-