001/*
002 *  Copyright 2012 Anyware Services
003 *
004 *  Licensed under the Apache License, Version 2.0 (the "License");
005 *  you may not use this file except in compliance with the License.
006 *  You may obtain a copy of the License at
007 *
008 *      http://www.apache.org/licenses/LICENSE-2.0
009 *
010 *  Unless required by applicable law or agreed to in writing, software
011 *  distributed under the License is distributed on an "AS IS" BASIS,
012 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 *  See the License for the specific language governing permissions and
014 *  limitations under the License.
015 */
016package org.ametys.runtime.parameter;
017
018import java.util.ArrayList;
019import java.util.Collections;
020import java.util.List;
021
022import org.ametys.runtime.i18n.I18nizableText;
023
024/**
025 * Errors structure to populate on validation.
026 * @see Validator
027 */
028public class Errors
029{
030    private List<I18nizableText> _errors = new ArrayList<>();
031    
032    /**
033     * Tests if there were any errors.
034     * @return <code>true</code> if there is at least one error,
035     *         <code>false</code> if there is no error.
036     */
037    public boolean hasErrors()
038    {
039        return !_errors.isEmpty();
040    }
041    
042    /**
043     * Retrieves the errors.
044     * @return the errors.
045     */
046    public List<I18nizableText> getErrors()
047    {
048        return Collections.unmodifiableList(_errors);
049    }
050    
051    /**
052     * Add an error.
053     * @param errorLabel the error label.
054     */
055    public void addError(I18nizableText errorLabel)
056    {
057        _errors.add(errorLabel);
058    }
059    
060    /**
061     * Add errors.
062     * @param errorLabels the error labels.
063     */
064    public void addErrors(List<I18nizableText> errorLabels)
065    {
066        _errors.addAll(errorLabels);
067    }
068}