THIS IS A TEST INSTANCE. ALL YOUR CHANGES WILL BE LOST!!!!
...
Code Block | ||
---|---|---|
| ||
// An example interface that provides pre-defined parameters.
public interface MyParams<T> extends WithParams<T> {
Param<Boolean> BOOLEAN_PARAM = new BooleanParam("booleanParam", "Description", false);
Param<Integer> INT_PARAM = new IntParam("intParam", "Description", 1, ParamValidators.lt(100));
Param<Long> LONG_PARAM = new LongParam("longParam", "Description", 2L, ParamValidators.lt(100));
Param<Integer[]> INT_ARRAY_PARAM = new IntArrayParam("intArrayParam", "Description", new Integer[] {3, 4});
Param<String[]> STRING_ARRAY_PARAM = new StringArrayParam("stringArrayParam", "Description", new String[] {"5", "6"});
}
// An example stage class that defines its own parameters and also inherits parameters from MyParams.
public static class MyStage implements Stage<MyStage>, MyParams<MyStage> {
private final Map<Param<?>, Object> paramMap = new HashMap<>();
Param<Integer> extraIntParam = new IntParam("extraIntParam", "Description", 100, ParamValidator.ALWAYS_TRUE);
public MyStage() {}
@Override
public Map<Param<?>, Object> getUserDefinedParamMap() {
return paramMap;
}
// Skipped implementation of save() and load().
}
public static void main(String[] args) {
MyStage stage = new MyStage();
// Gets the value of a parameter defined in the MyParams interface without first setting its value.
Long[] longArrayValue = stage.get(MyParams.LONG_ARRAY_PARAM);
// Sets and gets value of a parameter defined in the MyParams interface.
stage.set(MyParams.INT_PARAM, 1);
Integer intValue = stage.get(MyParams.INT_PARAM);
// Sets and gets value of a parameter defined in the MyStage class.
stage.set(stage.extraIntParam, 2);
Integer extraIntValue = stage.get(stage.extraIntParam);
// Sets and gets value of a parameter identified by its name string.
Param<?> longParam = stage.getParam("longParam");
stage.set(longParam, 3L);
Long longValue = (Long) stage.get(stage.getParam("longParam"));
} |
Compatibility, Deprecation, and Migration Plan
...