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 on a free transfer
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
runCounter - byte 9, on buses most likely the ordinal of the run the vehicle was on
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 runCounter, 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
    • isFreeTransfer

      public boolean isFreeTransfer()
      Whether this is a ride that cost nothing, which the operator grants within about half an hour of a paid one.
      Returns:
      true when this is a journey of amount zero
    • 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
    • runCounter

      public int runCounter()
      Returns the value of the runCounter record component.
      Returns:
      the value of the runCounter 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