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 The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/
package io.opentelemetry.sdk.extension.incubator.fileconfig;
import static java.util.stream.Collectors.joining;
import static java.util.stream.Collectors.toList;
import io.opentelemetry.sdk.autoconfigure.internal.ComponentLoader;
import io.opentelemetry.sdk.autoconfigure.spi.ConfigurationException;
import io.opentelemetry.sdk.autoconfigure.spi.internal.StructuredConfigProperties;
import io.opentelemetry.sdk.extension.incubator.fileconfig.internal.model.OpenTelemetryConfigurationModel;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.StringJoiner;
import javax.annotation.Nullable;
/**
* Implementation of {@link StructuredConfigProperties} which uses a declarative configuration model
* as a source.
*
* @see #getStructured(String) Accessing nested maps
* @see #getStructuredList(String) Accessing lists of maps
* @see FileConfiguration#toConfigProperties(Object, ComponentLoader) Converting configuration model
* to properties
*/
final class YamlStructuredConfigProperties implements StructuredConfigProperties {
/** Values are {@link #isPrimitive(Object)}, {@link List} of scalars. */
private final Map simpleEntries;
private final Map> listEntries;
private final Map mapEntries;
private final ComponentLoader componentLoader;
private YamlStructuredConfigProperties(
Map simpleEntries,
Map> listEntries,
Map mapEntries,
ComponentLoader componentLoader) {
this.simpleEntries = simpleEntries;
this.listEntries = listEntries;
this.mapEntries = mapEntries;
this.componentLoader = componentLoader;
}
/**
* Create a {@link YamlStructuredConfigProperties} from the {@code properties} map.
*
*
{@code properties} is expected to be the output of YAML parsing (i.e. with Jackson {@link
* com.fasterxml.jackson.databind.ObjectMapper}), and have values which are scalars, lists of
* scalars, lists of maps, and maps.
*
* @see FileConfiguration#toConfigProperties(OpenTelemetryConfigurationModel)
*/
@SuppressWarnings("unchecked")
static YamlStructuredConfigProperties create(
Map properties, ComponentLoader componentLoader) {
Map simpleEntries = new HashMap<>();
Map> listEntries = new HashMap<>();
Map mapEntries = new HashMap<>();
for (Map.Entry entry : properties.entrySet()) {
String key = entry.getKey();
Object value = entry.getValue();
if (isPrimitive(value) || value == null) {
simpleEntries.put(key, value);
continue;
}
if (isPrimitiveList(value)) {
simpleEntries.put(key, value);
continue;
}
if (isListOfMaps(value)) {
List list =
((List