Class Reasons

java.lang.Object
net.thauvin.erik.httpstatus.Reasons

@NullMarked public final class Reasons extends Object
Loads HTTP status reason phrases from the resource bundle and provides lookup utilities for individual status codes and status code classes.

The reason phrases are stored in a sorted, immutable map for predictable iteration order and thread‑safe access.

  • Method Details

    • getReasonClass

      public static Map<String,String> getReasonClass(StatusCodeClass reasonClass)
      Returns all reason phrases belonging to the given status code class.

      The returned map is sorted by status code.

      Parameters:
      reasonClass - the status code class to look up
      Returns:
      a sorted map of status codes to reason phrases for the given class
    • getReasonPhrase

      public static @Nullable String getReasonPhrase(int statusCode)
      Returns the reason phrase for the given status code, or null if none exists.
      Parameters:
      statusCode - the HTTP status code
      Returns:
      the reason phrase, or null if none exists
    • getReasonPhrase

      public static @Nullable String getReasonPhrase(String statusCode)
      Returns the reason phrase for the given status code, or null if none exists.
      Parameters:
      statusCode - the HTTP status code as a string
      Returns:
      the reason phrase, or null if none exists
    • getReasonPhrase

      public static String getReasonPhrase(int statusCode, String defaultReason)
      Returns the reason phrase for the given status code, or the provided default value if no phrase is defined.
      Parameters:
      statusCode - the HTTP status code
      defaultReason - the default reason phrase to return if none exists
      Returns:
      the reason phrase, or defaultReason if none exists
    • getReasonPhrase

      public static String getReasonPhrase(String statusCode, String defaultReason)
      Returns the reason phrase for the given status code, or the provided default value if no phrase is defined.
      Parameters:
      statusCode - the HTTP status code as a string
      defaultReason - the default reason phrase to return if none exists
      Returns:
      the reason phrase, or defaultReason if none exists
    • main

      public static void main(String... args)
      Prints reason phrases for the given status code(s) or status code class(es).

      If no arguments are provided, prints all reason phrases.

      Parameters:
      args - the status codes or status code classes to print (e.g., "404", "2xx")