Record Class Transaction

java.lang.Object
java.lang.Record
dev.hloth.zgztransport.Transaction
Record Components:
cardType - the product of the card that made it
networkFlag - byte 1, 0 on top up cards and 1 or 2 on personal ones
amount - the money moved, in Balance.UNITS_PER_EURO units, 0 when the journey cost nothing
consecutivePayments - payments of this card at one terminal in a row, counting from 1, or 0 on a top up
stop - where it happened
route - the route, or Route 0 on a top up made off board
kind - whether it was a journey or a top up
dutyTrip - byte 9, on buses most likely which trip of the vehicle daily duty this is, counting from 1
createdAt - when the card wrote the record
sequence - 0 to 4, which picks the archive block the record moves to
All Implemented Interfaces:
Encodable

public record Transaction(CardType cardType, int networkFlag, int amount, int consecutivePayments, Stop stop, Route route, TransactionKind kind, int dutyTrip, CardDateTime createdAt, int sequence) extends Record implements Encodable
One record of the transaction log: a journey or a top up, with where and when it happened.
  • Constructor Details

  • Method Details

    • decode

      public static Transaction decode(byte[] block)
      Decodes one record of the log.
      Parameters:
      block - the sixteen bytes
      Returns:
      the transaction
      Throws:
      CardFormatException - if the block is not sixteen bytes, no known product starts with byte 0, the timestamp is out of range, or byte 8 is neither a direction nor a top up
    • encode

      public byte[] encode()
      Encodes this transaction into one record of the log.
      Specified by:
      encode in interface Encodable
      Returns:
      the sixteen bytes
    • builder

      public static TransactionBuilder builder()
      A builder, which spares the caller a constructor of ten arguments.
      Returns:
      an empty builder
    • isFree

      public boolean isFree()
      Whether this is a ride that cost nothing. Every journey on a personal unlimited card is free.
      Returns:
      true when this is a journey of amount zero
    • isTransfer

      public boolean isTransfer()
      Whether this is the free transfer a balance card earns after a paid ride, which the operator grants once per ride, to another route, within 60 minutes on the urban network and 75 when a CTAZ card enters Zaragoza.
      Returns:
      true when this is a free journey carrying a payment counter
    • isCheckOut

      public boolean isCheckOut()
      Whether this is a check-out at a gated station, which carries no payment counter. Rests on the single Cercanias check-out in the dumps, so treat it as provisional.
      Returns:
      true when this is a free journey without a payment counter
    • direction

      public Optional<Direction> direction()
      The direction of this transaction when it is a journey.
      Returns:
      the direction, or empty on a top up
    • 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.
    • cardType

      public CardType cardType()
      Returns the value of the cardType record component.
      Returns:
      the value of the cardType record component
    • networkFlag

      public int networkFlag()
      Returns the value of the networkFlag record component.
      Returns:
      the value of the networkFlag record component
    • amount

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

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

      public Stop stop()
      Returns the value of the stop record component.
      Returns:
      the value of the stop record component
    • route

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

      public TransactionKind kind()
      Returns the value of the kind record component.
      Returns:
      the value of the kind record component
    • dutyTrip

      public int dutyTrip()
      Returns the value of the dutyTrip record component.
      Returns:
      the value of the dutyTrip record component
    • createdAt

      public CardDateTime createdAt()
      Returns the value of the createdAt record component.
      Returns:
      the value of the createdAt record component
    • sequence

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