查看本类的 API文档回源码主页即时通讯网 - 即时通讯开发者社区!
1   /*
2    * Copyright 2016 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  package io.netty.handler.codec.smtp;
17  
18  import io.netty.util.internal.UnstableApi;
19  
20  import java.util.Collections;
21  import java.util.List;
22  
23  /**
24   * Default {@link SmtpResponse} implementation.
25   */
26  @UnstableApi
27  public final class DefaultSmtpResponse implements SmtpResponse {
28  
29      private final int code;
30      private final List<CharSequence> details;
31  
32      /**
33       * Creates a new instance with the given smtp code and no details.
34       */
35      public DefaultSmtpResponse(int code) {
36          this(code, (List<CharSequence>) null);
37      }
38  
39      /**
40       * Creates a new instance with the given smtp code and details.
41       */
42      public DefaultSmtpResponse(int code, CharSequence... details) {
43          this(code, SmtpUtils.toUnmodifiableList(details));
44      }
45  
46      DefaultSmtpResponse(int code, List<CharSequence> details) {
47          if (code < 100 || code > 599) {
48              throw new IllegalArgumentException("code must be 100 <= code <= 599");
49          }
50          this.code = code;
51          if (details == null) {
52              this.details = Collections.emptyList();
53          } else {
54              this.details = Collections.unmodifiableList(details);
55          }
56      }
57  
58      @Override
59      public int code() {
60          return code;
61      }
62  
63      @Override
64      public List<CharSequence> details() {
65          return details;
66      }
67  
68      @Override
69      public int hashCode() {
70          return code * 31 + details.hashCode();
71      }
72  
73      @Override
74      public boolean equals(Object o) {
75          if (!(o instanceof DefaultSmtpResponse)) {
76              return false;
77          }
78  
79          if (o == this) {
80              return true;
81          }
82  
83          DefaultSmtpResponse other = (DefaultSmtpResponse) o;
84  
85          return code() == other.code() &&
86                  details().equals(other.details());
87      }
88  
89      @Override
90      public String toString() {
91          return "DefaultSmtpResponse{" +
92                  "code=" + code +
93                  ", details=" + details +
94                  '}';
95      }
96  }