001/* 002 * Copyright (C) 2013 The Guava Authors 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 005 * in compliance with the License. You may obtain a copy of the License at 006 * 007 * http://www.apache.org/licenses/LICENSE-2.0 008 * 009 * Unless required by applicable law or agreed to in writing, software distributed under the License 010 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 011 * or implied. See the License for the specific language governing permissions and limitations under 012 * the License. 013 */ 014 015package com.google.thirdparty.publicsuffix; 016 017import com.google.common.annotations.Beta; 018import com.google.common.annotations.GwtCompatible; 019 020/** 021 * <b>Do not use this class directly. For access to public-suffix information, use {@link 022 * com.google.common.net.InternetDomainName}.</b> 023 * 024 * <p>Specifies the type of a top-level domain definition. 025 * 026 * @since 23.3 027 */ 028@Beta 029@GwtCompatible 030public enum PublicSuffixType { 031 032 /** Public suffix that is provided by a private company, e.g. "blogspot.com" */ 033 PRIVATE(':', ','), 034 /** Public suffix that is backed by an ICANN-style domain name registry */ 035 REGISTRY('!', '?'); 036 037 /** The character used for an inner node in the trie encoding */ 038 private final char innerNodeCode; 039 040 /** The character used for a leaf node in the trie encoding */ 041 private final char leafNodeCode; 042 043 PublicSuffixType(char innerNodeCode, char leafNodeCode) { 044 this.innerNodeCode = innerNodeCode; 045 this.leafNodeCode = leafNodeCode; 046 } 047 048 char getLeafNodeCode() { 049 return leafNodeCode; 050 } 051 052 char getInnerNodeCode() { 053 return innerNodeCode; 054 } 055 056 /** Returns a PublicSuffixType of the right type according to the given code */ 057 static PublicSuffixType fromCode(char code) { 058 for (PublicSuffixType value : values()) { 059 if (value.getInnerNodeCode() == code || value.getLeafNodeCode() == code) { 060 return value; 061 } 062 } 063 throw new IllegalArgumentException("No enum corresponding to given code: " + code); 064 } 065}