001/* 002 * ============================================================================ 003 * Copyright © 2002-2021 by Thomas Thrien. 004 * All Rights Reserved. 005 * ============================================================================ 006 * 007 * Licensed to the public under the agreements of the GNU Lesser General Public 008 * License, version 3.0 (the "License"). You may obtain a copy of the License at 009 * 010 * http://www.gnu.org/licenses/lgpl.html 011 * 012 * Unless required by applicable law or agreed to in writing, software 013 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 014 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 015 * License for the specific language governing permissions and limitations 016 * under the License. 017 */ 018 019package org.tquadrat.foundation.config.spi.prefs; 020 021import static org.apiguardian.api.API.Status.STABLE; 022import static org.tquadrat.foundation.lang.Objects.isNull; 023import static org.tquadrat.foundation.lang.Objects.requireNonNullArgument; 024 025import java.util.prefs.Preferences; 026 027import org.apiguardian.api.API; 028import org.tquadrat.foundation.annotation.ClassVersion; 029import org.tquadrat.foundation.config.spi.InvalidPreferenceValueException; 030import org.tquadrat.foundation.function.Getter; 031import org.tquadrat.foundation.function.Setter; 032 033/** 034 * <p>{@summary The implementation of 035 * {@link PreferenceAccessor} 036 * for {@code double}.}</p> 037 * <p>This differs from 038 * {@link DoubleAccessor} 039 * as it forces 0.0 (zero) as the default value, while the other 040 * implementation has {@code null} as the default value.</p> 041 * 042 * @extauthor Thomas Thrien - thomas.thrien@tquadrat.org 043 * @version $Id: PrimitiveDoubleAccessor.java 914 2021-05-07 21:22:12Z tquadrat $ 044 * @since 0.0.1 045 * 046 * @UMLGraph.link 047 */ 048@ClassVersion( sourceVersion = "$Id: PrimitiveDoubleAccessor.java 914 2021-05-07 21:22:12Z tquadrat $" ) 049@API( status = STABLE, since = "0.0.1" ) 050public final class PrimitiveDoubleAccessor extends PreferenceAccessor<Double> 051{ 052 /*--------------*\ 053 ====** Constructors **===================================================== 054 \*--------------*/ 055 /** 056 * Creates a new {@code PrimitiveDoubleAccessor} instance. 057 * 058 * @param propertyName The name of the property. 059 * @param getter The property getter. 060 * @param setter The property setter. 061 */ 062 public PrimitiveDoubleAccessor( final String propertyName, final Getter<Double> getter, final Setter<Double> setter ) 063 { 064 super( propertyName, getter, setter ); 065 } // DoubleAccessor() 066 067 /*---------*\ 068 ====** Methods **========================================================== 069 \*---------*/ 070 /** 071 * {@inheritDoc} 072 */ 073 @Override 074 public final void readPreference( final Preferences node ) throws InvalidPreferenceValueException 075 { 076 final var defaultValue = getter().get(); 077 setter().set( Double.valueOf( requireNonNullArgument( node, "node" ).getDouble( getPropertyName(), isNull( defaultValue ) ? 0.0 : defaultValue.doubleValue() ) ) ); 078 } // readPreference() 079 080 /** 081 * {@inheritDoc} 082 */ 083 @Override 084 public final void writePreference( final Preferences node ) 085 { 086 node.putDouble( getPropertyName(), getter().get().doubleValue() ); 087 } // writePreference() 088} 089// class PrimitiveDoubleAccessor 090 091/* 092 * End of File 093 */