mirror of
https://github.com/google/nomulus.git
synced 2025-08-23 17:51:07 +02:00
Move getTldFromDomainName into DomainNameUtils
------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=118475557
This commit is contained in:
parent
4442f4c31b
commit
b3125ae070
9 changed files with 34 additions and 58 deletions
|
@ -13,15 +13,16 @@
|
|||
// limitations under the License.
|
||||
|
||||
package com.google.domain.registry.model.domain;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkState;
|
||||
import static com.google.common.base.Strings.isNullOrEmpty;
|
||||
import static com.google.common.collect.Sets.difference;
|
||||
import static com.google.common.collect.Sets.union;
|
||||
import static com.google.domain.registry.model.domain.DesignatedContact.Type.REGISTRANT;
|
||||
import static com.google.domain.registry.model.domain.DomainUtils.getTldFromDomainName;
|
||||
import static com.google.domain.registry.util.CollectionUtils.nullToEmptyImmutableCopy;
|
||||
import static com.google.domain.registry.util.CollectionUtils.nullToEmptyImmutableSortedCopy;
|
||||
import static com.google.domain.registry.util.CollectionUtils.union;
|
||||
import static com.google.domain.registry.util.DomainNameUtils.getTldFromDomainName;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.ImmutableSortedSet;
|
||||
|
|
|
@ -1,50 +0,0 @@
|
|||
// Copyright 2016 The Domain Registry Authors. All Rights Reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package com.google.domain.registry.model.domain;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkArgument;
|
||||
|
||||
import com.google.common.base.Strings;
|
||||
import com.google.common.net.InternetDomainName;
|
||||
|
||||
/**
|
||||
* Utility class for dealing with domains.
|
||||
*/
|
||||
public final class DomainUtils {
|
||||
|
||||
/**
|
||||
* Returns the canonicalized TLD part of a valid domain name (just an SLD, no subdomains) by
|
||||
* stripping off the leftmost part.
|
||||
*
|
||||
* <p>This function is compatible with multi-part tlds, e.g. {@code co.uk}. This function will
|
||||
* also work on domains for which the registry is not authoritative. If you are certain that the
|
||||
* input will be under a TLD this registry controls, then it is preferable to use
|
||||
* {@link com.google.domain.registry.model.registry.Registries#findTldForName(InternetDomainName)
|
||||
* Registries#findTldForName}, which will work on hostnames in addition to domains.
|
||||
*
|
||||
* @param fullyQualifiedDomainName must be a punycode SLD (not a host or unicode)
|
||||
* @throws IllegalArgumentException if there is no TLD
|
||||
*/
|
||||
public static String getTldFromDomainName(String fullyQualifiedDomainName) {
|
||||
checkArgument(
|
||||
!Strings.isNullOrEmpty(fullyQualifiedDomainName),
|
||||
"fullyQualifiedDomainName cannot be null or empty");
|
||||
InternetDomainName domainName = InternetDomainName.from(fullyQualifiedDomainName);
|
||||
checkArgument(domainName.hasParent(), "fullyQualifiedDomainName does not have a TLD");
|
||||
return domainName.parent().toString();
|
||||
}
|
||||
|
||||
private DomainUtils() {}
|
||||
}
|
|
@ -91,8 +91,8 @@ public final class Registries {
|
|||
*
|
||||
* <p><b>Note:</b> This routine will only work on names under TLDs for which this registry is
|
||||
* authoritative. To extract TLDs from domains (not hosts) that other registries control, use
|
||||
* {@link com.google.domain.registry.model.domain.DomainUtils#getTldFromDomainName(String)
|
||||
* DomainUtils#getTldFromDomainName}.
|
||||
* {@link com.google.domain.registry.util.DomainNameUtils#getTldFromDomainName(String)
|
||||
* DomainNameUtils#getTldFromDomainName}.
|
||||
*
|
||||
* @param domainName domain name or host name (but not TLD) under an authoritative TLD
|
||||
* @return TLD or absent if {@code domainName} has no labels under an authoritative TLD
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue