All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.netflix.archaius.CustomDecoder Maven / Gradle / Ivy

The newest version!
package com.netflix.archaius;

import com.netflix.archaius.api.TypeConverter;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Objects;

/**
 * A configurable {@code Decoder} implementation which allows extension through custom {@code TypeConverter.Factory}
 * instances. The custom factories are searched first, and if no appropriate converter is found, the default
 * converters used by {@code DefaultDecoder} will be consulted.
 */
public class CustomDecoder extends AbstractRegistryDecoder {
    private CustomDecoder(Collection typeConverterFactories) {
        super(typeConverterFactories);
    }

    /**
     * Create a new {@code CustomDecoder} with the supplied {@code TypeConverter.Factory} instances installed.
     * The default converter factories will still be registered, but will be installed AFTER any custom ones,
     * giving callers the opportunity to override the behavior of the default converters.
     *
     * @param customTypeConverterFactories the collection of converter factories to use for this decoder
     */
    public static CustomDecoder create(Collection customTypeConverterFactories) {
        Objects.requireNonNull(customTypeConverterFactories, "customTypeConverterFactories == null");
        List factories = new ArrayList<>(customTypeConverterFactories);
        factories.addAll(DefaultDecoder.DEFAULT_FACTORIES);
        return new CustomDecoder(factories);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy