java.lang.Object
java.lang.Record
dev.hloth.zgztransport.Transaction
- Record Components:
cardType- the product of the card that made itnetworkFlag- byte 1,0on top up cards and1or2on personal onesamount- the money moved, inBalance.UNITS_PER_EUROunits,0on a free transferconsecutivePayments- payments of this card at one terminal in a row, counting from1, or0on a top upstop- where it happenedroute- the route, orRoute0on a top up made off boardkind- whether it was a journey or a top uprunCounter- byte 9, on buses most likely the ordinal of the run the vehicle was oncreatedAt- when the card wrote the recordsequence-0to4, which picks the archive block the record moves to
- All Implemented Interfaces:
Encodable
public record Transaction(CardType cardType, int networkFlag, int amount, int consecutivePayments, Stop stop, Route route, TransactionKind kind, int runCounter, CardDateTime createdAt, int sequence)
extends Record
implements Encodable
One record of the transaction log: a journey or a top up, with where and when
it happened.
-
Constructor Summary
ConstructorsConstructorDescriptionTransaction(CardType cardType, int networkFlag, int amount, int consecutivePayments, Stop stop, Route route, TransactionKind kind, int runCounter, CardDateTime createdAt, int sequence) Checks the ranges of the numeric fields and that the others are present. -
Method Summary
Modifier and TypeMethodDescriptionintamount()Returns the value of theamountrecord component.static TransactionBuilderbuilder()A builder, which spares the caller a constructor of ten arguments.cardType()Returns the value of thecardTyperecord component.intReturns the value of theconsecutivePaymentsrecord component.Returns the value of thecreatedAtrecord component.static Transactiondecode(byte[] block) Decodes one record of the log.The direction of this transaction when it is a journey.byte[]encode()Encodes this transaction into one record of the log.final booleanIndicates whether some other object is "equal to" this one.final inthashCode()Returns a hash code value for this object.booleanWhether this is a ride that cost nothing, which the operator grants within about half an hour of a paid one.kind()Returns the value of thekindrecord component.intReturns the value of thenetworkFlagrecord component.route()Returns the value of therouterecord component.intReturns the value of therunCounterrecord component.intsequence()Returns the value of thesequencerecord component.stop()Returns the value of thestoprecord component.final StringtoString()Returns a string representation of this record class.
-
Constructor Details
-
Transaction
public Transaction(CardType cardType, int networkFlag, int amount, int consecutivePayments, Stop stop, Route route, TransactionKind kind, int runCounter, CardDateTime createdAt, int sequence) Checks the ranges of the numeric fields and that the others are present.- Throws:
IllegalArgumentException- if a field is outside the range its byte allowsNullPointerException- if a field is null
-
-
Method Details
-
decode
Decodes one record of the log.- Parameters:
block- the sixteen bytes- Returns:
- the transaction
- Throws:
CardFormatException- if the block is not sixteen bytes, no known product starts with byte 0, the timestamp is out of range, or byte 8 is neither a direction nor a top up
-
encode
public byte[] encode()Encodes this transaction into one record of the log. -
builder
A builder, which spares the caller a constructor of ten arguments.- Returns:
- an empty builder
-
isFreeTransfer
public boolean isFreeTransfer()Whether this is a ride that cost nothing, which the operator grants within about half an hour of a paid one.- Returns:
- true when this is a journey of amount zero
-
direction
The direction of this transaction when it is a journey.- Returns:
- the direction, or empty on a top up
-
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. -
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. Reference components are compared withObjects::equals(Object,Object); primitive components are compared with '=='. -
cardType
Returns the value of thecardTyperecord component.- Returns:
- the value of the
cardTyperecord component
-
networkFlag
public int networkFlag()Returns the value of thenetworkFlagrecord component.- Returns:
- the value of the
networkFlagrecord component
-
amount
public int amount()Returns the value of theamountrecord component.- Returns:
- the value of the
amountrecord component
-
consecutivePayments
public int consecutivePayments()Returns the value of theconsecutivePaymentsrecord component.- Returns:
- the value of the
consecutivePaymentsrecord component
-
stop
Returns the value of thestoprecord component.- Returns:
- the value of the
stoprecord component
-
route
Returns the value of therouterecord component.- Returns:
- the value of the
routerecord component
-
kind
Returns the value of thekindrecord component.- Returns:
- the value of the
kindrecord component
-
runCounter
public int runCounter()Returns the value of therunCounterrecord component.- Returns:
- the value of the
runCounterrecord component
-
createdAt
Returns the value of thecreatedAtrecord component.- Returns:
- the value of the
createdAtrecord component
-
sequence
public int sequence()Returns the value of thesequencerecord component.- Returns:
- the value of the
sequencerecord component
-