Record Class PurchaseResult
java.lang.Object
java.lang.Record
com.csse3200.game.components.shop.PurchaseResult
- Record Components:
ok
-true
if the purchase was successful;false
otherwise.error
- The error type if the purchase failed, orPurchaseError.NONE
if successful.entry
- The purchased catalog entry, ornull
if the purchase failed.qty
- The quantity purchased.0
if the purchase failed.
public record PurchaseResult(boolean ok, PurchaseError error, CatalogEntry entry, int qty)
extends Record
Represents the outcome of a purchase attempt in the shop system.
A PurchaseResult
indicates whether the purchase succeeded,
the type of error (if any), the catalog entry involved, and the
quantity purchased.
-
Constructor Summary
ConstructorsConstructorDescriptionPurchaseResult
(boolean ok, PurchaseError error, CatalogEntry entry, int qty) Creates an instance of aPurchaseResult
record class. -
Method Summary
Modifier and TypeMethodDescriptionentry()
Returns the value of theentry
record component.final boolean
Indicates whether some other object is "equal to" this one.error()
Returns the value of theerror
record component.static PurchaseResult
Creates a failed purchase result.final int
hashCode()
Returns a hash code value for this object.boolean
ok()
Returns the value of theok
record component.static PurchaseResult
ok
(CatalogEntry entry, int qty) Creates a successful purchase result.int
qty()
Returns the value of theqty
record component.final String
toString()
Returns a string representation of this record class.
-
Constructor Details
-
Method Details
-
ok
Creates a successful purchase result.- Parameters:
entry
- The catalog entry that was purchased (must not benull
).qty
- The number of units purchased (must be> 0
).- Returns:
- A
PurchaseResult
indicating success with the specified entry and quantity.
-
fail
Creates a failed purchase result.- Parameters:
e
- The error indicating why the purchase failed.- Returns:
- A
PurchaseResult
indicating failure with the specified error. Theentry
will benull
andqty
will be0
.
-
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 '=='. -
ok
public boolean ok()Returns the value of theok
record component.- Returns:
- the value of the
ok
record component
-
error
Returns the value of theerror
record component.- Returns:
- the value of the
error
record component
-
entry
Returns the value of theentry
record component.- Returns:
- the value of the
entry
record component
-
qty
public int qty()Returns the value of theqty
record component.- Returns:
- the value of the
qty
record component
-