Skip to content
This repository has been archived by the owner on May 7, 2020. It is now read-only.

Commit

Permalink
add nullness annotations to config option provider (#6264)
Browse files Browse the repository at this point in the history
Signed-off-by: Markus Rathgeb <maggu2810@gmail.com>
  • Loading branch information
maggu2810 authored and kaikreuzer committed Sep 24, 2018
1 parent d3b2f58 commit 029d7d9
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
Expand Up @@ -16,38 +16,44 @@
import java.util.Collection;
import java.util.Locale;

import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;

/**
* The {@link ConfigOptionProvider} can be implemented and registered as an <i>OSGi</i>
* service to provide {@link ConfigDescription}s options.
*
* @author Chris Jackson - Initial contribution
* @author Kai Kreuzer - added support for contexts
*/
@NonNullByDefault
public interface ConfigOptionProvider {

/**
* Provides a collection of {@link ParameterOptions}s.
*
* @deprecated Use {@link getParameterOptions} with context instead.
*
* @param uri the uri of the config description
* @param param the parameter name for which the requested options shall be returned
* @param uri the uri of the config description
* @param param the parameter name for which the requested options shall be returned
* @param locale the locale in which the result is expected
* @return the configuration options provided by this provider if any or {@code null} otherwise
*/
@Deprecated
Collection<ParameterOption> getParameterOptions(URI uri, String param, Locale locale);
@Nullable
Collection<ParameterOption> getParameterOptions(URI uri, String param, @Nullable Locale locale);

/**
* Provides a collection of {@link ParameterOptions}s.
*
* @param uri the uri of the config description
* @param param the parameter name for which the requested options shall be returned
* @param uri the uri of the config description
* @param param the parameter name for which the requested options shall be returned
* @param context the defined context of the parameter
* @param locale the locale in which the result is expected
* @param locale the locale in which the result is expected
* @return the configuration options provided by this provider if any or {@code null} otherwise
*/
default Collection<ParameterOption> getParameterOptions(URI uri, String param, String context, Locale locale) {
default @Nullable Collection<ParameterOption> getParameterOptions(URI uri, String param, @Nullable String context,
@Nullable Locale locale) {
return getParameterOptions(uri, param, locale);
}
}
Expand Up @@ -289,12 +289,13 @@ public Set<String> getSinkIds(String pattern) {
@Override
public Collection<ParameterOption> getParameterOptions(URI uri, String param, Locale locale) {
if (uri.toString().equals(CONFIG_URI)) {
final Locale safeLocale = locale != null ? locale : Locale.getDefault();
if (CONFIG_DEFAULT_SOURCE.equals(param)) {
return audioSources.values().stream().sorted(comparing(s -> s.getLabel(locale)))
.map(s -> new ParameterOption(s.getId(), s.getLabel(locale))).collect(toList());
return audioSources.values().stream().sorted(comparing(s -> s.getLabel(safeLocale)))
.map(s -> new ParameterOption(s.getId(), s.getLabel(safeLocale))).collect(toList());
} else if (CONFIG_DEFAULT_SINK.equals(param)) {
return audioSinks.values().stream().sorted(comparing(s -> s.getLabel(locale)))
.map(s -> new ParameterOption(s.getId(), s.getLabel(locale))).collect(toList());
return audioSinks.values().stream().sorted(comparing(s -> s.getLabel(safeLocale)))
.map(s -> new ParameterOption(s.getId(), s.getLabel(safeLocale))).collect(toList());
}
}
return null;
Expand Down

0 comments on commit 029d7d9

Please sign in to comment.