com.yelstream.topp.standard.microprofile.config.source.DynamicMapConfigSource Maven / Gradle / Ivy
/*
* Project: Topp Standard
* GitHub: https://github.com/sabroe/Topp-Standard
*
* Copyright 2024 Morten Sabroe Mortensen
*
* 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 com.yelstream.topp.standard.microprofile.config.source;
import com.yelstream.topp.standard.util.MapBuilders;
import com.yelstream.topp.standard.util.function.MemoizedIntSupplier;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Singular;
import org.eclipse.microprofile.config.spi.ConfigSource;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.IntSupplier;
import java.util.function.Supplier;
/**
* In-memory configuration-source keeping properties as a {@link Map}.
*
* Actual properties may be handed over at the time of instantiation and
* otherwise created, read, updated or removed during runtime.
*
*
* This may support properties whose value is {@code null} depending upon construction.
*
*
* This may be immutable depending upon construction.
*
*
* This may be thread-safe depending upon construction.
*
*
* @author Morten Sabroe Mortensen
* @version 1.0
* @since 2024-04-15
*/
@AllArgsConstructor(staticName="of",access=AccessLevel.PRIVATE)
public class DynamicMapConfigSource implements ConfigSource {
/**
* Name.
*/
private final Supplier nameSupplier;
/**
* Ordinal.
*
* Note: If the values from this varies at runtime then the configuration-source possibly will not work.
*
*/
private final IntSupplier ordinalSupplier;
/**
* Properties held.
*/
private final AtomicReference