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_UNLIMITED

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

      public static final CardType LAZO_TOP_UP
      A balance top up Lazo card.
  • 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
    • firstByte

      public int firstByte()
      The first byte of the product, which transactions and the journey summary carry.
      Returns:
      byte 0 of block 1
    • 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 leaves a constant there instead, which JourneySummary.decode(byte[]) rejects.
      Returns:
      true when block 10 holds a journey summary
    • 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
    • ofFirstByte

      public static CardType ofFirstByte(int firstByte)
      The product whose first byte is the one given, as transactions carry it.
      Parameters:
      firstByte - byte 0 of a transaction or of the journey summary
      Returns:
      the product
      Throws:
      CardFormatException - if no known product starts with that byte
    • 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 both Avanza products, so either 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