Unit? getUnitByIndex(int? index, [Unit? def]) { if (index == null || index < 0 || index >= Unit.values.length) return def; return Unit.values[index]; }