Last active
November 23, 2015 16:24
-
-
Save chkal/bf3207cf2f01633ffa82 to your computer and use it in GitHub Desktop.
Draft: MVC 1.0 support for message handling
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Severity.SUCCESS could be added