private static Map < String , Object > extractPropertiesForBranch ( Properties properties , String prefix , String branchSuffix ) { Map < String , Object > ret = new HashMap <> ( ) ; for ( Map . Entry < Object , Object > prop : properties . entrySet ( ) ) { String key = ( String ) prop . getKey ( ) ; if ( key . startsWith ( prefix ) && ( branchSuffix . length ( ) == 0 || key . endsWith ( branchSuffix ) ) ) { int strippedKeyStart = Math . min ( key . length ( ) , prefix . length ( ) + 1 ) ; // filter out subkeys that don't have a '.' -- eg writer.encrypted.foo shouldn't be returned // if prefix is writer.encrypt if ( strippedKeyStart != key . length ( ) && key . charAt ( strippedKeyStart - 1 ) != ' ' ) { continue ; } int strippedKeyEnd = Math . max ( strippedKeyStart , key . length ( ) - branchSuffix . length ( ) ) ; String strippedKey = key . substring ( strippedKeyStart , strippedKeyEnd ) ; ret . put ( strippedKey , prop . getValue ( ) ) ; } } return ret ; }
Extract a set of properties for a given branch stripping out the prefix and branch suffix .