Request for comments: Bug 6306820
Alan Bateman
Alan.Bateman at Sun.COM
Sun May 20 04:32:57 PDT 2007
Richard Kennard wrote:
> :
>
> So, can we agree a regular class is better than a utility class?
That seems reasonable to me. I just suggested thinking about a utility
class given that this is mostly about manipulating a map of parameters.
Some aspects of the builder pattern are probably useful here but if I
were creating it then I would keep it very simple and probably suggest
something like this:
public class UrlQueryString {
private UrlQueryString() { }
public static UrlQueryString create()
public static UrlQueryString parse(CharSequence query)
public String get(String name)
public List<String> getAll(String name)
public UrlQueryString set(String name, String... value)
public UrlQueryString set(String name, List<String> values)
public UrlQueryString add(String name, String... value)
public UrlQueryString add(String name, List<String> values)
public UrlQueryString add(UrlQueryString other)
public UrlQueryString add(CharSequence other)
public UrlQueryString remove(String name)
public String toString()
public Map<String,List<String>> toMap()
}
This isn't too different from what you have except that the object is
created with static factory methods rather than public constructors, it
allows for method chaining, and it doesn't do the URL/URI creation. For
the latter I would suggest looking into adding static methods to
java.net.URI to allow URIs be created from various URI and component
combinations. Does that seem reasonable?
-Alan.
More information about the net-dev
mailing list