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,0when the journey cost nothingconsecutivePayments- 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 updutyTrip- byte 9, on buses most likely which trip of the vehicle daily duty this is, counting from1createdAt- 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 dutyTrip, 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 dutyTrip, 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.intdutyTrip()Returns the value of thedutyTriprecord component.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 check-out at a gated station, which carries no payment counter.booleanisFree()Whether this is a ride that cost nothing.booleanWhether this is the free transfer a balance card earns after a paid ride, which the operator grants once per ride, to another route, within 60 minutes on the urban network and 75 when a CTAZ card enters Zaragoza.kind()Returns the value of thekindrecord component.intReturns the value of thenetworkFlagrecord component.route()Returns the value of therouterecord 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 dutyTrip, 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
-
isFree
public boolean isFree()Whether this is a ride that cost nothing. Every journey on a personal unlimited card is free.- Returns:
- true when this is a journey of amount zero
-
isTransfer
public boolean isTransfer()Whether this is the free transfer a balance card earns after a paid ride, which the operator grants once per ride, to another route, within 60 minutes on the urban network and 75 when a CTAZ card enters Zaragoza.- Returns:
- true when this is a free journey carrying a payment counter
-
isCheckOut
public boolean isCheckOut()Whether this is a check-out at a gated station, which carries no payment counter. Rests on the single Cercanias check-out in the dumps, so treat it as provisional.- Returns:
- true when this is a free journey without a payment counter
-
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
-
dutyTrip
public int dutyTrip()Returns the value of thedutyTriprecord component.- Returns:
- the value of the
dutyTriprecord 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
-