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
cardType - the product of the card
free - whether the current journey was a free transfer
route - the route of the current journey
direction - the direction of the current journey
transfersLeft - 0x63 after a paid journey and 0x62 after 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().
  • Constructor Details

  • 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

      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
    • cardType

      public CardType cardType()
      Returns the value of the cardType record component.
      Returns:
      the value of the cardType 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
    • transfersLeft

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