Home / Class/ DomainNameMapping Class — netty Architecture

DomainNameMapping Class — netty Architecture

Architecture documentation for the DomainNameMapping class in DomainNameMapping.java from the netty codebase.

Entity Profile

Dependency Diagram

graph TD
  c25c4773_f951_fbcd_4633_f867679f934d["DomainNameMapping"]
  43177bd8_f5e2_576a_a4cf_1d2e0d94f0f2["DomainNameMapping.java"]
  c25c4773_f951_fbcd_4633_f867679f934d -->|defined in| 43177bd8_f5e2_576a_a4cf_1d2e0d94f0f2
  f66f62b5_f08d_ed2f_31de_e71dc31ef19a["DomainNameMapping()"]
  c25c4773_f951_fbcd_4633_f867679f934d -->|method| f66f62b5_f08d_ed2f_31de_e71dc31ef19a
  a784202d_0e83_3610_1861_25f2beca5c19["add()"]
  c25c4773_f951_fbcd_4633_f867679f934d -->|method| a784202d_0e83_3610_1861_25f2beca5c19
  f8726707_67c9_c600_1239_abbc09537fa2["matches()"]
  c25c4773_f951_fbcd_4633_f867679f934d -->|method| f8726707_67c9_c600_1239_abbc09537fa2
  4f29e73f_3ba4_b804_6f61_92552d4b5c4c["String()"]
  c25c4773_f951_fbcd_4633_f867679f934d -->|method| 4f29e73f_3ba4_b804_6f61_92552d4b5c4c
  dc924c12_d06e_b834_0b28_d3798341d33d["needsNormalization()"]
  c25c4773_f951_fbcd_4633_f867679f934d -->|method| dc924c12_d06e_b834_0b28_d3798341d33d
  83350eec_9113_e0c4_bf35_4a6088c63d98["V()"]
  c25c4773_f951_fbcd_4633_f867679f934d -->|method| 83350eec_9113_e0c4_bf35_4a6088c63d98
  1cb9de0d_c605_2de5_eff2_dcb1975ef610["asMap()"]
  c25c4773_f951_fbcd_4633_f867679f934d -->|method| 1cb9de0d_c605_2de5_eff2_dcb1975ef610

Relationship Graph

Source Code

common/src/main/java/io/netty/util/DomainNameMapping.java lines 38–152

@Deprecated
public class DomainNameMapping<V> implements Mapping<String, V> {

    final V defaultValue;
    private final Map<String, V> map;
    private final Map<String, V> unmodifiableMap;

    /**
     * Creates a default, order-sensitive mapping. If your hostnames are in conflict, the mapping
     * will choose the one you add first.
     *
     * @param defaultValue the default value for {@link #map(String)} to return when nothing matches the input
     * @deprecated use {@link DomainNameMappingBuilder} to create and fill the mapping instead
     */
    @Deprecated
    public DomainNameMapping(V defaultValue) {
        this(4, defaultValue);
    }

    /**
     * Creates a default, order-sensitive mapping. If your hostnames are in conflict, the mapping
     * will choose the one you add first.
     *
     * @param initialCapacity initial capacity for the internal map
     * @param defaultValue    the default value for {@link #map(String)} to return when nothing matches the input
     * @deprecated use {@link DomainNameMappingBuilder} to create and fill the mapping instead
     */
    @Deprecated
    public DomainNameMapping(int initialCapacity, V defaultValue) {
        this(new LinkedHashMap<String, V>(initialCapacity), defaultValue);
    }

    DomainNameMapping(Map<String, V> map, V defaultValue) {
        this.defaultValue = checkNotNull(defaultValue, "defaultValue");
        this.map = map;
        unmodifiableMap = map != null ? Collections.unmodifiableMap(map)
                                      : null;
    }

    /**
     * Adds a mapping that maps the specified (optionally wildcard) host name to the specified output value.
     * <p>
     * <a href="https://en.wikipedia.org/wiki/Wildcard_DNS_record">DNS wildcard</a> is supported as hostname.
     * For example, you can use {@code *.netty.io} to match {@code netty.io} and {@code downloads.netty.io}.
     * </p>
     *
     * @param hostname the host name (optionally wildcard)
     * @param output   the output value that will be returned by {@link #map(String)} when the specified host name
     *                 matches the specified input host name
     * @deprecated use {@link DomainNameMappingBuilder} to create and fill the mapping instead
     */
    @Deprecated
    public DomainNameMapping<V> add(String hostname, V output) {
        map.put(normalizeHostname(checkNotNull(hostname, "hostname")), checkNotNull(output, "output"));
        return this;
    }

    /**
     * Simple function to match <a href="https://en.wikipedia.org/wiki/Wildcard_DNS_record">DNS wildcard</a>.
     */
    static boolean matches(String template, String hostName) {
        if (template.startsWith("*.")) {
            return template.regionMatches(2, hostName, 0, hostName.length())
                || commonSuffixOfLength(hostName, template, template.length() - 1);
        }
        return template.equals(hostName);
    }

    /**
     * IDNA ASCII conversion and case normalization
     */
    static String normalizeHostname(String hostname) {
        if (needsNormalization(hostname)) {
            hostname = IDN.toASCII(hostname, IDN.ALLOW_UNASSIGNED);
        }
        return hostname.toLowerCase(Locale.US);
    }

    private static boolean needsNormalization(String hostname) {
        final int length = hostname.length();
        for (int i = 0; i < length; i++) {

Frequently Asked Questions

What is the DomainNameMapping class?
DomainNameMapping is a class in the netty codebase, defined in common/src/main/java/io/netty/util/DomainNameMapping.java.
Where is DomainNameMapping defined?
DomainNameMapping is defined in common/src/main/java/io/netty/util/DomainNameMapping.java at line 38.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free