001/*
002 * Configurate
003 * Copyright (C) zml and Configurate contributors
004 *
005 * Licensed under the Apache License, Version 2.0 (the "License");
006 * you may not use this file except in compliance with the License.
007 * You may obtain a copy of the License at
008 *
009 *    http://www.apache.org/licenses/LICENSE-2.0
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,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017package org.spongepowered.configurate.interfaces;
018
019import org.spongepowered.configurate.ConfigurationOptions;
020import org.spongepowered.configurate.serialize.TypeSerializerCollection;
021
022import java.util.function.UnaryOperator;
023
024/**
025 * This class has the default {@link ConfigurationOptions}
026 * with {@link InterfaceTypeSerializer} added to the serializers.
027 *
028 * @since 4.2.0
029 */
030public final class InterfaceDefaultOptions {
031
032    private static final ConfigurationOptions DEFAULTS =
033        ConfigurationOptions.defaults()
034            .serializers(
035                TypeSerializerCollection.builder()
036                    .registerAnnotated(InterfaceTypeSerializer::applicable, InterfaceTypeSerializer.INSTANCE)
037                    .registerAnnotatedObjects(InterfaceMiddleware.buildObjectMapperWithMiddleware())
038                    .registerAll(TypeSerializerCollection.defaults())
039                    .build()
040            );
041
042    private InterfaceDefaultOptions() {
043    }
044
045    /**
046     * The default ConfigurationOptions with {@link InterfaceTypeSerializer} added to the serializers.
047     *
048     * @return the default ConfigurationOptions with {@link InterfaceTypeSerializer} added to the serializers.
049     * @since 4.2.0
050     */
051    public static ConfigurationOptions get() {
052        return DEFAULTS;
053    }
054
055    /**
056     * Sets the default configuration options to be used by the resultant loader
057     * by providing a function which takes the current {@link #get() default options}
058     * and applies any desired changes.
059     *
060     * @param options to transform the existing default options
061     * @return the default options with the applied changes
062     * @since 4.2.0
063     */
064    public static ConfigurationOptions with(final UnaryOperator<ConfigurationOptions> options) {
065        return options.apply(DEFAULTS);
066    }
067
068}