Record Class PriceLookup<T>

java.lang.Object
java.lang.Record
com.eqixiac.equinix.design.value.ratecard.PriceLookup<T>
Type Parameters:
T - the figure's type (PriceQuote or EgressRate)
Record Components:
value - the figure, or null when unpriced
unpricedReason - why there is no figure; null when value is present
answeredBy - the card that produced the figure (its RateCard.cardName()), or null when unpriced
trail - what each consulted card said, in order (one entry per card for a layered card; empty for a single card)

public record PriceLookup<T>(T value, String unpricedReason, String answeredBy, List<String> trail) extends Record
The answer to one rate-card lookup: the figure, or the reason there is none, plus which card answered and why earlier cards declined. It is the explainable form of the Optional the plain RateCard methods return, for callers that must tell a reader why an item is unpriced.
  • Constructor Details

    • PriceLookup

      public PriceLookup(T value, String unpricedReason, String answeredBy, List<String> trail)
      Requires a reason when there is no value and copies the trail.
  • Method Details

    • priced

      public static <T> PriceLookup<T> priced(T value, String answeredBy)
      Type Parameters:
      T - the figure's type
      Parameters:
      value - the figure
      answeredBy - the card that produced it
      Returns:
      a priced lookup
    • unpriced

      public static <T> PriceLookup<T> unpriced(String reason)
      Type Parameters:
      T - the figure's type
      Parameters:
      reason - why the item cannot be priced
      Returns:
      an unpriced lookup
    • of

      public static <T> PriceLookup<T> of(Optional<T> result, String answeredBy, String reason)
      Adapts a plain Optional result.
      Type Parameters:
      T - the figure's type
      Parameters:
      result - the plain result
      answeredBy - the card's name
      reason - the reason to state when result is empty
      Returns:
      the lookup
    • isPriced

      public boolean isPriced()
      Returns:
      true when there is a figure
    • toOptional

      public Optional<T> toOptional()
      Returns:
      the figure as an Optional
    • reason

      public Optional<String> reason()
      Returns:
      the reason there is no figure, empty when priced
    • map

      public <R> PriceLookup<R> map(Function<T,R> mapper)
      Type Parameters:
      R - the new type
      Parameters:
      mapper - transforms the figure
      Returns:
      a lookup with the mapped figure and the same reason, card and trail
    • withTrail

      public PriceLookup<T> withTrail(List<String> entries)
      Parameters:
      entries - the trail to attach
      Returns:
      a copy with the trail replaced
    • 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. All components in this record class are compared with Objects::equals(Object,Object).
      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.
    • value

      public T value()
      Returns the value of the value record component.
      Returns:
      the value of the value record component
    • unpricedReason

      public String unpricedReason()
      Returns the value of the unpricedReason record component.
      Returns:
      the value of the unpricedReason record component
    • answeredBy

      public String answeredBy()
      Returns the value of the answeredBy record component.
      Returns:
      the value of the answeredBy record component
    • trail

      public List<String> trail()
      Returns the value of the trail record component.
      Returns:
      the value of the trail record component