1 /* 2 * Copyright 2015 The Netty Project 3 * 4 * The Netty Project licenses this file to you under the Apache License, 5 * version 2.0 (the "License"); you may not use this file except in compliance 6 * with the License. You may obtain a copy of the License at: 7 * 8 * https://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, WITHOUT 12 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 * License for the specific language governing permissions and limitations 14 * under the License. 15 */ 16 17 package io.netty.util; 18 19 /** 20 * Builder for immutable {@link DomainNameMapping} instances. 21 * 22 * @param <V> concrete type of value objects 23 * @deprecated Use {@link DomainWildcardMappingBuilder} instead. 24 */ 25 @Deprecated 26 public final class DomainMappingBuilder<V> { 27 28 private final DomainNameMappingBuilder<V> builder; 29 30 /** 31 * Constructor with default initial capacity of the map holding the mappings 32 * 33 * @param defaultValue the default value for {@link DomainNameMapping#map(String)} to return 34 * when nothing matches the input 35 */ 36 public DomainMappingBuilder(V defaultValue) { 37 builder = new DomainNameMappingBuilder<V>(defaultValue); 38 } 39 40 /** 41 * Constructor with initial capacity of the map holding the mappings 42 * 43 * @param initialCapacity initial capacity for the internal map 44 * @param defaultValue the default value for {@link DomainNameMapping#map(String)} to return 45 * when nothing matches the input 46 */ 47 public DomainMappingBuilder(int initialCapacity, V defaultValue) { 48 builder = new DomainNameMappingBuilder<V>(initialCapacity, defaultValue); 49 } 50 51 /** 52 * Adds a mapping that maps the specified (optionally wildcard) host name to the specified output value. 53 * Null values are forbidden for both hostnames and values. 54 * <p> 55 * <a href="https://en.wikipedia.org/wiki/Wildcard_DNS_record">DNS wildcard</a> is supported as hostname. 56 * For example, you can use {@code *.netty.io} to match {@code netty.io} and {@code downloads.netty.io}. 57 * </p> 58 * 59 * @param hostname the host name (optionally wildcard) 60 * @param output the output value that will be returned by {@link DomainNameMapping#map(String)} 61 * when the specified host name matches the specified input host name 62 */ 63 public DomainMappingBuilder<V> add(String hostname, V output) { 64 builder.add(hostname, output); 65 return this; 66 } 67 68 /** 69 * Creates a new instance of immutable {@link DomainNameMapping} 70 * Attempts to add new mappings to the result object will cause {@link UnsupportedOperationException} to be thrown 71 * 72 * @return new {@link DomainNameMapping} instance 73 */ 74 public DomainNameMapping<V> build() { 75 return builder.build(); 76 } 77 }