Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Copyright 2024 https://dejvokep.dev/
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package dev.dejvokep.boostedyaml.updater.operators;
import dev.dejvokep.boostedyaml.YamlDocument;
import dev.dejvokep.boostedyaml.block.Block;
import dev.dejvokep.boostedyaml.block.implementation.TerminatedBlock;
import dev.dejvokep.boostedyaml.block.implementation.Section;
import dev.dejvokep.boostedyaml.engine.ExtendedConstructor;
import dev.dejvokep.boostedyaml.engine.ExtendedRepresenter;
import dev.dejvokep.boostedyaml.route.Route;
import dev.dejvokep.boostedyaml.settings.general.GeneralSettings;
import dev.dejvokep.boostedyaml.settings.updater.MergeRule;
import dev.dejvokep.boostedyaml.settings.updater.UpdaterSettings;
import org.jetbrains.annotations.NotNull;
import org.snakeyaml.engine.v2.common.ScalarStyle;
import org.snakeyaml.engine.v2.nodes.MappingNode;
import org.snakeyaml.engine.v2.nodes.Node;
import org.snakeyaml.engine.v2.nodes.ScalarNode;
import org.snakeyaml.engine.v2.nodes.Tag;
import org.snakeyaml.engine.v2.representer.BaseRepresenter;
import java.util.*;
import java.util.function.Supplier;
/**
* Merger is the last of the updating process operators, responsible for merging the document with the defaults.
*/
public class Merger {
/**
* Instance for calling non-static methods.
*/
private static final Merger INSTANCE = new Merger();
/**
* Merges the given document with the defaults.
*
* Merging algorithm consists of iterating through blocks in the defaults and for each pair (document+default block)
* outputs the preserved one (according to the merging rules) into the document. If the block is ignored,
* immediately continues without changing the block. If the preserved block is the default one, deep copies it (so
* it is isolated from the defaults). If both blocks represent sections, iterates through these pair of
* subsections.
*
* Additionally, after iteration had finished, deletes all non-merged blocks (those which are not contained in the
* defaults) from the document, unless {@link UpdaterSettings#isKeepAll()} is enabled.
*
* @param document the document
* @param defaults the default equivalent to the document
* @param settings updater settings to use
* @see #iterate(Section, Section, UpdaterSettings)
*/
public static void merge(@NotNull Section document, @NotNull Section defaults, @NotNull UpdaterSettings settings) {
INSTANCE.iterate(document, defaults, settings);
}
/**
* Merges the given document with the defaults.
*
* Merging algorithm consists of iterating through blocks in the defaults and for each pair (document+default block)
* outputs the preserved one (according to the merging rules) into the document. If the block is ignored,
* immediately continues without changing the block. If the preserved block is the default one, deep copies it (so
* it is isolated from the defaults). If both blocks represent sections, iterates through these pair of
* subsections.
*
* Additionally, after iteration had finished, deletes all non-merged blocks (those which are not contained in the
* defaults) from the document, unless {@link UpdaterSettings#isKeepAll()} is enabled.
*
* @param document the document
* @param defaults the default equivalent to the document
* @param settings updater settings to use
*/
private void iterate(Section document, Section defaults, UpdaterSettings settings) {
//Keys
Set