Enum Class CardType

java.lang.Object
java.lang.Enum<CardType>
dev.hloth.zgztransport.CardType
All Implemented Interfaces:
Encodable, Serializable, Comparable<CardType>, Constable

public enum CardType extends Enum<CardType> implements Encodable
The products these cards come as, which bytes 0 to 2 of block 1 tell apart.
  • Enum Constant Details

    • AVANZA_TOP_UP

      public static final CardType AVANZA_TOP_UP
      A balance top up Avanza Tarjeta Bus, which pays each journey out of its balance.
    • AVANZA_PERSONAL

      public static final CardType AVANZA_PERSONAL
      A personal Avanza Tarjeta Bus, which travels on a subscription and never spends.
    • AVANZA_PERSONAL_ABONO

      public static final CardType AVANZA_PERSONAL_ABONO
      A personal Avanza Tarjeta Bus printed "Abono de transporte". What separates it from AVANZA_PERSONAL is unknown; both behave the same here.
    • LAZO_TOP_UP_371F

      public static final CardType LAZO_TOP_UP_371F
      A balance top up Lazo card.
    • LAZO_TOP_UP_375F

      public static final CardType LAZO_TOP_UP_375F
      A balance top up Lazo card. What separates it from LAZO_TOP_UP_371F is unknown: a card carrying it holds the same keys, the same balance blocks, the same transaction ring and the same empty product sectors, and rewrites block 10 on every journey, with bytes 10 and 13 of it unidentified.
  • Method Details

    • values

      public static CardType[] values()
      Returns an array containing the constants of this enum class, in the order they are declared.
      Returns:
      an array containing the constants of this enum class, in the order they are declared
    • valueOf

      public static CardType valueOf(String name)
      Returns the enum constant of this class with the specified name. The string must match exactly an identifier used to declare an enum constant in this class. (Extraneous whitespace characters are not permitted.)
      Parameters:
      name - the name of the enum constant to be returned.
      Returns:
      the enum constant with the specified name
      Throws:
      IllegalArgumentException - if this enum class has no constant with the specified name
      NullPointerException - if the argument is null
    • value

      public int value()
      Bytes 0 to 2 of block 1.
      Returns:
      the three bytes as one integer
    • chip

      public Chip chip()
      The chip this product comes on.
      Returns:
      the chip
    • productSectors

      public List<Integer> productSectors()
      The sectors holding a subscription product on cards of this product, one product per sector.
      Returns:
      the sectors, empty on a product that pays each journey out of its balance
    • recordsJourneySummary

      public boolean recordsJourneySummary()
      Whether cards of this product rewrite block 10 on every journey. A product that travels on a subscription does not maintain it, see JourneySummary.personalBlock().
      Returns:
      true when block 10 holds a journey summary
    • isPersonal

      public boolean isPersonal()
      Whether cards of this product travel on a subscription rather than a balance.
      Returns:
      true on a personal product
    • ofValue

      public static CardType ofValue(int value)
      The product with those three bytes.
      Parameters:
      value - bytes 0 to 2 of block 1 as one integer
      Returns:
      the product
      Throws:
      CardFormatException - if no known product has those bytes
    • decode

      public static CardType decode(byte[] block)
      Decodes block 1, which says which product a card is.
      Parameters:
      block - the sixteen bytes
      Returns:
      the product
      Throws:
      CardFormatException - if the block is not sixteen bytes, its checksum does not match, bytes 3 to 14 are not zero, or no known product has those first three bytes
    • encode

      public byte[] encode()
      Encodes this product into block 1, with its checksum.
      Specified by:
      encode in interface Encodable
      Returns:
      the sixteen bytes
    • keys

      public Optional<SectorKeys> keys(int sector)
      The keys of one sector of a card of this product, read from the table it carries.

      Sectors 0 to 8 hold the same keys on every Avanza product, so any of them opens an Avanza card before block 1 has been read.

      Parameters:
      sector - the sector, counting from zero
      Returns:
      the keys, or empty for a sector the table does not cover, which is every sector past the last one Chip.sectors() counts
      Throws:
      IllegalArgumentException - if the sector is negative