1 /* 2 * Copyright (C) 2015 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.security.net.config; 18 19 import android.annotation.Nullable; 20 21 import java.util.Locale; 22 23 /** @hide */ 24 public final class Domain { 25 /** 26 * Lower case hostname for this domain rule. 27 */ 28 public final String hostname; 29 30 /** 31 * Whether this domain includes subdomains. 32 */ 33 public final boolean subdomainsIncluded; 34 Domain(String hostname, boolean subdomainsIncluded)35 public Domain(String hostname, boolean subdomainsIncluded) { 36 if (hostname == null) { 37 throw new NullPointerException("Hostname must not be null"); 38 } 39 this.hostname = hostname.toLowerCase(Locale.US); 40 this.subdomainsIncluded = subdomainsIncluded; 41 } 42 43 @Override hashCode()44 public int hashCode() { 45 return hostname.hashCode() ^ (subdomainsIncluded ? 1231 : 1237); 46 } 47 48 @Override equals(@ullable Object other)49 public boolean equals(@Nullable Object other) { 50 if (other == this) { 51 return true; 52 } 53 if (!(other instanceof Domain)) { 54 return false; 55 } 56 Domain otherDomain = (Domain) other; 57 return otherDomain.subdomainsIncluded == this.subdomainsIncluded && 58 otherDomain.hostname.equals(this.hostname); 59 } 60 } 61