Change optional primitive methods to return specialized optional classes.


The Configuration methods that return Optional<> (findXXX() after ) for primitive types such as int currently use wrappers to return an instance of Optional<> with an object, such as Optional<Integer>. These should be probably be converted to use the specialized classes such as OptionalInt.

The general Optional<> class was originally used (here and in Rincl) for two main reasons:

  • Optional<> has some extra methods that the specialized classes don't.

  • It allowed a common requireConfiguration() utility class to require a value for the non-Optional methods and throw an exception with a useful method if not present.

The greater efficiency of the specialized classes mean we should probably go ahead and use them. Users can convert them to Optional<> if they need extra capabilities, and we'll probably be refactoring requireConfiguration() anyway. This tiny implementation benefit shouldn't drive the API design.

We should consider adding a general findValue(String key, Class<T> type) method that would return an Optional<Integer> for int, but to pull this off we'd probably want to use some sort of converter such as in CONFOUND-15.




Garret Wilson
January 31, 2019, 6:24 PM

In working on I discovered that one of the methods for retrieving a long was returning an int, so I fixed that.

Garret Wilson
January 31, 2019, 6:19 PM

I accidentally resolved this after seeing a merged pull request. It hasn't been implemented yet, so I'm reopening it.



Garret Wilson


Garret Wilson



Fix versions