Record Class ParseResult

java.lang.Object
java.lang.Record
me.pauleff.common.argparse.ParseResult
Record Components:
arguments - the parsed arguments on success, or null when the process should exit
exitCode - a process exit code when >= 0; -1 indicates a successful parse

public record ParseResult(ParsedArguments arguments, int exitCode) extends Record
Represents the outcome of parsing command-line arguments.

Distinguishes between a successful parse that yields ParsedArguments and a terminal result that should end the process with an exit code.

  • Constructor Details

    • ParseResult

      public ParseResult(ParsedArguments arguments, int exitCode)
      Creates an instance of a ParseResult record class.
      Parameters:
      arguments - the value for the arguments record component
      exitCode - the value for the exitCode record component
  • Method Details

    • success

      public static ParseResult success(ParsedArguments arguments)
      Creates a successful parse result that carries the given arguments.
      Parameters:
      arguments - the parsed arguments
      Returns:
      a result with exitCode -1
    • exit

      public static ParseResult exit(int exitCode)
      Creates a terminal parse result that signals the process should exit.
      Parameters:
      exitCode - the process exit code to use
      Returns:
      a result with null arguments and the given exit code
    • shouldExit

      public boolean shouldExit()
      Indicates whether the caller should terminate instead of continuing with conversion.
      Returns:
      true if exitCode is >= 0; false otherwise
    • 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 the compare method from their corresponding wrapper classes.
      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.
    • arguments

      public ParsedArguments arguments()
      Returns the value of the arguments record component.
      Returns:
      the value of the arguments record component
    • exitCode

      public int exitCode()
      Returns the value of the exitCode record component.
      Returns:
      the value of the exitCode record component