Record Class HeapObject

java.lang.Object
java.lang.Record
cs1302.tracer.model.modern.HeapObject
Record Components:
id - The unique reference ID of this heap object.
type - The runtime or declared type of the object.
kind - The category of heap object: "object", "array", "string", "lambda", "box", or "color".
fields - The list of instance fields for objects.
elements - The list of element values for arrays.
value - The scalar string or boxed value.
sam - The single abstract method implementation for lambdas.

public record HeapObject(long id, String type, String kind, List<Variable> fields, List<Object> elements, Object value, String sam) extends Record
Represents a typed heap object in the modern trace format.
  • Constructor Details

    • HeapObject

      public HeapObject(long id, String type, String kind, List<Variable> fields, List<Object> elements, Object value, String sam)
      Creates an instance of a HeapObject record class.
      Parameters:
      id - the value for the id record component
      type - the value for the type record component
      kind - the value for the kind record component
      fields - the value for the fields record component
      elements - the value for the elements record component
      value - the value for the value record component
      sam - the value for the sam record component
  • Method Details

    • ofObject

      public static HeapObject ofObject(long id, String type, List<Variable> fields)
      Factory method for general instance objects.
      Parameters:
      id - The heap object ID.
      type - The object type.
      fields - The object fields.
      Returns:
      A new HeapObject instance for an object.
    • ofArray

      public static HeapObject ofArray(long id, String type, List<Object> elements)
      Factory method for arrays.
      Parameters:
      id - The heap object ID.
      type - The array component or array type.
      elements - The array elements.
      Returns:
      A new HeapObject instance for an array.
    • ofString

      public static HeapObject ofString(long id, String type, String value)
      Factory method for strings with custom type qualification.
      Parameters:
      id - The heap object ID.
      type - The string type name.
      value - The string value.
      Returns:
      A new HeapObject instance for a string.
    • ofString

      public static HeapObject ofString(long id, String value)
      Factory method for strings defaulting to java.lang.String.
      Parameters:
      id - The heap object ID.
      value - The string value.
      Returns:
      A new HeapObject instance for a string.
    • ofBox

      public static HeapObject ofBox(long id, String type, Object value)
      Factory method for boxed primitives.
      Parameters:
      id - The heap object ID.
      type - The boxed type.
      value - The primitive value.
      Returns:
      A new HeapObject instance for a box.
    • ofLambda

      public static HeapObject ofLambda(long id, String type, String sam)
      Factory method for lambdas.
      Parameters:
      id - The heap object ID.
      type - The functional interface type.
      sam - The single abstract method implementation.
      Returns:
      A new HeapObject instance for a lambda.
    • ofColor

      public static HeapObject ofColor(long id, String type, String value)
      Factory method for colors.
      Parameters:
      id - The heap object ID.
      type - The color type name.
      value - The hex color string.
      Returns:
      A new HeapObject instance for a color.
    • 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 '=='.
      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.
    • id

      @SerializedName("id") public long id()
      Returns the value of the id record component.
      Returns:
      the value of the id record component
    • type

      @SerializedName("type") public String type()
      Returns the value of the type record component.
      Returns:
      the value of the type record component
    • kind

      @SerializedName("kind") public String kind()
      Returns the value of the kind record component.
      Returns:
      the value of the kind record component
    • fields

      @SerializedName("fields") public List<Variable> fields()
      Returns the value of the fields record component.
      Returns:
      the value of the fields record component
    • elements

      @SerializedName("elements") public List<Object> elements()
      Returns the value of the elements record component.
      Returns:
      the value of the elements record component
    • value

      @SerializedName("value") public Object value()
      Returns the value of the value record component.
      Returns:
      the value of the value record component
    • sam

      @SerializedName("sam") public String sam()
      Returns the value of the sam record component.
      Returns:
      the value of the sam record component