« Validity controls » : différence entre les versions
Aucun résumé des modifications |
Aucun résumé des modifications |
||
Ligne 1 : | Ligne 1 : | ||
== The GInterval class | == The GInterval class == | ||
<font color=#556B2F>'''GENIUS'''</font> gives the possibility to manage validity intervals (consistent with <font color=#556B2F>'''SIRIUS'''</font> requirements): | <font color=#556B2F>'''GENIUS'''</font> gives the possibility to manage validity intervals (consistent with <font color=#556B2F>'''SIRIUS'''</font> requirements): |
Version du 5 mai 2017 à 10:38
The GInterval class
GENIUS gives the possibility to manage validity intervals (consistent with SIRIUS requirements):
- Only for GEntryReal, GEntryInt, GEntryRealVector et GEntryIntVector widgets
- Possibility to get an error and/or warning information
- For real values, these validity controls of course take into account units management
To do it, we will have to instantiate a GInterval object. The example below shows how to create an [0.,100.] validity interval.
GInterval myInterval = new GInterval(0., 100.);
It is possible to precise if the interval is opened or closed on each side (by default it is inclusive): below, we define the validity interval as [0., 100.[.
GInterval myInterval = new GInterval(0., 100., GInterval.Rule.INCLUSIVE, GInterval.Rule.EXCLUSIVE);
At last, it is possible to add an intermediate "warning" interval meaning that the value is OK but to be careful with it:
GInterval myInterval = new GInterval(10., 90., GInterval.Rule.EXCLUSIVE, GInterval.Rule.EXCLUSIVE,
0., 100., GInterval.Rule.INCLUSIVE, GInterval.Rule.INCLUSIVE);
With that example, the data will be OK if included in the [0.,100.] interval but a warning message will appear if the data will be comprised in the [0.,10.[ or ]90.,100.] intervals.
Note that we can use the infinity definitions given by the Java language to define, for example the [0,∞[ interval:
GInterval myInterval = new GInterval(0., Double.POSITIVE_INFINITY);
At last, in case of an data out of the validity interval (or the warning one), a tooltip is available when the mouse will stay above the input field (see below).
The corresponding code is the following one:
GUnit[] unitDuration = {new GMetricUnit("mn"), new GMetricUnit("s")};
GUnit[] unitThrust = {new GMetricUnit("N")};
GUnit[] unitIsp = {new GMetricUnit("s")};
// Error control validity
durationIhm = new GEntryReal("Duration:", val1, unitDuration);
durationIhm.addInterval( new GInterval(0., Double.POSITIVE_INFINITY) );
// No validity control
thrustIhm = new GEntryReal("Thrust:", val2, unitThrust);
// Error and warning control validity
// Error if ]-Inf,200[ or[400,+Inf[
// Warning if [200,250[ or[350,400[
// OK if[250,350[
ispIhm = new GEntryReal("Isp:", val3, unitIsp);
ispIhm.addInterval( new GInterval(250., 350., GInterval.Rule.INCLUSIVE, GInterval.Rule.EXCLUSIVE,
200., 400., GInterval.Rule.INCLUSIVE, GInterval.Rule.EXCLUSIVE) );
Status management
This validity interval check is not only a graphical one. Indeed, we may also get the status of a widget using the getStatus() method. This method will return a GStatus enumeration : GStatus.OK, GStatus.WARN or GStatus.ERR.
Moreover, from 1.4 version, it is now possible to use a mechanism allowing to globally manage the whole data status. This mechanism uses the GCondensedStatusInterface as explained below.
First, the widgets in which we want to test data validity must implement this interface and thus we have to define the updateCondensedStatus method where we will check the data to be considered:
public class TestForCondensedStatusWidget extends GPanel implements GCondensedStatusInterface {
private final GEntryReal valAngle;
private final GEntryReal valDist;
public final GInterval angleInterval =
new GInterval(30., 60., GInterval.Rule.INCLUSIVE, GInterval.Rule.EXCLUSIVE,
0., 90., GInterval.Rule.INCLUSIVE, GInterval.Rule.EXCLUSIVE);
public final GInterval distInterval =
new GInterval(100.e+3, 1000.e+3, GInterval.Rule.INCLUSIVE, GInterval.Rule.INCLUSIVE,
0., 36000.e+3, GInterval.Rule.INCLUSIVE, GInterval.Rule.INCLUSIVE);
public TestForCondensedStatusWidget() throws GIntervalException {
valAngle = new GEntryReal("Angle entry", 45.);
valAngle.addGInterval(angleInterval);
valDist = new GEntryReal("Distance entry", 500.e+3);
valDist.addGInterval(distInterval);
}
...
@Override
public void updateCondensedStatus(GCondensedStatus arg0) {
// valAngle and valDist are checked
arg0.update(valAngle, valDist);
}
}
Then, to test the global status (for example just before launching an execution), we only have to write something like this:
TestForCondensedStatusWidget widget = new TestForCondensedStatusWidget();
...
GCondensedStatus status = new GCondensedStatus(widget);
// We print the global status ...
System.out.println("Global status: "+status.getStatus());
// We print the list of data with an ERROR status ...
for (int i = 0; i < status.getErrorComponentList().size(); i++) {
System.out.println("Error on "+status.getErrorComponentList().get(i).getNameInConfigFile());
}
// We print the list of data with a WARNING status ...
for (int i = 0; i < status.getWarningComponentList().size(); i++) {
System.out.println("Warning on "+status.getWarningComponentList().get(i).getNameInConfigFile());
}