View Javadoc
1   /*
2    * Copyright 2013 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    *   http://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  package io.netty.handler.codec.dns;
17  
18  import static io.netty.handler.codec.dns.DnsClass.IN;
19  
20  /**
21   * The DNS question class which represents a question being sent to a server via
22   * a query, or the question being duplicated and sent back in a response.
23   * Usually a message contains a single question, and DNS servers often don't
24   * support multiple questions in a single query.
25   */
26  public final class DnsQuestion extends DnsEntry {
27  
28      /**
29       * Constructs a question with the default class IN (Internet).
30       *
31       * @param name
32       *            the domain name being queried i.e. "www.example.com"
33       * @param type
34       *            the question type, which represents the type of
35       *            {@link DnsResource} record that should be returned
36       */
37      public DnsQuestion(String name, DnsType type) {
38          this(name, type, IN);
39      }
40  
41      /**
42       * Constructs a question with the given class.
43       *
44       * @param name
45       *            the domain name being queried i.e. "www.example.com"
46       * @param type
47       *            the question type, which represents the type of
48       *            {@link DnsResource} record that should be returned
49       * @param qClass
50       *            the class of a DNS record
51       */
52      public DnsQuestion(String name, DnsType type, DnsClass qClass) {
53          super(name, type, qClass);
54  
55          if (name.isEmpty()) {
56              throw new IllegalArgumentException("name must not be left blank.");
57          }
58      }
59  
60      @Override
61      public boolean equals(Object other) {
62          if (!(other instanceof DnsQuestion)) {
63              return false;
64          }
65          return super.equals(other);
66      }
67  
68      @Override
69      public int hashCode() {
70          return super.hashCode();
71      }
72  }