1 /*
2  * Copyright 2020 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package androidx.camera.core.impl;
18 
19 import org.jspecify.annotations.NonNull;
20 import org.jspecify.annotations.Nullable;
21 
22 import java.util.Set;
23 
24 /**
25  * Interface that can be extended to create APIs for reading specific options.
26  *
27  * <p>ReadableConfig objects are also {@link Config} objects, so can be passed to any method that
28  * expects a {@link Config}.
29  */
30 public interface ReadableConfig extends Config {
31 
32     /**
33      * Returns the underlying immutable {@link Config} object.
34      *
35      * @return The underlying {@link Config} object.
36      */
getConfig()37     @NonNull Config getConfig();
38 
39     @Override
containsOption(@onNull Option<?> id)40     default boolean containsOption(@NonNull Option<?> id) {
41         return getConfig().containsOption(id);
42     }
43 
44     @Override
retrieveOption(@onNull Option<ValueT> id)45     default <ValueT> @Nullable ValueT retrieveOption(@NonNull Option<ValueT> id) {
46         return getConfig().retrieveOption(id);
47     }
48 
49     @Override
retrieveOption(@onNull Option<ValueT> id, @Nullable ValueT valueIfMissing)50     default <ValueT> @Nullable ValueT retrieveOption(@NonNull Option<ValueT> id,
51             @Nullable ValueT valueIfMissing) {
52         return getConfig().retrieveOption(id, valueIfMissing);
53     }
54 
55     @Override
findOptions(@onNull String idSearchString, @NonNull OptionMatcher matcher)56     default void findOptions(@NonNull String idSearchString, @NonNull OptionMatcher matcher) {
57         getConfig().findOptions(idSearchString, matcher);
58     }
59 
60     @Override
listOptions()61     default @NonNull Set<Option<?>> listOptions() {
62         return getConfig().listOptions();
63     }
64 
65     @Override
retrieveOptionWithPriority(@onNull Option<ValueT> id, @NonNull OptionPriority priority)66     default <ValueT> @Nullable ValueT retrieveOptionWithPriority(@NonNull Option<ValueT> id,
67             @NonNull OptionPriority priority) {
68         return getConfig().retrieveOptionWithPriority(id, priority);
69     }
70 
71     @Override
getOptionPriority(@onNull Option<?> opt)72     default @NonNull OptionPriority getOptionPriority(@NonNull Option<?> opt) {
73         return getConfig().getOptionPriority(opt);
74     }
75 
76     @Override
getPriorities(@onNull Option<?> option)77     default @NonNull Set<OptionPriority> getPriorities(@NonNull Option<?> option) {
78         return getConfig().getPriorities(option);
79     }
80 }
81