Record Class AccountStatus

java.lang.Object
java.lang.Record
lol.trq.alts.auth.AccountStatus
Record Components:
account - the account this describes, possibly with freshly issued credentials
state - the machine-readable outcome
failure - why the account is not usable, or empty when it is; carried since 1.0.0 in place of the former reason, message and wait

public record AccountStatus(AltAccount account, AccountStatus.State state, Optional<AltsFailure> failure) extends Record
What an account is worth right now, without having logged into it.

The account carried back is the record as it now stands — renewed credentials included — so a caller updates its own view from one place rather than reassembling it.

state() says what the account is; failure() says why it is not usable, in the library's one failure model. A rate limit, for one, is the state AccountStatus.State.UNREACHABLE with a failure of kind AltsFailure.Kind.RATE_LIMITED, whose AltsFailure.retryAfter() carries the wait when the service stated one.

Since:
0.8.0
  • Constructor Details

  • Method Details

    • usable

      public boolean usable()
      Returns whether the account can be logged into as it stands.
      Returns:
      true if the state is AccountStatus.State.VALID or AccountStatus.State.RENEWED
      Since:
      0.8.0
    • message

      public String message()
      Returns a short description to show: the failure's message, or a fixed phrase when the account is usable. Never branch on it.
      Returns:
      the description
      Since:
      0.8.0
    • valid

      public static AccountStatus valid(AltAccount account)
      Creates a status for an account whose stored credentials work.
      Parameters:
      account - the account
      Returns:
      a valid status
      Since:
      0.8.0
    • renewed

      public static AccountStatus renewed(AltAccount account)
      Creates a status for an account that was renewed.
      Parameters:
      account - the account carrying the freshly issued credentials
      Returns:
      a renewed status
      Since:
      0.8.0
    • failure

      public static AccountStatus failure(AltAccount account, AccountStatus.State state, AltsFailure failure)
      Creates a status for an account that cannot be used as it stands.
      Parameters:
      account - the account this describes
      state - the outcome; not AccountStatus.State.VALID or AccountStatus.State.RENEWED
      failure - why the account is not usable
      Returns:
      a failed status
      Since:
      1.0.0
    • 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.
    • account

      public AltAccount account()
      Returns the value of the account record component.
      Returns:
      the value of the account record component
    • state

      public AccountStatus.State state()
      Returns the value of the state record component.
      Returns:
      the value of the state record component
    • failure

      public Optional<AltsFailure> failure()
      Returns the value of the failure record component.
      Returns:
      the value of the failure record component