Record Class BudgetState

java.lang.Object
java.lang.Record
com.tnsai.quality.cost.BudgetState
Record Components:
budget - the budget being evaluated
spentUSD - cumulative spend over the budget's window
remainingUSD - periodBudget - spent, clamped at zero
fractionConsumed - in [0, 1] — convenience for "80% used" style dashboards
status - coarse status bucket (HEALTHY / WARNING / EXHAUSTED) derived from fractionConsumed
evaluatedAt - 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

invalid reference
CostBudgetEvaluator#evaluate(CostBudget, CostBudgetStore)
— couples a budget definition with the current spend reading so dashboards / enforcement hooks can present the budget alongside its current state.
Since:
0.5.0 (issue #82)
  • Constructor Details

    • BudgetState

      public BudgetState(CostBudget budget, BigDecimal spentUSD, BigDecimal remainingUSD, double fractionConsumed, BudgetState.Status status, Instant evaluatedAt)
      Creates an instance of a BudgetState record class.
      Parameters:
      budget - the value for the budget record component
      spentUSD - the value for the spentUSD record component
      remainingUSD - the value for the remainingUSD record component
      fractionConsumed - the value for the fractionConsumed record component
      status - the value for the status record component
      evaluatedAt - the value for the evaluatedAt record component
  • Method Details

    • isExhausted

      public boolean isExhausted()
      Budget is exhausted — at or over the cap.
    • compute

      public static BudgetState compute(CostBudget budget, BigDecimal spent, Instant evaluatedAt)
      Build a BudgetState from raw spent + budget values. Computes remaining, fraction, and status consistently so callers don't reproduce the math.
    • toString

      public final String 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.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • 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.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      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 with Objects::equals(Object,Object); primitive components are compared with '=='.
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • budget

      public CostBudget budget()
      Returns the value of the budget record component.
      Returns:
      the value of the budget record component
    • spentUSD

      public BigDecimal spentUSD()
      Returns the value of the spentUSD record component.
      Returns:
      the value of the spentUSD record component
    • remainingUSD

      public BigDecimal remainingUSD()
      Returns the value of the remainingUSD record component.
      Returns:
      the value of the remainingUSD record component
    • fractionConsumed

      public double fractionConsumed()
      Returns the value of the fractionConsumed record component.
      Returns:
      the value of the fractionConsumed record component
    • status

      public BudgetState.Status status()
      Returns the value of the status record component.
      Returns:
      the value of the status record component
    • evaluatedAt

      public Instant evaluatedAt()
      Returns the value of the evaluatedAt record component.
      Returns:
      the value of the evaluatedAt record component