public String assemble ( EnumSet < Parts > parts ) { StringBuilder uri = new StringBuilder ( ) ; // Note that format and base may be same, so case it out int useformat = ( parts . contains ( Parts . FORMAT ) ? 1 : 0 ) ; int usebase = ( parts . contains ( Parts . BASE ) ? 2 : 0 ) ; switch ( useformat + usebase ) { case 0 + 0 : // neither break ; case 1 + 0 : // FORMAT only uri . append ( this . formatprotocol + ":" ) ; break ; case 2 + 0 : // BASE only uri . append ( this . baseprotocol + ":" ) ; break ; case 2 + 1 : // both uri . append ( this . formatprotocol + ":" ) ; if ( ! this . baseprotocol . equals ( this . formatprotocol ) ) uri . append ( this . formatprotocol + ":" ) ; break ; } uri . append ( this . baseprotocol . equals ( "file" ) ? "/" : "//" ) ; if ( userinfo != null && parts . contains ( Parts . PWD ) ) uri . append ( this . userinfo + ":" ) ; if ( this . host != null && parts . contains ( Parts . HOST ) ) uri . append ( this . host ) ; if ( this . path != null && parts . contains ( Parts . PATH ) ) uri . append ( this . path ) ; if ( this . query != null && parts . contains ( Parts . QUERY ) ) uri . append ( "?" + this . query ) ; if ( this . frag != null && parts . contains ( Parts . FRAG ) ) uri . append ( "#" + this . frag ) ; return uri . toString ( ) ; }
Reassemble the url using the specified parts