Record Class BreakpointSpec

java.lang.Object
java.lang.Record
cs1302.tracer.trace.BreakpointSpec
Record Components:
file - The optional source file name or relative path.
lineNumber - The 1-based source line number, or -1 for end of main execution.

public record BreakpointSpec(Optional<String> file, int lineNumber) extends Record
Specification for a breakpoint target, which may be unqualified (line number only) or file-qualified (relative source file or class name with line number).
  • Constructor Details

    • BreakpointSpec

      public BreakpointSpec(Optional<String> file, int lineNumber)
      Constructs a validated BreakpointSpec.
      Parameters:
      file - Optional file qualification.
      lineNumber - Line number (1-based or -1).
  • Method Details

    • of

      public static BreakpointSpec of(int lineNumber)
      Creates an unqualified breakpoint specification for a line number.
      Parameters:
      lineNumber - Line number.
      Returns:
      BreakpointSpec instance.
    • of

      public static BreakpointSpec of(String file, int lineNumber)
      Creates a file-qualified breakpoint specification.
      Parameters:
      file - Source file name or relative path.
      lineNumber - Line number.
      Returns:
      BreakpointSpec instance.
    • parse

      public static BreakpointSpec parse(String spec)
      Parses a breakpoint string into a BreakpointSpec.

      Supported formats include:

      • "12" - unqualified line number 12
      • "Foo.java:12" - line 12 in Foo.java
      • "pkg/Foo.java:12" - line 12 in pkg/Foo.java
      • "-1" - end of main execution
      Parameters:
      spec - The raw specification string.
      Returns:
      Parsed BreakpointSpec.
      Throws:
      IllegalArgumentException - If syntax is invalid or line number cannot be parsed.
    • matchesSourcePath

      public boolean matchesSourcePath(String sourcePath)
      Checks if this breakpoint specification matches a given source file path.
      Parameters:
      sourcePath - Relative source file path.
      Returns:
      True if this specification matches the given path.
    • matchesReferenceType

      public boolean matchesReferenceType(ReferenceType refType)
      Checks if this breakpoint specification matches a JDI reference type.
      Parameters:
      refType - The JDI ReferenceType to inspect.
      Returns:
      True if this specification applies to the reference type.
    • toString

      public String toString()
      Returns a human-readable representation of this breakpoint spec.
      Specified by:
      toString in class Record
      Returns:
      Formatted breakpoint string.
    • 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 '=='.
      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.
    • file

      public Optional<String> file()
      Returns the value of the file record component.
      Returns:
      the value of the file record component
    • lineNumber

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