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 this.parameters = SmtpUtils.toUnmodifiableList(parameters);
47 }
48
49
50
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 }