public static Map < String , Properties > subProperties ( Properties prop , String regex ) { Map < String , Properties > subProperties = new HashMap <> ( ) ; Pattern pattern = Pattern . compile ( regex ) ; for ( Map . Entry < Object , Object > entry : prop . entrySet ( ) ) { Matcher m = pattern . matcher ( entry . getKey ( ) . toString ( ) ) ; if ( m . find ( ) ) { String prefix = m . group ( 1 ) ; String suffix = m . group ( 2 ) ; if ( ! subProperties . containsKey ( prefix ) ) { subProperties . put ( prefix , new Properties ( ) ) ; } subProperties . get ( prefix ) . put ( suffix , entry . getValue ( ) ) ; } } return subProperties ; }
Uses regex to parse every original property key to a prefix and a suffix . Creates sub properties that are grouped by the prefix .