Package com.tnsai.quality.cost
Record Class BudgetState
java.lang.Object
java.lang.Record
com.tnsai.quality.cost.BudgetState
- Record Components:
budget- the budget being evaluatedspentUSD- cumulative spend over the budget's windowremainingUSD-periodBudget - spent, clamped at zerofractionConsumed- in [0, 1] — convenience for "80% used" style dashboardsstatus- coarse status bucket (HEALTHY / WARNING / EXHAUSTED) derived from fractionConsumedevaluatedAt- wall-clock at evaluation time
public record BudgetState(CostBudget budget, BigDecimal spentUSD, BigDecimal remainingUSD, double fractionConsumed, BudgetState.Status status, Instant evaluatedAt)
extends Record
Snapshot of a
CostBudget's consumption (issue #82).
Produced by
— couples a budget definition with the current spend reading so
dashboards / enforcement hooks can present the budget alongside its
current state.invalid reference
CostBudgetEvaluator#evaluate(CostBudget, CostBudgetStore)
- Since:
- 0.5.0 (issue #82)
-
Nested Class Summary
Nested Classes -
Constructor Summary
ConstructorsConstructorDescriptionBudgetState(CostBudget budget, BigDecimal spentUSD, BigDecimal remainingUSD, double fractionConsumed, BudgetState.Status status, Instant evaluatedAt) Creates an instance of aBudgetStaterecord class. -
Method Summary
Modifier and TypeMethodDescriptionbudget()Returns the value of thebudgetrecord component.static BudgetStatecompute(CostBudget budget, BigDecimal spent, Instant evaluatedAt) Build aBudgetStatefrom raw spent + budget values.final booleanIndicates whether some other object is "equal to" this one.Returns the value of theevaluatedAtrecord component.doubleReturns the value of thefractionConsumedrecord component.final inthashCode()Returns a hash code value for this object.booleanBudget is exhausted — at or over the cap.Returns the value of theremainingUSDrecord component.spentUSD()Returns the value of thespentUSDrecord component.status()Returns the value of thestatusrecord component.final StringtoString()Returns a string representation of this record class.
-
Constructor Details
-
BudgetState
public BudgetState(CostBudget budget, BigDecimal spentUSD, BigDecimal remainingUSD, double fractionConsumed, BudgetState.Status status, Instant evaluatedAt) Creates an instance of aBudgetStaterecord class.- Parameters:
budget- the value for thebudgetrecord componentspentUSD- the value for thespentUSDrecord componentremainingUSD- the value for theremainingUSDrecord componentfractionConsumed- the value for thefractionConsumedrecord componentstatus- the value for thestatusrecord componentevaluatedAt- the value for theevaluatedAtrecord component
-
-
Method Details
-
isExhausted
public boolean isExhausted()Budget is exhausted — at or over the cap. -
compute
Build aBudgetStatefrom raw spent + budget values. Computes remaining, fraction, and status consistently so callers don't reproduce the math. -
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 '=='. -
budget
Returns the value of thebudgetrecord component.- Returns:
- the value of the
budgetrecord component
-
spentUSD
Returns the value of thespentUSDrecord component.- Returns:
- the value of the
spentUSDrecord component
-
remainingUSD
Returns the value of theremainingUSDrecord component.- Returns:
- the value of the
remainingUSDrecord component
-
fractionConsumed
public double fractionConsumed()Returns the value of thefractionConsumedrecord component.- Returns:
- the value of the
fractionConsumedrecord component
-
status
Returns the value of thestatusrecord component.- Returns:
- the value of the
statusrecord component
-
evaluatedAt
Returns the value of theevaluatedAtrecord component.- Returns:
- the value of the
evaluatedAtrecord component
-