Add ConfigSource.getDefaultOrdinal()
See original GitHub issueDescription
Hi guys,
The spec states that:
Note that a special property config_ordinal can be set within any built-in ConfigSource implementation. The default implementation of getOrdinal() will attempt to read this value. If found and a valid integer, the value will be used. Otherwise the respective default value will be used.
And to handle it properly in our custom built-in ConfigSources we often use following or similar boilerplate:
@Override
public int getOrdinal() {
String configOrdinal = getValue(CONFIG_ORDINAL);
if(configOrdinal != null) {
try {
return Integer.parseInt(configOrdinal);
}
catch (NumberFormatException ignored) {
}
}
return getDefaultOrdinal();
}
public int getDefaultOrdinal() {
return this.defaultOrdinal;
}
So I was wonderwing if a change to default ConfigSource.getOrdinal()
could be made to invoke another default method getDefaultOrdinal
that will return ConfigSource.DEFAULT_ORDINAL
by default and that could be overriden by ConfigSource implementors easily instead of the boilerplate.
- Fixes
The code will looks like:
@Override
default int getOrdinal() {
String configOrdinal = getValue(CONFIG_ORDINAL);
if(configOrdinal != null) {
try {
return Integer.parseInt(configOrdinal);
}
catch (NumberFormatException ignored) {
}
}
return getDefaultOrdinal();
}
default int getDefaultOrdinal() {
return DEFAULT_ORDINAL;
}
WDYT ?
Thanks
Issue Analytics
- State:
- Created 3 years ago
- Comments:9 (5 by maintainers)
Top GitHub Comments
Sure go ahead.
So @radcortez if you also think there is noting more to talk about and that things are OK as they are, let me know if I can close the issue ?
Thanks