The observation information is provided as one DebugResult object for one variable in a row, and It contains multiple value information (ValueInfo object).
You can get the observation information of variable a
from an observation point p
as follows.
Optional<DebugResult> dr = p.getResults("a")
You can also get the observation information of all variables that can be observed from an observation point p
as follows.
HashMap<String, DebugResult> drs = getResults()
A DebugResult may contain multiple value information, and the individual values are stored in a ValueInfo object.
To get the last observed value from a given DebugResult object result
, do the following
ValueInfo vi = result.lv(); // or result.getLatestValue();
String value = vi.getValue();
Note that all the observed values are returned as String in ValueInfo’s getValue().
Also, to get all the observed values, do the following
ArrayList<ValueInfo> vis = result.getValues()
There is an upper limit to the number of observation values to be retained, which is 100 by default.This can be changed as follows (example of increasing the upper limit to 200). Note that this function will not be applied to the observation points that have already been set.
DebugResult.setDefaultMaxRecordNoOfValue(200)
It is also possible to set the maximum value for each variable of the observation point (e.g., increase the maximum value for the variable a
of a certain Point p
to 200). In this case, the setting is immediately reflected in the observation point.
p.getResults("a").get().setMaxRecordNoOfValue(200)
If you want to know which row number and which variable a particular DebugResult is about, you can get the information from the DebugResult as follows If you want to know later which line number and which variable a particular DebugResult is about, extract the Location object from the DebugResult as follows.
var loc = result.getLocation();
int lineNumber = loc.getLineNumber();
String varName = loc.getVarName();
When you observe an array or an instance, you can expand the field values of the array elements or the instance.
If you want to get the last observed values of all fields of an instance a
of class A, you can do the following.
var dr = p.getResults("a").get();
var vi = dr.lv();
ArrayList<ValueInfo> fields = vi.ch();
If you want to get the most recently observed values of all elements of an array a
, the code is the same as above.
Currently, these functions are only available for debugging using JPDA; for debugging using ProbeJ, ch()
will return an empty ArrayList.