* Format the current element as an ordinary descriptor. If we are iterating
* over the descriptors rather than values, then the "value" column will be
* filled with the default value specified in descriptors.
*/
if (generalDescriptor instanceof ParameterDescriptor) {
final ParameterDescriptor descriptor = (ParameterDescriptor) generalDescriptor;
table.write(Classes.getShortName(descriptor.getValueClass()));
table.nextColumn();
table.setAlignment(TableWriter.ALIGN_RIGHT);
Object value = descriptor.getMinimumValue();
if (value != null) {
table.write(formatValue(value));
}
table.nextColumn();
value = descriptor.getMaximumValue();
if (value != null) {
table.write(formatValue(value));
}
table.nextColumn();
if (generalValue != null) {
value = ((ParameterValue) generalValue).getValue();
} else {
value = descriptor.getDefaultValue();
}
/*
* Wraps the value in an array. Because it may be an array of primitive
* type, we can't cast to Object[]. Then, each array's element will be
* formatted on its own line.
*/
final Object array;
if (value!=null && value.getClass().isArray()) {
array = value;
} else {
array = array1;
array1[0] = value;
}
final int length = Array.getLength(array);
for (int i=0; i<length; i++) {
value = Array.get(array, i);
if (value != null) {
if (i != 0) {
table.write(lineSeparator);
}
table.write(formatValue(value));
}
}
table.nextColumn();
table.setAlignment(TableWriter.ALIGN_LEFT);
value = descriptor.getUnit();
if (value != null) {
table.write(value.toString());
}
}
table.writeHorizontalSeparator();
}
table.flush();
/*
* Now format all groups deferred to the end of this table.
* Most of the time, there is no such group.
*/
if (deferredGroups != null) {
for (final Object element : deferredGroups) {
final ParameterValueGroup value;
final ParameterDescriptorGroup descriptor;
if (element instanceof ParameterValueGroup) {
value = (ParameterValueGroup) element;
descriptor = value.getDescriptor();
} else {
value = null;
descriptor = (ParameterDescriptorGroup) element;
}
out.write(lineSeparator);
format(name + '/' + descriptor.getName().getCode(), descriptor, value);
}
}
}