001////////////////////////////////////////////////////////////////////////////////
002// checkstyle: Checks Java source code for adherence to a set of rules.
003// Copyright (C) 2001-2015 the original author or authors.
004//
005// This library is free software; you can redistribute it and/or
006// modify it under the terms of the GNU Lesser General Public
007// License as published by the Free Software Foundation; either
008// version 2.1 of the License, or (at your option) any later version.
009//
010// This library is distributed in the hope that it will be useful,
011// but WITHOUT ANY WARRANTY; without even the implied warranty of
012// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
013// Lesser General Public License for more details.
014//
015// You should have received a copy of the GNU Lesser General Public
016// License along with this library; if not, write to the Free Software
017// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
018////////////////////////////////////////////////////////////////////////////////
019
020package com.puppycrawl.tools.checkstyle.api;
021
022import java.util.Set;
023import java.util.SortedSet;
024
025import com.google.common.collect.Sets;
026
027/**
028 * Collection of messages.
029 * @author Oliver Burn
030 */
031public final class LocalizedMessages {
032    /** Contains the messages logged. **/
033    private final Set<LocalizedMessage> messages = Sets.newTreeSet();
034
035    /**
036     * Gets the logged messages.
037     * @return the logged messages
038     */
039    public SortedSet<LocalizedMessage> getMessages() {
040        return Sets.newTreeSet(messages);
041    }
042
043    /** Reset the object. **/
044    public void reset() {
045        messages.clear();
046    }
047
048    /**
049     * Logs a message to be reported.
050     * @param aMsg the message to log
051     **/
052    public void add(LocalizedMessage aMsg) {
053        messages.add(aMsg);
054    }
055
056    /**
057     * Gets the number of messages.
058     * @return the number of messages
059     */
060    public int size() {
061        return messages.size();
062    }
063}