class ResourceDescriptionTemplateProcessor implements Function<AddressTemplate, AddressTemplate> {

    @Override
    public AddressTemplate apply(AddressTemplate template) {
        AddressTemplate modified = AddressTemplate.ROOT;

        if (template != null && !AddressTemplate.ROOT.equals(template)) {
            List<String[]> segments = stream(template.spliterator(), false)
                    .map(segment -> {
                        if (segment.contains("=")) {
                            return Splitter.on('=')
                                    .omitEmptyStrings()
                                    .trimResults()
                                    .limit(2)
                                    .splitToList(segment)
                                    .toArray(new String[2]);
                        }
                        return new String[]{segment, null};
                    })
                    .collect(toList());

            StringBuilder builder = new StringBuilder();
            SegmentProcessor.process(segments, segment -> {
                builder.append("/").append(segment[0]);
                if (segment[1] != null) {
                    builder.append("=").append(segment[1]);
                }
            });
            modified = AddressTemplate.of(builder.toString());
        }

        return modified;
    }

}