1 /*
2  * Copyright (C) 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 android.media;
18 
19 import android.annotation.NonNull;
20 import android.annotation.Nullable;
21 
22 /**
23  * AudioMetadataMap is a writeable {@code Map}-style
24  * interface of {@link AudioMetadata.Key} value pairs.
25  * This interface is not guaranteed to be thread-safe
26  * unless the underlying implementation for the {@code AudioMetadataMap}
27  * states it as thread safe.
28  *
29  * {@see AudioMetadataReadMap}
30  */
31 // TODO: Create a wrapper like java.util.Collections.synchronizedMap?
32 
33 public interface AudioMetadataMap extends AudioMetadataReadMap {
34     /**
35      * Removes the value associated with the key.
36      * @param key interface for storing the value.
37      * @param <T> type of value.
38      * @return the value of the key, null if it doesn't exist.
39      */
40     @Nullable
remove(@onNull AudioMetadata.Key<T> key)41     <T> T remove(@NonNull AudioMetadata.Key<T> key);
42 
43     /**
44      * Sets a value for the key.
45      *
46      * @param key interface for storing the value.
47      * @param <T> type of value.
48      * @param value a non-null value of type T.
49      * @return the previous value associated with key or null if it doesn't exist.
50      */
51     // See automatic Kotlin overloading for Java interoperability.
52     // https://kotlinlang.org/docs/reference/java-interop.html#operators
53     // See also Kotlin set for overloaded operator indexing.
54     // https://kotlinlang.org/docs/reference/operator-overloading.html#indexed
55     // Also the Kotlin mutable-list set.
56     // https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/-mutable-list/set.html
57     @Nullable
set(@onNull AudioMetadata.Key<T> key, @NonNull T value)58     <T> T set(@NonNull AudioMetadata.Key<T> key, @NonNull T value);
59 }
60