Record Class JourneySummary

java.lang.Object
java.lang.Record
dev.hloth.zgztransport.JourneySummary
Record Components:
previous - the journey before the current one, absent on the first ever journey
lastPaidAt - when the last paid journey happened, which a free transfer leaves pointing at the ride it belongs to
consecutivePayments - the same counter as byte 4 of the current transaction
productId - byte 7, the product that paid for the journey, the same code Transaction.productId() carries
free - whether the current journey was a free transfer
route - the route of the current journey
direction - the direction of the current journey
paidMarker - byte 13, 0x63 after a paid journey and 0x62 after 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().
  • Constructor Details

  • 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

      public static JourneySummary decode(byte[] block)
      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.
      Specified by:
      encode in interface Encodable
      Returns:
      the sixteen bytes
    • 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.
    • previous

      public Optional<JourneySummary.Leg> previous()
      Returns the value of the previous record component.
      Returns:
      the value of the previous record component
    • lastPaidAt

      public JourneySummary.LastPaid lastPaidAt()
      Returns the value of the lastPaidAt record component.
      Returns:
      the value of the lastPaidAt record component
    • consecutivePayments

      public int consecutivePayments()
      Returns the value of the consecutivePayments record component.
      Returns:
      the value of the consecutivePayments record component
    • productId

      public int productId()
      Returns the value of the productId record component.
      Returns:
      the value of the productId record component
    • free

      public boolean free()
      Returns the value of the free record component.
      Returns:
      the value of the free record component
    • route

      public Route route()
      Returns the value of the route record component.
      Returns:
      the value of the route record component
    • direction

      public Direction direction()
      Returns the value of the direction record component.
      Returns:
      the value of the direction record component
    • paidMarker

      public int paidMarker()
      Returns the value of the paidMarker record component.
      Returns:
      the value of the paidMarker record component