1 /*
2  * Copyright (C) 2017 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;
18 
19 import android.annotation.NonNull;
20 import android.os.Parcel;
21 import android.os.Parcelable;
22 import android.text.TextUtils;
23 
24 import com.android.internal.util.Preconditions;
25 
26 import java.util.Objects;
27 
28 /** @hide */
29 public final class StringNetworkSpecifier extends NetworkSpecifier implements Parcelable {
30     /**
31      * Arbitrary string used to pass (additional) information to the network factory.
32      */
33     @NonNull
34     public final String specifier;
35 
StringNetworkSpecifier(@onNull String specifier)36     public StringNetworkSpecifier(@NonNull String specifier) {
37         Preconditions.checkStringNotEmpty(specifier);
38         this.specifier = specifier;
39     }
40 
41     /** @hide */
42     @Override
canBeSatisfiedBy(NetworkSpecifier other)43     public boolean canBeSatisfiedBy(NetworkSpecifier other) {
44         return equals(other);
45     }
46 
47     @Override
equals(Object o)48     public boolean equals(Object o) {
49         if (!(o instanceof StringNetworkSpecifier)) return false;
50         return TextUtils.equals(specifier, ((StringNetworkSpecifier) o).specifier);
51     }
52 
53     @Override
hashCode()54     public int hashCode() {
55         return Objects.hashCode(specifier);
56     }
57 
58     @Override
toString()59     public String toString() {
60         return specifier;
61     }
62 
63     @Override
describeContents()64     public int describeContents() {
65         return 0;
66     }
67 
68     @Override
writeToParcel(@onNull Parcel dest, int flags)69     public void writeToParcel(@NonNull Parcel dest, int flags) {
70         dest.writeString(specifier);
71     }
72 
73     public static final @NonNull Parcelable.Creator<StringNetworkSpecifier> CREATOR =
74             new Parcelable.Creator<StringNetworkSpecifier>() {
75         public StringNetworkSpecifier createFromParcel(Parcel in) {
76             return new StringNetworkSpecifier(in.readString());
77         }
78         public StringNetworkSpecifier[] newArray(int size) {
79             return new StringNetworkSpecifier[size];
80         }
81     };
82 }
83