Java tutorial
/* * Copyright 2016 OPEN TONE Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package jp.co.opentone.bsol.framework.web.view.util; import java.io.Serializable; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import org.apache.commons.lang.StringUtils; import jp.co.opentone.bsol.framework.core.message.Message; /** * ??. * @author opentone */ public class MessageTable implements Serializable { /** * serialVersionUID. */ private static final long serialVersionUID = 7059081103388354024L; /** * . */ private Map<String, List<Message>> messageTable = new HashMap<String, List<Message>>(); /** * ???. */ private String lastAddMessageKey; /** * . */ public MessageTable() { } /** * 1???. * @param key * @param message ? */ public void addMessage(String key, Message message) { if (StringUtils.isNotEmpty(key) && null != message) { List<Message> messageList = messageTable.get(key); if (null == messageList) { messageList = new ArrayList<Message>(); } messageList.add(message); messageTable.put(key, messageList); lastAddMessageKey = key; } } /** * ????. * @param key * @return ??. ????null. */ public List<Message> getMessage(String key) { return getMessage(key, false); } /** * ????. * ?????????????. * @param key * @param isRemoveAll ??????true * @return ??. ????null. */ public List<Message> getMessage(String key, boolean isRemoveAll) { List<Message> messageList = null; if (StringUtils.isNotEmpty(key)) { messageList = messageTable.get(key); } if (isRemoveAll) { messageTable.remove(key); } return messageList; } /** * ???????????. */ public void removeAll() { messageTable.clear(); lastAddMessageKey = null; } /** * ???.????. * @return ???. */ public String getLastAddKey() { return lastAddMessageKey; } }