Record Class Balance

java.lang.Object
java.lang.Record
dev.hloth.zgztransport.Balance
Record Components:
units - the balance in UNITS_PER_EURO units
All Implemented Interfaces:
Encodable

public record Balance(long units) extends Record implements Encodable
The balance of blocks 8 and 9, in thousandths of a euro. Personal cards always hold zero.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final long
    Largest balance the value block holds.
    static final long
    Units in one euro.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Balance(long units)
    Checks the range of the balance.
  • Method Summary

    Modifier and Type
    Method
    Description
    static Balance
    decode(byte[] block)
    Decodes the value block of block 8 or 9, checking the complement and the copy the MIFARE value block format holds.
    byte[]
    Encodes this balance into the value block of blocks 8 and 9.
    final boolean
    Indicates whether some other object is "equal to" this one.
    The balance in euros, exact to the thousandth.
    final int
    Returns a hash code value for this object.
    The balance in euros with three decimals.
    long
    Returns the value of the units record component.

    Methods inherited from class java.lang.Object

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

    • UNITS_PER_EURO

      public static final long UNITS_PER_EURO
      Units in one euro.
      See Also:
    • MAX_UNITS

      public static final long MAX_UNITS
      Largest balance the value block holds. The terminals of the operator stay well below it; a card carrying more than a few tens of euros has been tampered with.
      See Also:
  • Constructor Details

  • Method Details

    • decode

      public static Balance decode(byte[] block)
      Decodes the value block of block 8 or 9, checking the complement and the copy the MIFARE value block format holds.
      Parameters:
      block - the sixteen bytes
      Returns:
      the balance
      Throws:
      CardFormatException - if the block is not sixteen bytes, the complement or the copy do not match, or the balance is above MAX_UNITS
    • encode

      public byte[] encode()
      Encodes this balance into the value block of blocks 8 and 9.
      Specified by:
      encode in interface Encodable
      Returns:
      the sixteen bytes
    • euros

      public BigDecimal euros()
      The balance in euros, exact to the thousandth.
      Returns:
      the amount in euros
    • toString

      public String toString()
      The balance in euros with three decimals.
      Specified by:
      toString in class Record
      Returns:
      the printed amount
    • 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 '=='.
      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.
    • units

      public long units()
      Returns the value of the units record component.
      Returns:
      the value of the units record component