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;
018
019import org.spongepowered.configurate.util.CheckedConsumer;
020
021/**
022 * A standard configuration node, without any additional options.
023 *
024 * @since 4.0.0
025 */
026public interface BasicConfigurationNode extends ScopedConfigurationNode<BasicConfigurationNode> {
027
028    /**
029     * Create a new factory providing {@link BasicConfigurationNode} instances.
030     *
031     * <p>The returned factory will create nodes with default options.</p>
032     *
033     * @return a new factory
034     * @since 4.0.0
035     */
036    static ConfigurationNodeFactory<BasicConfigurationNode> factory() {
037        return BasicConfigurationNode::root;
038    }
039
040    /**
041     * Create a new empty root node.
042     *
043     * <p>This node will use the {@link ConfigurationOptions#defaults() default options}</p>
044     *
045     * <p>A root node is always attached, and has no parent and an
046     * empty path.</p>
047     *
048     * @return a new empty node
049     * @since 4.0.0
050     */
051    static BasicConfigurationNode root() {
052        return root(ConfigurationOptions.defaults());
053    }
054
055    /**
056     * Create a new root node with the provided initializer which may throw.
057     *
058     * <p>This node will use the {@link ConfigurationOptions#defaults() default options}</p>
059     *
060     * <p>A root node is always attached, and has no parent and an
061     * empty path.</p>
062     *
063     * @param <E> error type thrown
064     * @param maker action to be applied to the newly created node
065     * @return a new initialized node
066     * @throws E when thrown from inner action
067     * @since 4.0.0
068     */
069    static <E extends Exception> BasicConfigurationNode root(final CheckedConsumer<? super BasicConfigurationNode, E> maker) throws E {
070        return root().act(maker);
071    }
072
073    /**
074     * Create a new empty root node with the provided options.
075     *
076     * <p>A root node is always attached, and has no parent and an
077     * empty path.</p>
078     *
079     * @param options options to apply.
080     * @return a new empty node
081     * @since 4.0.0
082     */
083    static BasicConfigurationNode root(final ConfigurationOptions options) {
084        return new BasicConfigurationNodeImpl(null, null, options);
085    }
086
087    /**
088     * Create a new root node with the provided options and initializer.
089     *
090     * <p>A root node is always attached, and has no parent and an
091     * empty path.</p>
092     *
093     * @param <E> thrown type
094     * @param options options to apply.
095     * @param maker action to be applied to the newly created node
096     * @return a new initialized node
097     * @throws E when thrown from inner action
098     * @since 4.0.0
099     */
100    static <E extends Exception> BasicConfigurationNode root(final ConfigurationOptions options,
101            final CheckedConsumer<? super BasicConfigurationNode, E> maker) throws E {
102        return root(options).act(maker);
103    }
104
105}