private void registerCommand ( String cmdOwner , RegisteredCommand cmd ) { // Add to owner map in RESTCatalog. Map < String , RESTCommand > nameMap = getCmdNameMap ( cmdOwner ) ; String cmdName = cmd . getName ( ) ; RESTCommand oldCmd = nameMap . put ( cmdName , cmd ) ; if ( oldCmd != null ) { throw new RuntimeException ( "Duplicate REST command with same owner/name: " + "owner=" + cmdOwner + ", name=" + cmdName + ", [1]=" + cmd + ", [2]=" + oldCmd ) ; } // Add to local evaluation map. Map < HttpMethod , SortedSet < RegisteredCommand > > evalMap = getCmdEvalMap ( cmdOwner ) ; for ( HttpMethod method : cmd . getMethods ( ) ) { SortedSet < RegisteredCommand > methodSet = evalMap . get ( method ) ; if ( methodSet == null ) { methodSet = new TreeSet <> ( ) ; evalMap . put ( method , methodSet ) ; } if ( ! methodSet . add ( cmd ) ) { throw new RuntimeException ( "Duplicate REST command: owner=" + cmdOwner + ", name=" + cmdName + ", commmand=" + cmd ) ; } } }
Register the given command and throw if is a duplicate name or command .