Config implements Serializable, Comparable<Config<?>> { public OptionalValueParser getIfValueDefined(Enum<?> key) { return new OptionalValueParser(getString(key), timeUnit, lengthUnit); } private  Config(
            Class<E> cls,
            ImmutableMap<E, ConfigValue> values,
            ImmutableMap<?, Config<?>> subConfig,
            String qualifier,
            TimeUnit timeUnit,
            LengthUnit lengthUnit);   Config(
            Class<E> cls,
            ImmutableMap<E, ConfigValue> values,
            ImmutableMap<?, Config<?>> subConfig,
            String qualifier); Config<E> getPrefixedConfigItems(String prefix); Config<E> getPrefixBiasedConfigItems(String prefix); ImmutableSet<String> getPrefixes(); ImmutableMap<E, ConfigValue> getValues(); static Config<T> empty(Class<T> c); TimeUnit getTimeUnit(); LengthUnit getLengthUnit(); @Deprecated boolean containsKey(Enum<?> key); boolean isValueDefined(Enum<?> key); boolean areKeyAndValueDefined(Enum<?> key); boolean enumTypeMatches(Class<? extends Enum> enumClazz); boolean enumTypeIncludes(Enum<?> key); @SuppressWarnings("unchecked") Config<T> getSubConfig(Class<T> key); StrictValueParser getValue(Enum<?> key); OptionalValueParser getIfValueDefined(Enum<?> key); OptionalValueParser getIfKeyAndValueDefined(Enum<?> key); @Deprecated int getInt(Enum<?> key); @Deprecated int getIntOrDefault(Enum<?> key, int defaultValue); @Deprecated OptionalInt getIntIfPresent(Enum<?> key); @Deprecated Optional<Double> getDoubleIfPresent(Enum<?> key); @Deprecated double getDouble(Enum<?> key); @Deprecated double getDoubleOrDefault(Enum<?> key, double defaultValue); @Deprecated boolean getBoolean(Enum<?> key); @Deprecated boolean getBooleanOrDefault(Enum<?> key, boolean defaultValue); @Deprecated long getLong(Enum<?> key); @Deprecated long getLongOrDefault(Enum<?> key, long defaultValue); @Deprecated OptionalLong getLongIfPresent(Enum<?> key); @Deprecated double getLength(Enum<?> key); @Deprecated double getLengthOrDefault(Enum<?> key, double defaultValue); @Deprecated double getFractionalTime(Enum<?> key); @Deprecated double getFractionalTimeOrDefault(Enum<?> key, double defaultValue); @Deprecated Optional<Double> getFractionalTimeIfPresent(Enum<?> key); @Deprecated long getTime(Enum<?> key); @Deprecated long getTimeOrDefault(Enum<?> key, long defaultValue); @Deprecated Optional<Long> getTimeIfPresent(Enum<?> key); @Deprecated Duration getDuration(Enum<?> key); @Deprecated Duration getDurationOrDefault(Enum<?> key, Duration defaultValue); @Deprecated Optional<Duration> getDurationIfPresent(Enum<?> key); @Deprecated double getSpeed(Enum<?> key); @Deprecated double getSpeedOrDefault(Enum<?> key, double defaultValue); @Deprecated double getAcceleration(Enum<?> key); @Deprecated double getAccelerationOrDefault(Enum<?> key, double defaultValue); @Deprecated ImmutableList<T> getListOf(Enum<?> key, Function<String, T> valueFunction); @Deprecated ImmutableList<T> getListOfOrEmpty(Enum<?> key, Function<String, T> valueFunction); @Deprecated ImmutableList<T> getListOfOrDefault(Enum<?> key, Function<String, T> valueFunction, ImmutableList<T> defaultValue); @Deprecated ImmutableSet<T> getSetOf(Enum<?> key, Function<String, T> valueFunction); @Deprecated ImmutableSet<T> getSetOfOrEmpty(Enum<?> key, Function<String, T> valueFunction); @Deprecated ImmutableSet<T> getSetOfOrDefault(Enum<?> key, Function<String, T> valueFunction, ImmutableSet<T> defaultValue); @Deprecated ImmutableList<Integer> getListOfIntegers(Enum<?> key); @Deprecated ImmutableList<Integer> getListOfIntegersOrEmpty(Enum<?> key); @Deprecated ImmutableList<Integer> getListOfIntegersOrDefault(Enum<?> key, ImmutableList<Integer> defaultValue); @Deprecated ImmutableSet<Integer> getSetOfIntegers(Enum<?> key); @Deprecated ImmutableSet<Integer> getSetOfIntegersOrEmpty(Enum<?> key); @Deprecated ImmutableSet<Integer> getSetOfIntegersOrDefault(Enum<?> key, ImmutableSet<Integer> defaultValue); @Deprecated ImmutableList<Long> getListOfLongs(Enum<?> key); @Deprecated ImmutableList<Long> getListOfLongsOrEmpty(Enum<?> key); @Deprecated ImmutableList<Long> getListOfLongsOrDefault(Enum<?> key, ImmutableList<Long> defaultValue); @Deprecated ImmutableSet<Long> getSetOfLongs(Enum<?> key); @Deprecated ImmutableSet<Long> getSetOfLongsOrEmpty(Enum<?> key); @Deprecated ImmutableSet<Long> getSetOfLongsOrDefault(Enum<?> key, ImmutableSet<Long> defaultValue); @Deprecated ImmutableList<Double> getListOfDoubles(Enum<?> key); @Deprecated ImmutableList<Double> getListOfDoublesOrEmpty(Enum<?> key); @Deprecated ImmutableList<Double> getListOfDoublesOrDefault(Enum<?> key, ImmutableList<Double> defaultValue); @Deprecated ImmutableSet<Double> getSetOfDoubles(Enum<?> key); @Deprecated ImmutableSet<Double> getSetOfDoublesOrEmpty(Enum<?> key); @Deprecated ImmutableSet<Double> getSetOfDoublesOrDefault(Enum<?> key, ImmutableSet<Double> defaultValue); @Deprecated ImmutableList<Id<T>> getListOfIdsIfPresent(Enum<?> key); @Deprecated ImmutableList<Id<T>> getListOfIds(Enum<?> key); @Deprecated ImmutableList<Id<T>> getListOfIdsOrEmpty(Enum<?> key); @Deprecated ImmutableList<Id<T>> getListOfIdsOrDefault(Enum<?> key, ImmutableList<Id<T>> defaultValue); @Deprecated ImmutableSet<Id<T>> getSetOfIdsIfPresent(Enum<?> key); @Deprecated ImmutableSet<Id<T>> getSetOfIds(Enum<?> key); @Deprecated ImmutableSet<Id<T>> getSetOfIdsOrEmpty(Enum<?> key); @Deprecated ImmutableSet<Id<T>> getSetOfIdsOrDefault(Enum<?> key, ImmutableSet<Id<T>> defaultValue); @Deprecated ImmutableSet<T> getSetOfEnums(Enum<?> key, Class<T> enumClass); @Deprecated ImmutableSet<T> getSetOfEnumsOrEmpty(Enum<?> key, Class<T> enumClass); @Deprecated ImmutableSet<T> getSetOfEnumsOrDefault(Enum<?> key, Class<T> enumClass, ImmutableSet<T> defaultValue); @Deprecated ImmutableList<T> getListOfEnums(Enum<?> key, Class<T> enumClass); @Deprecated ImmutableList<T> getListOfEnumsOrEmpty(Enum<?> key, Class<T> enumClass); @Deprecated ImmutableList<T> getListOfEnumsOrDefault(Enum<?> key, Class<T> enumClass, ImmutableList<T> defaultValue); @Deprecated ImmutableList<String> getListOfStrings(Enum<?> key); @Deprecated ImmutableList<String> getListOfStringsOrEmpty(Enum<?> key); @Deprecated ImmutableList<String> getListOfStringsOrDefault(Enum<?> key, ImmutableList<String> defaultValue); @Deprecated ImmutableSet<String> getSetOfStrings(Enum<?> key); @Deprecated ImmutableSet<String> getSetOfStringsOrEmpty(Enum<?> key); @Deprecated ImmutableSet<String> getSetOfStringsOrDefault(Enum<?> key, ImmutableSet<String> defaultValue); @Deprecated ImmutableList<StringId<T>> getListOfStringIdsIfPresent(Enum<?> key); @Deprecated ImmutableList<StringId<T>> getListOfStringIds(Enum<?> key); @Deprecated ImmutableList<StringId<T>> getListOfStringIdsOrEmpty(Enum<?> key); @Deprecated ImmutableList<StringId<T>> getListOfStringIdsOrDefault(Enum<?> key, ImmutableList<StringId<T>> defaultValue); @Deprecated ImmutableSet<StringId<T>> getSetOfStringIdsIfPresent(Enum<?> key); @Deprecated ImmutableSet<StringId<T>> getSetOfStringIds(Enum<?> key); @Deprecated ImmutableSet<StringId<T>> getSetOfStringIdsOrEmpty(Enum<?> key); @Deprecated ImmutableSet<StringId<T>> getSetOfStringIdsOrDefault(Enum<?> key, ImmutableSet<StringId<T>> defaultValue); @Deprecated String getString(Enum<?> key); @Deprecated String getStringOrDefault(Enum<?> key, String defaultValue); @Deprecated V get(Enum<?> key, Function<String, V> valueFunction); @Deprecated V getOrDefault(Enum<?> key, Function<String, V> valueExtractor, V defaultValue); @Deprecated Optional<String> getStringIfPresent(Enum<?> key); @Deprecated ImmutableMap<String, String> getStringMap(Enum<?> key); @Deprecated ImmutableMap<String, String> getStringMapOrEmpty(Enum<?> key); @Deprecated ImmutableMap<String, String> getStringMapOrDefault(Enum<?> key, ImmutableMap<String, String> defaultValue); @Deprecated ImmutableMap<K, V> getMap(Enum<?> configKey, Function<String, K> keyParser, Function<String, V> valueParser); @Deprecated ImmutableMap<K, V> getMapOrEmpty(Enum<?> configKey, Function<String, K> keyParser, Function<String, V> valueParser); @Deprecated ImmutableMap<K, V> getMapOrDefault(Enum<?> configKey, Function<String, K> keyParser, Function<String, V> valueParser, ImmutableMap<K, V> defaultValue); @Deprecated ImmutableSetMultimap<String, String> getStringSetMultimap(Enum<?> configKey); @Deprecated ImmutableSetMultimap<String, String> getStringSetMultimapOrEmpty(Enum<?> configKey); @Deprecated ImmutableSetMultimap<String, String> getStringSetMultimapOrDefault(
            Enum<?> configKey,
            ImmutableSetMultimap<String, String> defaultValue); @Deprecated ImmutableSetMultimap<K, V> getSetMultimapOrEmpty(
            Enum<?> configKey,
            Function<String, K> keyParser,
            Function<String, V> valueParser); @Deprecated ImmutableSetMultimap<K, V> getSetMultimapOrDefault(
            Enum<?> configKey,
            Function<String, K> keyParser,
            Function<String, V> valueParser,
            ImmutableSetMultimap<K, V> defaultValue); @Deprecated ImmutableSetMultimap<K, V> getSetMultimap(
            Enum<?> configKey,
            Function<String, K> keyParser,
            Function<String, V> valueParser); @Deprecated T getEnum(Enum<?> key, Class<T> enumClass); @Deprecated T getEnumOrDefault(Enum<?> key, Class<T> enumClass, T defaultValue); @Deprecated Optional<T> getEnumIfPresent(Enum<?> key, Class<T> enumClass); String getQualifiedKeyName(E key); @Deprecated ImmutableMap<String, String> getKeyValueStringMap(); ImmutableMap<String, String> getKeyValueStringMapWithoutSecrets(); ImmutableMap<String, String> getKeyValueStringMapWithPrefixesWithoutSecrets(); @Deprecated ImmutableMap<String, String> getUnqualifiedKeyValueStringMap(Class<T> key); ImmutableMap<String, String> getUnqualifiedKeyValueStringMapWithoutSecrets(Class<T> key); @Override int compareTo(Config<?> o); @Override boolean equals(Object o); @Override int hashCode(); @Override String toString(); final Class<E> cls; }
@Test void getIfValueDefined_whenKeyHasEmptyStringValue_thenReturnsParserWithoutValue() { String testValue = ""; Config<TestConfig> config = SimpleConfigBuilder.create(TestConfig.class) .put(TestConfig.FOO, testValue) .buildWrapped(); assertThat(config.getIfValueDefined(TestConfig.FOO).asString().isPresent()).isFalse(); }
@Test void getIfValueDefined_whenKeyNotDefined_thenThrowsException() { Config<TestConfig> config = SimpleConfigBuilder.create(TestConfig.class).buildWrapped(); assertThatThrownBy(() -> config.getIfValueDefined(TestConfig.FOO)).isInstanceOf(ConfigKeyNotFoundException.class); }