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