String subCommand ( String cmd , ArgTokenizer at , String [ ] subs ) { at . allowedOptions ( "-retain" ) ; String sub = at . next ( ) ; if ( sub == null ) { // No sub-command was given return at . hasOption ( "-retain" ) ? "_retain" : "_blank" ; } String [ ] matches = Arrays . stream ( subs ) . filter ( s -> s . startsWith ( sub ) ) . toArray ( String [ ] :: new ) ; if ( matches . length == 0 ) { // There are no matching sub-commands errormsg ( "jshell.err.arg" , cmd , sub ) ; fluffmsg ( "jshell.msg.use.one.of" , Arrays . stream ( subs ) . collect ( Collectors . joining ( ", " ) ) ) ; return null ; } if ( matches . length > 1 ) { // More than one sub-command matches the initial characters provided errormsg ( "jshell.err.sub.ambiguous" , cmd , sub ) ; fluffmsg ( "jshell.msg.use.one.of" , Arrays . stream ( matches ) . collect ( Collectors . joining ( ", " ) ) ) ; return null ; } return matches [ 0 ] ; }
Return null on error