001/*
002 * ============================================================================
003 *  Copyright © 2002-2026 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.jsonbuilder.internal;
019
020import static org.apiguardian.api.API.Status.INTERNAL;
021import static org.tquadrat.foundation.lang.Objects.hash;
022import static org.tquadrat.foundation.lang.Objects.requireNonNullArgument;
023import static org.tquadrat.foundation.util.StringUtils.escapeJSON;
024
025import java.util.Formatter;
026
027import org.apiguardian.api.API;
028import org.tquadrat.foundation.annotation.ClassVersion;
029import org.tquadrat.foundation.jsonbuilder.JSONNumber;
030import org.tquadrat.foundation.jsonbuilder.JSONString;
031
032/**
033 *  <p>{@summary The implementation of the interface
034 *  {@link JSONString}.}</p>
035 *
036 *  @extauthor Thomas Thrien - thomas.thrien@tquadrat.org
037 *  @version $Id: JSONStringImpl.java 1190 2026-04-08 13:27:20Z tquadrat $
038 *  @since 0.25.0
039 *
040 *  @UMLGraph.link
041 */
042@ClassVersion( sourceVersion = "$Id: JSONStringImpl.java 1190 2026-04-08 13:27:20Z tquadrat $" )
043@API( status = INTERNAL, since = "0.25.0" )
044public final class JSONStringImpl implements JSONString
045{
046        /*------------*\
047    ====** Attributes **=======================================================
048        \*------------*/
049    /**
050     *  The value.
051     */
052    private final String m_Value;
053
054        /*--------------*\
055    ====** Constructors **=====================================================
056        \*--------------*/
057    /**
058     *  Creates a new instance of {@link JSONNumber}.
059     *
060     *  @param  value   The value.
061     */
062    public JSONStringImpl( final String value )
063    {
064        m_Value = requireNonNullArgument( value, "value" );
065    }   //  JSONStringImpl()
066
067        /*---------*\
068    ====** Methods **==========================================================
069        \*---------*/
070    /**
071     *  {@inheritDoc}
072     */
073    @Override
074    public final boolean equals( final Object o )
075    {
076        var retValue = this == o;
077        if( !retValue && o instanceof final JSONStringImpl other )
078        {
079            retValue = m_Value.equals( other.m_Value );
080        }
081        //---* Done *----------------------------------------------------------
082        return retValue;
083    }   //  equals()
084
085    /**
086     * {@inheritDoc}
087     */
088    @Override
089    public final void formatTo( final Formatter formatter, final int flags, final int width, final int precision )
090    {
091        formatter.format( toString() );
092    }   //  formatTo()
093
094    /**
095     *  {@inheritDoc}
096     */
097    @Override
098    public final String getString() { return m_Value; }
099
100    /**
101     *  {@inheritDoc}
102     */
103    @Override
104    public int hashCode() { return hash( m_Value ); }
105
106    /**
107     *  {@inheritDoc}
108     */
109    @Override
110    public String toString() { return escapeJSON( m_Value ); }
111}
112//  class JSONStringImpl
113
114/*
115 *  End of File
116 */