public static List < Integer > indexes ( String name , Map < String , String > data ) { logger . debug ( "get indexes for {}" , name ) ; // matches: 'prefix[index]...' Pattern keyPattern = Pattern . compile ( "^" + Pattern . quote ( name ) + "\\[(\\d+)\\].*$" ) ; return data . keySet ( ) . stream ( ) . map ( key -> { Matcher m = keyPattern . matcher ( key ) ; return m . matches ( ) ? Integer . parseInt ( m . group ( 1 ) ) : - 1 ; } ) . filter ( i -> i >= 0 ) . distinct ( ) . sorted ( ) . collect ( Collectors . toList ( ) ) ; }
Computes the available indexes for the given key in this set of data .