Skip to content

Instantly share code, notes, and snippets.

@chkal
Last active November 23, 2015 16:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chkal/bf3207cf2f01633ffa82 to your computer and use it in GitHub Desktop.
Save chkal/bf3207cf2f01633ffa82 to your computer and use it in GitHub Desktop.
Draft: MVC 1.0 support for message handling
public class Message implements Serializable {
private static final long serialVersionUID = 2518143831776562527L;
public enum Severity {
INFO,
WARN,
ERROR
}
private final Severity severity;
private final String param;
private final String text;
public Message(String text) {
this(Severity.INFO, text);
}
public Message(Severity severity, String text) {
this(severity, null, text);
}
public Message(Severity severity, String param, String text) {
this.severity = Objects.requireNonNull(severity, "Severity must not be null");
this.text = Objects.requireNonNull(text, "Text must not be null");
this.param = param; // optional
}
public Severity getSeverity() {
return severity;
}
public String getParam() {
return param;
}
public String getText() {
return text;
}
}
@RedirectScoped
public class Messages implements Serializable {
private static final long serialVersionUID = 6053885126353989270L;
private final List<Message> messages = new ArrayList<>();
public Messages add(Message message) {
messages.add(message);
return this;
}
public List<Message> getAllMessages() {
return Collections.unmodifiableList(messages);
}
public List<Message> getMessages(String param) {
return messages.stream()
.filter(message -> param.equals(message.getParam()))
.collect(Collectors.toList());
}
}
@ptemplier
Copy link

Severity.SUCCESS could be added

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment