1 /*
2  * Copyright (C) 2018 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.net.util;
18 
19 import java.util.Collections;
20 import java.util.HashSet;
21 import java.util.Set;
22 import java.util.StringJoiner;
23 
24 
25 /**
26  * @hide
27  */
28 public class InterfaceSet {
29     public final Set<String> ifnames;
30 
InterfaceSet(String... names)31     public InterfaceSet(String... names) {
32         final Set<String> nameSet = new HashSet<>();
33         for (String name : names) {
34             if (name != null) nameSet.add(name);
35         }
36         ifnames = Collections.unmodifiableSet(nameSet);
37     }
38 
39     @Override
toString()40     public String toString() {
41         final StringJoiner sj = new StringJoiner(",", "[", "]");
42         for (String ifname : ifnames) sj.add(ifname);
43         return sj.toString();
44     }
45 
46     @Override
equals(Object obj)47     public boolean equals(Object obj) {
48         return obj != null
49                 && obj instanceof InterfaceSet
50                 && ifnames.equals(((InterfaceSet) obj).ifnames);
51     }
52 }
53