Class ScriptResult

java.lang.Object
org.dellroad.javabox.ScriptResult

public class ScriptResult extends Object
The result from executing a script in a JavaBox.

Instances are thread safe.

See Also:
  • Method Details

    • box

      public JavaBox box()
      Get the associated JavaBox.
      Returns:
      associated container
    • source

      public String source()
      Get the original script source.
      Returns:
      script source
    • snippetOutcomes

      public List<SnippetOutcome> snippetOutcomes()
      Get the outcomes of the individual JShell Snippets created from the script.
      Returns:
      script snippet outcomes
    • lastOutcome

      public Optional<SnippetOutcome> lastOutcome()
      Get the outcome of the last Snippet whose execution was attempted.
      Returns:
      last snippet outcome, or empty if there were zero snippets
    • returnValue

      public <T> T returnValue(Class<T> type)
      Convenience method to get the return value from a script's final snippet.

      This is useful in scenarios where the purpose of the script is to produce some result and you want to verify that all snippets up to and including the final snippet were successful.

      This checks that:

      • The script was not empty, i.e., it contained at least one snippet
      • The outcome of every snippet in the script was successful
      • The final snippet was an expression whose value is an instance of the given type

      If the above criteria are not met, a ResultCheckerException is thrown.

      Parameters:
      type - required return type
      Returns:
      script return value (possibly null)
      Throws:
      IllegalArgumentException - if type is null or primitive
      ResultCheckerException - if script failed or did not return a value
      See Also:
    • isSuccessful

      public boolean isSuccessful()
      Determine whether the script exeuction was successful.

      A successful script execution is one in which all of the individual snippetOutcomes are instances of SnippetOutcome.Successful.

      Returns:
      script snippet outcomes