001/*
002 * ============================================================================
003 *  Copyright © 2002-2021 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.config.cli;
019
020import static org.apiguardian.api.API.Status.INTERNAL;
021
022import java.time.LocalDate;
023import java.util.Optional;
024import java.util.function.BiConsumer;
025
026import org.apiguardian.api.API;
027import org.tquadrat.foundation.annotation.ClassVersion;
028import org.tquadrat.foundation.config.spi.CLIDefinition;
029import org.tquadrat.foundation.util.stringconverter.LocalDateStringConverter;
030import org.tquadrat.foundation.util.stringconverter.TimeDateStringConverter;
031
032/**
033 *  The implementation of
034 *  {@link TimeValueHandler}
035 *  for {@code java.time.LocalDate}.
036 *
037 *  @extauthor Thomas Thrien - thomas.thrien@tquadrat.org
038 *  @version $Id: LocalDateValueHandler.java 896 2021-04-05 20:25:33Z tquadrat $
039 *  @since 0.0.1
040 *
041 *  @UMLGraph.link
042 */
043@ClassVersion( sourceVersion = "$Id: LocalDateValueHandler.java 896 2021-04-05 20:25:33Z tquadrat $" )
044@API( status = INTERNAL, since = "0.0.1" )
045public final class LocalDateValueHandler extends TimeValueHandler<LocalDate>
046{
047        /*--------------*\
048    ====** Constructors **=====================================================
049        \*--------------*/
050    /**
051     *  Creates a new {@code LocalDateValueHandler} instance.
052     *
053     *  @param  context The CLI definition that provides the context for this
054     *      value handler.
055     *  @param  valueSetter The
056     *      {@link BiConsumer Consumer}
057     *      that places the translated value to the property.
058     */
059    public LocalDateValueHandler( final CLIDefinition context, final BiConsumer<String,LocalDate> valueSetter )
060    {
061        super( context, valueSetter, LocalDateStringConverter.INSTANCE );
062    }   //  LocalDateValueHandler()
063
064    /**
065     *  Creates a new {@code LocalDateValueHandler} instance.
066     *
067     *  @param  valueSetter The
068     *      {@link BiConsumer Consumer}
069     *      that places the translated value to the property.
070     */
071    public LocalDateValueHandler( final BiConsumer<String,LocalDate> valueSetter )
072    {
073        super( valueSetter, LocalDateStringConverter.INSTANCE );
074    }   //  LocalDateValueHandler()
075
076        /*---------*\
077    ====** Methods **==========================================================
078        \*---------*/
079    /**
080     *  {@inheritDoc}
081     */
082    @Override
083    protected final Optional<TimeDateStringConverter<LocalDate>> createCustomStringConverter()
084    {
085        final Optional<TimeDateStringConverter<LocalDate>> retValue = getFormatter().map( LocalDateStringConverter::new );
086
087        //---* Done *----------------------------------------------------------
088        return retValue;
089    }   //  createCustomerConverter()
090
091    /**
092     *  {@inheritDoc}
093     */
094    @Override
095    protected final LocalDate getNow() { return LocalDate.now(); }
096}
097//  class LocalDateValueHandler
098
099/*
100 *  End of File
101 */