java.lang.Object
java.lang.Record
dev.hloth.zgztransport.Balance
- Record Components:
units- the balance inUNITS_PER_EUROunits
- All Implemented Interfaces:
Encodable
The balance of blocks 8 and 9, in thousandths of a euro. Personal cards
always hold zero.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final longLargest balance the value block holds.static final longUnits in one euro. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic Balancedecode(byte[] block) Decodes the value block of block 8 or 9, checking the complement and the copy the MIFARE value block format holds.byte[]encode()Encodes this balance into the value block of blocks 8 and 9.final booleanIndicates whether some other object is "equal to" this one.euros()The balance in euros, exact to the thousandth.final inthashCode()Returns a hash code value for this object.toString()The balance in euros with three decimals.longunits()Returns the value of theunitsrecord component.
-
Field Details
-
UNITS_PER_EURO
public static final long UNITS_PER_EUROUnits in one euro.- See Also:
-
MAX_UNITS
public static final long MAX_UNITSLargest 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
-
Balance
public Balance(long units) Checks the range of the balance.- Throws:
IllegalArgumentException- if the balance is negative or aboveMAX_UNITS
-
-
Method Details
-
decode
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 aboveMAX_UNITS
-
encode
public byte[] encode()Encodes this balance into the value block of blocks 8 and 9. -
euros
The balance in euros, exact to the thousandth.- Returns:
- the amount in euros
-
toString
The balance in euros with three decimals. -
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. -
equals
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 '=='. -
units
public long units()Returns the value of theunitsrecord component.- Returns:
- the value of the
unitsrecord component
-