Create collection retrieval methods.

Description

The Configuration interface currently has no way to retrieve a list of items, such as might be represented by a TURF list or even a string with delimiters. See for comparison Apache Commons ImmutableConfiguration.getList(String key).

Implementing this feature will involve several steps:

  • Implement methods to retrieve a collection of objects, both as Collection<Object> and with a passed-in type.

  • Add a means to split strings (if so configured) in the string-based configurations.

  • Add convenience methods to get lists of other types, e.g. URI.

  • Update the key expression to retrieve indexed items in lists (if the collection happens to be a list), e.g. foo[2].bar.

Design Considerations

  • The current thinking is to use Collection<> as the interface. We assume that configuration values are small in number, and there would thus be little reason to return something less rich such as Iterable<>. i.e. We should always expect to have the size. Stream<> is another option, but we can always get a stream from a collection, and the underlying value may be a Set<>, which we couldn't get back to (without collecting the values) if we returned a stream. Lastly we could return a List<>, but we might as well distinguish underlying implementations that are collections but may not be list (again without forcing item collection).

  • We'll continue the get/find dichotomy we have for the single values. That is, findObjects(key) would return an Optional<Collection<Object>>. This will allow us to distinguish between a defined empty list, for example, or an undefined configuration key, because a configuration key defined as [] (an empty list) might be very different than undefined value which means we should use some default. Apache Commons Configuration considers a missing value as an empty list. Consumers who want that sort of functionality can simply use findObjects(key).orElse(Collections.emptyList()).

  • As with Apache Commons Configuration, we'll wrap single, non-collections objects in a collection of one. We'll probably use List<>, but maybe provide a facility to indicate the type of collection. (This could be used as variations of the normal retrieval methods as well.)

Environment

None

Assignee

Garret Wilson

Reporter

Garret Wilson

Labels

None

Priority

Major

Epic Name

Collections
Configure