001/* 002 * SPDX-FileCopyrightText: none 003 * SPDX-License-Identifier: CC0-1.0 004 */ 005 006package dev.metaschema.core.configuration; 007 008import java.util.Map; 009 010import edu.umd.cs.findbugs.annotations.NonNull; 011 012/** 013 * The base interface for getting the configuration of processors and parsers in 014 * this library. This provides an immutable view of the current configuration. 015 * 016 * @param <T> 017 * the type of the feature set 018 */ 019public interface IConfiguration<T extends IConfigurationFeature<?>> { 020 /** 021 * Determines if a specific feature is enabled. 022 * 023 * @param feature 024 * the feature to check for 025 * @return {@code true} if the feature is enabled, or {@code false} otherwise 026 * @throws UnsupportedOperationException 027 * if the feature is not a boolean valued feature 028 * @see IConfigurationFeature#getValueClass() 029 */ 030 boolean isFeatureEnabled(@NonNull T feature); 031 032 /** 033 * Get the configuration value of the provided {@code feature}. 034 * 035 * @param <V> 036 * the value type 037 * @param feature 038 * the requested feature 039 * @return the value of the feature 040 */ 041 @SuppressWarnings("unchecked") 042 @NonNull 043 default <V> V get(@NonNull T feature) { 044 V value = (V) getFeatureValues().get(feature); 045 if (value == null) { 046 value = (V) feature.getDefault(); 047 } 048 return value; 049 } 050 051 /** 052 * Get the mapping of each feature mapped to its value. 053 * 054 * @return the mapping 055 */ 056 @NonNull 057 Map<T, Object> getFeatureValues(); 058}