private Object getValue ( String key ) { // iterate over configuration tree String [ ] splittedKeys = key . split ( "\\." ) ; Object value = config ; for ( int i = 0 ; i < splittedKeys . length ; i ++ ) { String splittedKey = splittedKeys [ i ] ; if ( value == null ) { return null ; } // parse arrays if ( representsArray ( splittedKey ) ) { // value array support int arrayIndex ; int openingBracket = splittedKey . indexOf ( "[" ) ; int closingBracket = splittedKey . indexOf ( "]" ) ; try { arrayIndex = Integer . parseInt ( splittedKey . substring ( openingBracket + 1 , closingBracket ) ) ; } catch ( NumberFormatException e ) { if ( log != null ) { log . severe ( "Cannot cast array index." ) ; } return null ; } splittedKey = splittedKey . substring ( 0 , openingBracket ) ; if ( value instanceof Map ) { value = ( ( Map ) value ) . get ( splittedKey ) ; } else { return null ; } if ( value instanceof List ) { value = ( arrayIndex < ( ( List ) value ) . size ( ) ) ? ( ( List ) value ) . get ( arrayIndex ) : null ; } } else { if ( value instanceof Map ) { Object tmpValue = ( ( Map ) value ) . get ( splittedKey ) ; if ( tmpValue == null && i != splittedKeys . length - 1 ) { String postfixKey = Arrays . stream ( splittedKeys ) . skip ( i ) . collect ( Collectors . joining ( "." ) ) ; return ( ( Map ) value ) . get ( postfixKey ) ; } else { value = tmpValue ; } } else { return null ; } } } return value ; }
Parses configuration map returns value for given key .