查看本类的 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.ObjectUtil;
19  import io.netty.util.internal.UnstableApi;
20  
21  import java.util.Collections;
22  import java.util.List;
23  
24  /**
25   * Default {@link SmtpRequest} implementation.
26   */
27  @UnstableApi
28  public final class DefaultSmtpRequest implements SmtpRequest {
29  
30      private final SmtpCommand command;
31      private final List<CharSequence> parameters;
32  
33      /**
34       * Creates a new instance with the given command and no parameters.
35       */
36      public DefaultSmtpRequest(SmtpCommand command) {
37          this.command = ObjectUtil.checkNotNull(command, "command");
38          parameters = Collections.emptyList();
39      }
40  
41      /**
42       * Creates a new instance with the given command and parameters.
43       */
44      public DefaultSmtpRequest(SmtpCommand command, CharSequence... parameters) {
45          this.command = ObjectUtil.checkNotNull(command, "command");
46          this.parameters = SmtpUtils.toUnmodifiableList(parameters);
47      }
48  
49      /**
50       * Creates a new instance with the given command and parameters.
51       */
52      public DefaultSmtpRequest(CharSequence command, CharSequence... parameters) {
53          this(SmtpCommand.valueOf(command), parameters);
54      }
55  
56      DefaultSmtpRequest(SmtpCommand command, List<CharSequence> parameters) {
57          this.command = ObjectUtil.checkNotNull(command, "command");
58          this.parameters = parameters != null ?
59                  Collections.unmodifiableList(parameters) : Collections.<CharSequence>emptyList();
60      }
61  
62      @Override
63      public SmtpCommand command() {
64          return command;
65      }
66  
67      @Override
68      public List<CharSequence> parameters() {
69          return parameters;
70      }
71  
72      @Override
73      public int hashCode() {
74          return command.hashCode() * 31 + parameters.hashCode();
75      }
76  
77      @Override
78      public boolean equals(Object o) {
79          if (!(o instanceof DefaultSmtpRequest)) {
80              return false;
81          }
82  
83          if (o == this) {
84              return true;
85          }
86  
87          DefaultSmtpRequest other = (DefaultSmtpRequest) o;
88  
89          return command().equals(other.command()) &&
90                  parameters().equals(other.parameters());
91      }
92  
93      @Override
94      public String toString() {
95          return "DefaultSmtpRequest{" +
96                  "command=" + command +
97                  ", parameters=" + parameters +
98                  '}';
99      }
100 }