1
2
3
4
5
6
7
8
9
10
11
12
13
14
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
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
35
36 public DefaultSmtpRequest(SmtpCommand command) {
37 this.command = ObjectUtil.checkNotNull(command, "command");
38 parameters = Collections.emptyList();
39 }
40
41
42
43
44 public DefaultSmtpRequest(SmtpCommand command, CharSequence... parameters) {
45 this.command = ObjectUtil.checkNotNull(command, "command");
46 SmtpUtils.validateSMTPParameters(parameters);
47 this.parameters = SmtpUtils.toUnmodifiableList(parameters);
48 }
49
50
51
52
53 public DefaultSmtpRequest(CharSequence command, CharSequence... parameters) {
54 this(SmtpCommand.valueOf(command), parameters);
55 }
56
57 DefaultSmtpRequest(SmtpCommand command, List<CharSequence> parameters) {
58 this.command = ObjectUtil.checkNotNull(command, "command");
59 SmtpUtils.validateSMTPParameters(parameters);
60 this.parameters = parameters != null ?
61 Collections.unmodifiableList(parameters) : Collections.<CharSequence>emptyList();
62 }
63
64 @Override
65 public SmtpCommand command() {
66 return command;
67 }
68
69 @Override
70 public List<CharSequence> parameters() {
71 return parameters;
72 }
73
74 @Override
75 public int hashCode() {
76 return command.hashCode() * 31 + parameters.hashCode();
77 }
78
79 @Override
80 public boolean equals(Object o) {
81 if (!(o instanceof DefaultSmtpRequest)) {
82 return false;
83 }
84
85 if (o == this) {
86 return true;
87 }
88
89 DefaultSmtpRequest other = (DefaultSmtpRequest) o;
90
91 return command().equals(other.command()) &&
92 parameters().equals(other.parameters());
93 }
94
95 @Override
96 public String toString() {
97 return "DefaultSmtpRequest{" +
98 "command=" + command +
99 ", parameters=" + parameters +
100 '}';
101 }
102 }