001/*
002 * ============================================================================
003 *  Copyright © 2002-2023 by Thomas Thrien.
004 *  All Rights Reserved.
005 * ============================================================================
006 *  Licensed to the public under the agreements of the GNU Lesser General Public
007 *  License, version 3.0 (the "License"). You may obtain a copy of the License at
008 *
009 *       http://www.gnu.org/licenses/lgpl.html
010 *
011 *  Unless required by applicable law or agreed to in writing, software
012 *  distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
013 *  WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
014 *  License for the specific language governing permissions and limitations
015 *  under the License.
016 */
017
018package org.tquadrat.foundation.testutil.impl;
019
020import static java.util.Collections.enumeration;
021import static java.util.Objects.isNull;
022import static org.apiguardian.api.API.Status.STABLE;
023
024import java.util.Enumeration;
025import java.util.Map;
026import java.util.ResourceBundle;
027
028import org.apiguardian.api.API;
029
030/**
031 *  A simple implementation of
032 *  {@link ResourceBundle}
033 *  for testing purposes.
034 *
035 *  @extauthor Thomas Thrien - thomas.thrien@tquadrat.org
036 *  @version $Id: ResourceBundleImpl.java 1074 2023-10-02 12:05:06Z tquadrat $
037 *  @since 0.0.1
038 */
039@API( status = STABLE, since = "0.0.1" )
040
041public class ResourceBundleImpl extends ResourceBundle
042{
043        /*------------*\
044    ====** Attributes **=======================================================
045        \*------------*/
046    /**
047     *  The values.
048     */
049    private final Map<String,Object> m_Texts;
050
051        /*--------------*\
052    ====** Constructors **=====================================================
053        \*--------------*/
054    /**
055     *  Creates a new {@code ResourceBundleImpl} instance.
056     *
057     *  @param  texts   The texts.
058     */
059    public ResourceBundleImpl( final Map<String,Object> texts )
060    {
061        m_Texts = isNull( texts ) ? Map.of() : texts;
062    }   //  ResourceBundleImpl()
063
064        /*---------*\
065    ====** Methods **==========================================================
066        \*---------*/
067    /**
068     *  {@inheritDoc}
069     */
070    @Override
071    protected final Object handleGetObject( final String key )
072    {
073        return m_Texts.get( key );
074    }   //  handleGetObject()
075
076    /**
077     *  {@inheritDoc}
078     */
079    @Override
080    public Enumeration<String> getKeys()
081    {
082        final var retValue = enumeration( m_Texts.keySet() );
083
084        //---* Done *----------------------------------------------------------
085        return retValue;
086    }   //  getKeys()
087}
088//  class ResourceBundleImpl
089
090/*
091 *  End of File
092 */