Here you can find the source of extractFromPropertiesAsMap(String prefix, Properties properties)
Parameter | Description |
---|---|
prefix | prefix which specifies the part which should be extracted as map |
properties | properties to extract from |
public static Map<String, String> extractFromPropertiesAsMap(String prefix, Properties properties)
//package com.java2s; //License from project: Apache License import java.util.*; public class Main { /**/*from w w w. j a va 2 s. co m*/ * Extract part of given properties as a map. The given prefix is used to find the properties, * the rest of the property name is used as key for the map. * * @param prefix prefix which specifies the part which should be extracted as map * @param properties properties to extract from * @return the extracted map or null if no such map exists */ public static Map<String, String> extractFromPropertiesAsMap(String prefix, Properties properties) { Map<String, String> ret = new HashMap<>(); Enumeration names = properties.propertyNames(); String prefixP = prefix + "."; while (names.hasMoreElements()) { String propName = (String) names.nextElement(); if (propMatchesPrefix(prefixP, propName)) { String mapKey = propName.substring(prefixP.length()); ret.put(mapKey, properties.getProperty(propName)); } } return ret.size() > 0 ? ret : null; } private static boolean propMatchesPrefix(String prefix, String key) { return key.startsWith(prefix) && key.length() >= prefix.length(); } }