1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package com.linecorp.centraldogma.common;
18
19 import static com.linecorp.centraldogma.internal.Util.emailToUsername;
20 import static java.util.Objects.requireNonNull;
21
22 import com.fasterxml.jackson.annotation.JsonCreator;
23 import com.fasterxml.jackson.annotation.JsonProperty;
24
25 import com.linecorp.centraldogma.internal.Util;
26
27
28
29
30 public class Author {
31
32
33
34
35 public static final Author SYSTEM = new Author("System", "system@localhost.localdomain");
36
37
38
39
40 public static final Author DEFAULT = new Author("User", "user@localhost.localdomain");
41
42
43
44
45 public static final Author UNKNOWN = new Author("Unknown", "nobody@no.where");
46
47
48
49
50
51 public static Author ofEmail(String email) {
52 return new Author(emailToUsername(email, "email"), email);
53 }
54
55 private final String name;
56 private final String email;
57
58
59
60
61
62
63 @Deprecated
64 public Author(String email) {
65 this(email, email);
66 }
67
68
69
70
71 @JsonCreator
72 public Author(@JsonProperty("name") String name,
73 @JsonProperty("email") String email) {
74
75 this.name = requireNonNull(name, "name");
76 this.email = Util.validateEmailAddress(email, "email");
77 }
78
79
80
81
82 @JsonProperty
83 public String name() {
84 return name;
85 }
86
87
88
89
90 @JsonProperty
91 public String email() {
92 return email;
93 }
94
95 @Override
96 public int hashCode() {
97 return email.hashCode();
98 }
99
100 @Override
101 public boolean equals(Object o) {
102 if (this == o) {
103 return true;
104 }
105 if (!(o instanceof Author)) {
106 return false;
107 }
108 final Author author = (Author)o;
109 return email.equals(author.email);
110 }
111
112 @Override
113 public String toString() {
114 final StringBuilder buf = new StringBuilder();
115
116 buf.append(Util.simpleTypeName(this));
117 buf.append("[\"");
118 buf.append(name);
119 buf.append("\" <");
120 buf.append(email);
121 buf.append(">]");
122
123 return buf.toString();
124 }
125 }