public @ NotNull String build ( ) { SortedMap < String , Object > sortedParameterMap = new TreeMap <> ( parameterMap ) ; // gather resource paths in a treeset (having them in a defined order helps with caching) SortedSet < String > resourcePathsSet = new TreeSet <> ( ) ; // iterate over all parts that should be kept from the current request for ( String nextPart : initialSuffixParts ) { // if this is a key-value-part: if ( nextPart . indexOf ( KEY_VALUE_DELIMITER ) > 0 ) { String key = decodeKey ( nextPart ) ; // decode and keep the part if it is not overridden in the given parameter-map if ( ! sortedParameterMap . containsKey ( key ) ) { String value = decodeValue ( nextPart ) ; sortedParameterMap . put ( key , value ) ; } } else { // decode and keep the resource paths (unless they are specified again in resourcePaths) String path = decodeResourcePathPart ( nextPart ) ; if ( ! resourcePaths . contains ( path ) ) { resourcePathsSet . add ( path ) ; } } } // copy the resources specified as parameters to the sorted set of paths if ( resourcePaths != null ) { resourcePathsSet . addAll ( ImmutableList . copyOf ( resourcePaths ) ) ; } // gather all suffix parts in this list List < String > suffixParts = new ArrayList <> ( ) ; // now encode all resource paths for ( String path : resourcePathsSet ) { suffixParts . add ( encodeResourcePathPart ( path ) ) ; } // now encode all entries from the parameter map for ( Entry < String , Object > entry : sortedParameterMap . entrySet ( ) ) { Object value = entry . getValue ( ) ; if ( value == null ) { // don't add suffix part if value is null continue ; } String encodedKey = encodeKeyValuePart ( entry . getKey ( ) ) ; String encodedValue = encodeKeyValuePart ( value . toString ( ) ) ; suffixParts . add ( encodedKey + KEY_VALUE_DELIMITER + encodedValue ) ; } // finally join these parts to a single string return StringUtils . join ( suffixParts , SUFFIX_PART_DELIMITER ) ; }
Build complete suffix .