private static Map < String , String > asMap ( final Iterable < String > args ) { final Map < String , String > map = new HashMap <> ( 0 ) ; final Pattern ptn = Pattern . compile ( "--([a-z\\-]+)(=.+)?" ) ; for ( final String arg : args ) { final Matcher matcher = ptn . matcher ( arg ) ; if ( ! matcher . matches ( ) ) { throw new IllegalStateException ( String . format ( "can't parse this argument: '%s'" , arg ) ) ; } final String value = matcher . group ( 2 ) ; if ( value == null ) { map . put ( matcher . group ( 1 ) , "" ) ; } else { map . put ( matcher . group ( 1 ) , value . substring ( 1 ) ) ; } } return map ; }
Convert the provided arguments into a Map .