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.value;
019
020import static org.apiguardian.api.API.Status.STABLE;
021
022import java.io.Serial;
023import java.math.BigDecimal;
024import java.util.function.BiPredicate;
025
026import org.apiguardian.api.API;
027import org.tquadrat.foundation.annotation.ClassVersion;
028import org.tquadrat.foundation.value.api.ValueBase;
029
030/**
031 *  A value class for temperatures.
032 *
033 *  @extauthor Thomas Thrien - thomas.thrien@tquadrat.org
034 *  @version $Id: TemperatureValue.java 1072 2023-09-30 20:44:38Z tquadrat $
035 *  @since 0.1.0
036 *
037 *  @UMLGraph.link
038 */
039@ClassVersion( sourceVersion = "$Id: TemperatureValue.java 1072 2023-09-30 20:44:38Z tquadrat $" )
040@API( status = STABLE, since = "0.1.0" )
041public final class TemperatureValue extends ValueBase<Temperature, TemperatureValue>
042{
043        /*-----------*\
044    ====** Constants **========================================================
045        \*-----------*/
046    /**
047     *  <p>{@summary The validator for temperatures.}</p>
048     *  A temperature in Kelvin may not be less than 0.
049     */
050    private static final BiPredicate<Temperature, BigDecimal> TEMPERATURE_VALIDATOR = ( unit, value) -> !(value.signum() < 0);
051
052        /*------------------------*\
053    ====** Static Initialisations **===========================================
054        \*------------------------*/
055    /**
056     *  The serial version UID for objects of this class: {@value}.
057     *
058     *  @hidden
059     */
060    @Serial
061    private static final long serialVersionUID = 1729884766468723788L;
062
063        /*--------------*\
064    ====** Constructors **=====================================================
065        \*--------------*/
066    /**
067     *  Creates a new {@code TemperatureValue} instance.
068     *
069     *  @param  dimension   The dimension.
070     *  @param  value   The value.
071     */
072    public TemperatureValue( final Temperature dimension, final BigDecimal value )
073    {
074        //---* Daddy's performing the null check ... *-------------------------
075        super( dimension, value, TEMPERATURE_VALIDATOR );
076    }   //  TemperatureValue()
077
078    /**
079     *  Creates a new {@code TemperatureValue} instance.
080     *
081     *  @param  dimension   The dimension.
082     *  @param  value   The value; it must be possible to parse the given
083     *      String into a
084     *      {@link BigDecimal}.
085     *  @throws NumberFormatException   The provided value cannot be converted
086     *      into a {@code BigDecimal}.
087     */
088    public TemperatureValue( final Temperature dimension, final String value ) throws NumberFormatException
089    {
090        //---* Daddy's performing the null check ... *-------------------------
091        super( dimension, value, TEMPERATURE_VALIDATOR );
092    }   //  TemperatureValue()
093
094    /**
095     *  Creates a new {@code LengthValue} instance.
096     *
097     *  @param  <N> The type of {@code value}.
098     *  @param  dimension   The dimension.
099     *  @param  value   The value.
100     */
101    public <N extends Number> TemperatureValue( final Temperature dimension, final N value )
102    {
103        //---* Daddy's performing the null check ... *-------------------------
104        super( dimension, value, TEMPERATURE_VALIDATOR );
105    }   //  TemperatureValue()
106
107        /*---------*\
108    ====** Methods **==========================================================
109        \*---------*/
110    /**
111     *  {@inheritDoc}
112     */
113    @Override
114    public final TemperatureValue clone()
115    {
116        @SuppressWarnings( "cast" )
117        final var retValue = super.clone();
118
119        //---* Done *----------------------------------------------------------
120        return retValue;
121    }   //  clone()
122}
123//  class TemperatureValue
124
125/*
126 *  End of File
127 */