package org.springframework.cloud.env;

import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.core.env.EnumerablePropertySource;
import org.springframework.core.env.Environment;
import org.springframework.core.env.PropertySource;
import org.springframework.core.env.PropertySources;

import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.Map;

/**
 * @author Spencer Gibb
 */
public class EnvironmentUtils {
	public static Map<String, Object> getSubProperties(Environment environment, String keyPrefix) {
		if (environment instanceof ConfigurableEnvironment) {
			ConfigurableEnvironment env = (ConfigurableEnvironment) environment;
			Map<String, Object> subProperties = new LinkedHashMap<>();
			PropertySources propertySources = env.getPropertySources();
			for (PropertySource<?> source : propertySources) {
				if (source instanceof EnumerablePropertySource) {
					for (String name : ((EnumerablePropertySource<?>) source)
							.getPropertyNames()) {
						String key = getSubKey(name, keyPrefix);
						if (key != null && !subProperties.containsKey(key)) {
							subProperties.put(key, source.getProperty(name));
						}
					}
				}
			}
			return Collections.unmodifiableMap(subProperties);
		}
		return Collections.emptyMap();
	}

	private static String getSubKey(String name, String keyPrefix) {
		if (name.startsWith(keyPrefix)) {
			return name.substring(keyPrefix.length());
		}
		return null;
	}
}

@@ -44,361 +44,231 @@
 ort 
-org.springframework.core.env.ConfigurableEnvironment;%0Aimport org.springframework.core.env.EnumerablePropertySource;%0Aimport org.springframework.core.env.Environment;%0Aimport org.springframework.core.env.PropertySource;%0Aimport org.springframework.core.env.PropertySources;%0A%0Aimport java.util.Collections;%0Aimport java.util.LinkedHashMap;%0Aimport java.util.Map
+java.util.Collections;%0Aimport java.util.Map;%0A%0Aimport org.springframework.boot.context.properties.bind.Bindable;%0Aimport org.springframework.boot.context.properties.bind.Binder;%0Aimport org.springframework.core.env.Environment
 ;%0A%0A/
@@ -357,22 +357,22 @@
 String, 
-Object
+String
 %3E getSub
@@ -406,17 +406,20 @@
 ronment,
- 
+%0A%09%09%09
 String k
@@ -436,717 +436,119 @@
 %7B%0A%09%09
-if (environment instanceof ConfigurableEnvironment) %7B%0A%09%09%09ConfigurableEnvironment env = (ConfigurableEnvironment) environment;%0A%09%09%09Map%3CString, Object%3E subProperties = new LinkedHashMap%3C%3E();%0A%09%09%09PropertySources propertySources = env.getPropertySources();%0A%09%09%09for (PropertySource%3C?%3E source : propertySources) %7B%0A%09%09%09%09if (source instanceof EnumerablePropertySource) %7B%0A%09%09%09%09%09for (String name : ((EnumerablePropertySource%3C?%3E) source)%0A%09%09%09%09%09%09%09.getPropertyNames()) %7B%0A%09%09%09%09%09%09String key = getSubKey(name, keyPrefix);%0A%09%09%09%09%09%09if (key != null && !subProperties.containsKey(key)) %7B%0A%09%09%09%09%09%09%09subProperties.put(key, source.getProperty(name
+return Binder.get(environment)%0A%09%09%09%09.bind(keyPrefix, Bindable.mapOf(String.class, String.class
 ))
-;
 %0A%09%09%09%09
-%09%09%7D%0A%09%09%09%09%09%7D%0A%09%09%09%09%7D%0A%09%09%09%7D%0A%09%09%09return Collections.unmodifiableMap(subProperties);%0A%09%09%7D%0A%09%09return 
+.orElseGet(
 Coll
@@ -558,17 +558,18 @@
 ions
-.
+::
 emptyMap
 ();%0A
@@ -568,181 +568,9 @@
 yMap
-();%0A%09%7D%0A%0A%09private static String getSubKey(String name, String keyPrefix) %7B%0A%09%09if (name.startsWith(keyPrefix)) %7B%0A%09%09%09return name.substring(keyPrefix.length());%0A%09%09%7D%0A%09%09return null
+)
 ;%0A%09%7D

Simplify EnvironmentUtils (maybe could be deleted?)