Record Class Transaction

java.lang.Object
java.lang.Record
dev.hloth.zgztransport.Transaction
Record Components:
productId - byte 0, the product that paid for the journey: the subscription product id on a personal card, the first byte of the CardType on a top up card
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; a top up can carry 0x21 instead
All Implemented Interfaces:
Encodable

public record Transaction(int productId, 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 Summary

    Constructors
    Constructor
    Description
    Transaction(int productId, int networkFlag, int amount, int consecutivePayments, Stop stop, Route route, TransactionKind kind, int dutyTrip, CardDateTime createdAt, int sequence)
    Checks the ranges of the numeric fields and that the others are present.
  • Method Summary

    Modifier and Type
    Method
    Description
    int
    Returns the value of the amount record component.
    A builder, which spares the caller a constructor of ten arguments.
    int
    Returns the value of the consecutivePayments record component.
    Returns the value of the createdAt record component.
    decode(byte[] block)
    Decodes one record of the log.
    The direction of this transaction when it is a journey.
    int
    Returns the value of the dutyTrip record component.
    byte[]
    Encodes this transaction into one record of the log.
    final boolean
    Indicates whether some other object is "equal to" this one.
    final int
    Returns a hash code value for this object.
    boolean
    Whether this is a check-out at a gated station, which carries no payment counter.
    boolean
    Whether this is a ride that cost nothing.
    boolean
    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 the value of the kind record component.
    int
    Returns the value of the networkFlag record component.
    int
    Returns the value of the productId record component.
    Returns the value of the route record component.
    int
    Returns the value of the sequence record component.
    Returns the value of the stop record component.
    final String
    Returns a string representation of this record class.

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • Transaction

      public Transaction(int productId, int networkFlag, int amount, int consecutivePayments, Stop stop, Route route, TransactionKind kind, int dutyTrip, CardDateTime createdAt, int sequence)
      Checks the ranges of the numeric fields and that the others are present.
      Throws:
      IllegalArgumentException - if a field is outside the range its byte allows
      NullPointerException - if a field is null
  • 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, 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 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.

      The network flag tells the two kinds of card apart: zero on every balance record seen, non-zero on every personal one.

      Returns:
      true when this is a free journey carrying a payment counter, made by a card that pays from its balance
    • 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.
    • productId

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