001/* 002 * Copyright 2012-2018 the original author or authors. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 017package org.springframework.boot.context.properties.source; 018 019import java.util.Iterator; 020import java.util.function.Predicate; 021import java.util.stream.Stream; 022 023import org.springframework.boot.origin.OriginTrackedValue; 024 025/** 026 * A {@link ConfigurationPropertySource} with a fully {@link Iterable} set of entries. 027 * Implementations of this interface <strong>must</strong> be able to iterate over all 028 * contained configuration properties. Any {@code non-null} result from 029 * {@link #getConfigurationProperty(ConfigurationPropertyName)} must also have an 030 * equivalent entry in the {@link #iterator() iterator}. 031 * 032 * @author Phillip Webb 033 * @author Madhura Bhave 034 * @since 2.0.0 035 * @see ConfigurationPropertyName 036 * @see OriginTrackedValue 037 * @see #getConfigurationProperty(ConfigurationPropertyName) 038 * @see #iterator() 039 * @see #stream() 040 */ 041public interface IterableConfigurationPropertySource 042 extends ConfigurationPropertySource, Iterable<ConfigurationPropertyName> { 043 044 /** 045 * Return an iterator for the {@link ConfigurationPropertyName names} managed by this 046 * source. 047 * @return an iterator (never {@code null}) 048 */ 049 @Override 050 default Iterator<ConfigurationPropertyName> iterator() { 051 return stream().iterator(); 052 } 053 054 /** 055 * Returns a sequential {@code Stream} for the {@link ConfigurationPropertyName names} 056 * managed by this source. 057 * @return a stream of names (never {@code null}) 058 */ 059 Stream<ConfigurationPropertyName> stream(); 060 061 @Override 062 default ConfigurationPropertyState containsDescendantOf( 063 ConfigurationPropertyName name) { 064 return ConfigurationPropertyState.search(this, name::isAncestorOf); 065 } 066 067 @Override 068 default IterableConfigurationPropertySource filter( 069 Predicate<ConfigurationPropertyName> filter) { 070 return new FilteredIterableConfigurationPropertiesSource(this, filter); 071 } 072 073 @Override 074 default IterableConfigurationPropertySource withAliases( 075 ConfigurationPropertyNameAliases aliases) { 076 return new AliasedIterableConfigurationPropertySource(this, aliases); 077 } 078 079}