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