package br.com.caelum.vraptor.validator;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.enterprise.context.RequestScoped;
import javax.inject.Named;

@Named
@RequestScoped
public class Messages {

	private Map<Severity, List<Message>> messages = new HashMap<>();

	public Messages add(Message message) {
		get(message.getSeverity()).add(message);
		return this;
	}

	private List<Message> get(Severity severity) {
		if (!messages.containsKey(severity)) {
			messages.put(severity, new MessageList(new ArrayList<Message>()));
		}
		return messages.get(severity);
	}

	public List<Message> getErrors() {
		return get(Severity.ERROR);
	}

	public List<Message> getInfo() {
		return get(Severity.INFO);
	}

	public List<Message> getWarn() {
		return get(Severity.WARN);
	}
}

@@ -541,20 +541,22 @@
 verity, 
-new 
+create
 MessageL
@@ -563,32 +563,8 @@
 ist(
-new ArrayList%3CMessage%3E()
 ));%0A
@@ -806,11 +806,110 @@
 ARN);%0A%09%7D
+%0A%0A%09private MessageList createMessageList() %7B%0A%09%09return new MessageList(new ArrayList%3CMessage%3E());%0A%09%7D
 %0A%7D%0A

Extracting method to a better name