Home / Class/ DomainNameMappingBuilder Class — netty Architecture

DomainNameMappingBuilder Class — netty Architecture

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

Entity Profile

Dependency Diagram

graph TD
  0887840e_80f4_a650_71a2_5e987527ee92["DomainNameMappingBuilder"]
  294da090_10a1_718d_ed47_827fca44dc48["DomainNameMappingBuilder.java"]
  0887840e_80f4_a650_71a2_5e987527ee92 -->|defined in| 294da090_10a1_718d_ed47_827fca44dc48
  00c5c7da_ad75_647c_d1fe_5e747d3c57fb["DomainNameMappingBuilder()"]
  0887840e_80f4_a650_71a2_5e987527ee92 -->|method| 00c5c7da_ad75_647c_d1fe_5e747d3c57fb
  fd668b68_4512_25e9_a0cf_dffba2ecc759["add()"]
  0887840e_80f4_a650_71a2_5e987527ee92 -->|method| fd668b68_4512_25e9_a0cf_dffba2ecc759
  309b06b0_0a4f_3cbc_934d_2839cb548e57["build()"]
  0887840e_80f4_a650_71a2_5e987527ee92 -->|method| 309b06b0_0a4f_3cbc_934d_2839cb548e57

Relationship Graph

Source Code

common/src/main/java/io/netty/util/DomainNameMappingBuilder.java lines 32–206

@Deprecated
public final class DomainNameMappingBuilder<V> {

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

    /**
     * Constructor with default initial capacity of the map holding the mappings
     *
     * @param defaultValue the default value for {@link DomainNameMapping#map(String)} to return
     *                     when nothing matches the input
     */
    public DomainNameMappingBuilder(V defaultValue) {
        this(4, defaultValue);
    }

    /**
     * Constructor with initial capacity of the map holding the mappings
     *
     * @param initialCapacity initial capacity for the internal map
     * @param defaultValue    the default value for {@link DomainNameMapping#map(String)} to return
     *                        when nothing matches the input
     */
    public DomainNameMappingBuilder(int initialCapacity, V defaultValue) {
        this.defaultValue = checkNotNull(defaultValue, "defaultValue");
        map = new LinkedHashMap<String, V>(initialCapacity);
    }

    /**
     * Adds a mapping that maps the specified (optionally wildcard) host name to the specified output value.
     * Null values are forbidden for both hostnames and values.
     * <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 DomainNameMapping#map(String)}
     *                 when the specified host name matches the specified input host name
     */
    public DomainNameMappingBuilder<V> add(String hostname, V output) {
        map.put(checkNotNull(hostname, "hostname"), checkNotNull(output, "output"));
        return this;
    }

    /**
     * Creates a new instance of immutable {@link DomainNameMapping}
     * Attempts to add new mappings to the result object will cause {@link UnsupportedOperationException} to be thrown
     *
     * @return new {@link DomainNameMapping} instance
     */
    public DomainNameMapping<V> build() {
        return new ImmutableDomainNameMapping<V>(defaultValue, map);
    }

    /**
     * Immutable mapping from domain name pattern to its associated value object.
     * Mapping is represented by two arrays: keys and values. Key domainNamePatterns[i] is associated with values[i].
     *
     * @param <V> concrete type of value objects
     */
    private static final class ImmutableDomainNameMapping<V> extends DomainNameMapping<V> {
        private static final String REPR_HEADER = "ImmutableDomainNameMapping(default: ";
        private static final String REPR_MAP_OPENING = ", map: {";
        private static final String REPR_MAP_CLOSING = "})";
        private static final int REPR_CONST_PART_LENGTH =
            REPR_HEADER.length() + REPR_MAP_OPENING.length() + REPR_MAP_CLOSING.length();

        private final String[] domainNamePatterns;
        private final V[] values;
        private final Map<String, V> map;

        @SuppressWarnings("unchecked")
        private ImmutableDomainNameMapping(V defaultValue, Map<String, V> map) {
            super(null, defaultValue);

            Set<Map.Entry<String, V>> mappings = map.entrySet();
            int numberOfMappings = mappings.size();
            domainNamePatterns = new String[numberOfMappings];
            values = (V[]) new Object[numberOfMappings];

Frequently Asked Questions

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

Analyze Your Own Codebase

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

Try Supermodel Free