Record Class Card

java.lang.Object
java.lang.Record
dev.hloth.zgztransport.Card
Record Components:
uid - the UID of block 0
cardType - the product of block 1
id - the printed id of block 2
balance - the balance of blocks 8 and 9, always zero on a personal card
transactions - the last six transactions, oldest first
journeySummary - block 10, absent on a personal card and before the first journey
products - the subscription products, empty on a top up card

public record Card(Uid uid, CardType cardType, CardId id, Balance balance, List<Transaction> transactions, Optional<JourneySummary> journeySummary, List<Product> products) extends Record
Everything a dump of one card holds.
  • Field Details

    • LAST_USED_BLOCK

      public static final int LAST_USED_BLOCK
      The first block a dump must reach to hold everything this decodes.
      See Also:
  • Constructor Details

  • Method Details

    • decode

      public static Card decode(byte[] bytes)
      Decodes a dump of either card, as MIFARE Classic Tool or a Proxmark writes it. A dump that stops after block 33 is enough, and anything past it is ignored.
      Parameters:
      bytes - the blocks, one after another from block 0
      Returns:
      the card
      Throws:
      CardFormatException - if the bytes are not whole blocks or the card does not decode
    • decode

      public static Card decode(Dump dump)
      Decodes a dump of either card.
      Parameters:
      dump - the blocks, from block 0
      Returns:
      the card
      Throws:
      CardFormatException - if the dump stops before block 33, carries no known SAK, holds two different balance blocks, or any block it reads does not decode
    • 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. All components in this record class are compared with Objects::equals(Object,Object).
      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.
    • uid

      public Uid uid()
      Returns the value of the uid record component.
      Returns:
      the value of the uid record component
    • cardType

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

      public CardId id()
      Returns the value of the id record component.
      Returns:
      the value of the id record component
    • balance

      public Balance balance()
      Returns the value of the balance record component.
      Returns:
      the value of the balance record component
    • transactions

      public List<Transaction> transactions()
      Returns the value of the transactions record component.
      Returns:
      the value of the transactions record component
    • journeySummary

      public Optional<JourneySummary> journeySummary()
      Returns the value of the journeySummary record component.
      Returns:
      the value of the journeySummary record component
    • products

      public List<Product> products()
      Returns the value of the products record component.
      Returns:
      the value of the products record component