1/* 2 * Copyright (C) 2013 The Guava Authors 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 com.google.thirdparty.publicsuffix; 18 19import com.google.common.annotations.GwtCompatible; 20 21/** 22 * Specifies the type of a top-level domain definition. 23 */ 24@GwtCompatible 25enum PublicSuffixType { 26 27 /** private definition of a top-level domain */ 28 PRIVATE(':', ','), 29 /** ICANN definition of a top-level domain */ 30 ICANN('!', '?'); 31 32 /** The character used for an inner node in the trie encoding */ 33 private final char innerNodeCode; 34 35 /** The character used for a leaf node in the trie encoding */ 36 private final char leafNodeCode; 37 38 private PublicSuffixType(char innerNodeCode, char leafNodeCode) { 39 this.innerNodeCode = innerNodeCode; 40 this.leafNodeCode = leafNodeCode; 41 } 42 43 char getLeafNodeCode() { 44 return leafNodeCode; 45 } 46 47 char getInnerNodeCode() { 48 return innerNodeCode; 49 } 50 51 /** Returns a PublicSuffixType of the right type according to the given code */ 52 static PublicSuffixType fromCode(char code) { 53 for (PublicSuffixType value : values()) { 54 if (value.getInnerNodeCode() == code || value.getLeafNodeCode() == code) { 55 return value; 56 } 57 } 58 throw new IllegalArgumentException("No enum corresponding to given code: " + code); 59 } 60 61 static PublicSuffixType fromIsPrivate(boolean isPrivate) { 62 return isPrivate ? PRIVATE : ICANN; 63 } 64} 65