question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

add convenience methods for getting multi-valued properties

See original GitHub issue

The existing Config API only permits retrieving multi-valued properties as arrays like this:

for (String value : config.getValue("my.key", String[].class)) {
    // do something with value
}

I propose we add the following methods to permit retrieving more than one value in a more natural way:

<T> Iterable<T> getValues(String propertyName, Class<T> propertyType);
    
<T> Optional<Iterable<T>> getOptionalValues(String propertyName, Class<T> propertyType);

This would enable the use of lamba-friendly patterns like this:

config.getValues("my.key", String.class)
      .forEach(value -> {
            // do something with value
      });

As a bonus, the developer doesn’t need to worry about asking for String.class or String[].class depending on the scenario.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:16 (16 by maintainers)

github_iconTop GitHub Comments

1reaction
emattheiscommented, Jan 21, 2020

That works for me. Not sure which hacky way is best for obtaining the array class in the default implementation, but the Array#newInstance approach seems like the cleanest since there are no magic string formulas or checked exceptions to deal with.

default <T> List<T> getValues(String propertyName, Class<T> propertyType) {
    @SuppressWarnings("unchecked")
    Class<T[]> arrayType = (Class<T[]>) Array.newInstance(propertyType, 0).getClass();
    return Arrays.asList(getValue(propertyName, arrayType));
}

default <T> Optional<List<T>> getOptionalValues(String propertyName, Class<T> propertyType) {
    @SuppressWarnings("unchecked")
    Class<T[]> arrayType = (Class<T[]>) Array.newInstance(propertyType, 0).getClass();
    return getOptionalValue(propertyName, arrayType).map(Arrays::asList);
}
0reactions
Emily-Jiangcommented, Jul 2, 2020

The PR #501 has been merged a while ago.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Modifying multivalued properties: Exchange 2013 Help
This topic explains how to use the Exchange Management Shell to add values to and remove values from a multivalued property on an...
Read more >
How to set multiple attributes with one value function?
The d3-selection-multi docs for .attrs describes it as "A convenience method on top of selection.attr for setting multiple attributes." Looking ...
Read more >
W6PMultiValue Object (ClickSchedule Server-Side Business ...
You can add elements to multivalued properties by calling their Add... methods. You can retrieve elements by calling their Get... and Item methods, ......
Read more >
Attaching fields to represent inetorgperson data
For more information on multivalued attributes, see Specifying multivalued attributes. Alternative method of adding a field to represent the uid ...
Read more >
prop - Go Packages
Special SCIM property that contains other property. This interface shall be implemented by complex and multiValued properties. A container property usually does ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found