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.UnstableApi;
19
20 import java.util.Collections;
21 import java.util.List;
22
23
24
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
34
35 public DefaultSmtpResponse(int code) {
36 this(code, (List<CharSequence>) null);
37 }
38
39
40
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 }