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 java.lang.Math.max; 022import static org.apiguardian.api.API.Status.STABLE; 023 024import java.util.HashSet; 025import java.util.Set; 026 027import org.apiguardian.api.API; 028import org.tquadrat.foundation.annotation.ClassVersion; 029import org.tquadrat.foundation.function.Getter; 030import org.tquadrat.foundation.function.Setter; 031import org.tquadrat.foundation.lang.StringConverter; 032 033/** 034 * The implementation of 035 * {@link org.tquadrat.foundation.config.spi.prefs.PreferenceAccessor} 036 * for instances of 037 * {@link Set}. 038 * 039 * @note This class requires that there is an implementation of 040 * {@code StringConverter} available for the {@code Set}'s element type. 041 * 042 * @param <T> The element type of the {@code Set}. 043 * 044 * @extauthor Thomas Thrien - thomas.thrien@tquadrat.org 045 * @version $Id: SetAccessor.java 912 2021-05-06 22:27:04Z tquadrat $ 046 * @since 0.0.1 047 * 048 * @UMLGraph.link 049 */ 050@ClassVersion( sourceVersion = "$Id: SetAccessor.java 912 2021-05-06 22:27:04Z tquadrat $" ) 051@API( status = STABLE, since = "0.0.1" ) 052public final class SetAccessor<T> extends CollectionAccessor<T,Set<T>> 053{ 054 /*--------------*\ 055 ====** Constructors **===================================================== 056 \*--------------*/ 057 /** 058 * Creates a new {@code SetAccessor} instance. 059 * 060 * @param propertyName The name of the property. 061 * @param stringConverter The implementation of 062 * {@link StringConverter} 063 * for the {@code Set} element type. 064 * @param getter The property getter. 065 * @param setter The property setter. 066 */ 067 public SetAccessor( final String propertyName, final StringConverter<T> stringConverter, final Getter<Set<T>> getter, final Setter<Set<T>> setter ) 068 { 069 super( propertyName, stringConverter, getter, setter ); 070 } // SetAccessor() 071 072 /*---------*\ 073 ====** Methods **========================================================== 074 \*---------*/ 075 /** 076 * {@inheritDoc} 077 */ 078 @Override 079 protected final Set<T> createCollection( final int size ) 080 { 081 final var initialCapacity = max( size, 16 ); 082 final var loadFactor = 0.75f; 083 final Set<T> retValue = new HashSet<>( initialCapacity, loadFactor ); 084 085 //---* Done *---------------------------------------------------------- 086 return retValue; 087 } // createCollection() 088} 089// class SetAccessor 090 091/* 092 * End of File 093 */