1 /*
2  * Copyright 2019 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 
21 import java.util.ArrayList;
22 import java.util.Collections;
23 import java.util.HashSet;
24 import java.util.List;
25 import java.util.Set;
26 
27 /**
28  * A value set implementation that store multiple values in type C.
29  *
30  * @param <C> The type of the parameter.
31  */
32 public abstract class MultiValueSet<C> {
33 
34     private Set<C> mSet = new HashSet<>();
35 
36     /**
37      * Adds all of the elements in the specified collection to this value set if they're not already
38      * present (optional operation).
39      *
40      * @param  value collection containing elements to be added to this value.
41      */
addAll(@onNull List<C> value)42     public void addAll(@NonNull List<C> value) {
43         mSet.addAll(value);
44     }
45 
46     /**
47      * Returns the list of {@link C} which containing all the elements were added to this value set.
48      */
getAllItems()49     public @NonNull List<C> getAllItems() {
50         return Collections.unmodifiableList(new ArrayList<>(mSet));
51     }
52 
53     /**
54      * Need to implement the clone method for object copy.
55      * @return the cloned instance.
56      */
57     @Override
clone()58     public abstract @NonNull MultiValueSet<C> clone();
59 }
60