/** Gets the query string, with initial "?", or null. * http://www.w3.org/TR/url/#dom-urlutils-search * ?key=value&key=value */ public String getSearch(){ if(query==null || query.empty())return ""; return "?" + query.toString(); }
/** Matches equals(), does not take order into account. */ @Override public int hashCode(){ URLParameters ps=sort(); String s=ps.toString(); return s.hashCode(); }
/** Deep clone. */ public URLParameters clone(){ String s=toString(); return new URLParameters(s); }
/** URLParameters objects are equal if the have the same keys and values. * The order is not relevant. * This is the same as in http. */ @Override public boolean equals(Object o){ if(o==null)return false; if(this==o)return true; if(!(o instanceof URLParameters))return false; URLParameters ps=(URLParameters)o; URLParameters a=sort();//can I avoid this? URLParameters b=ps.sort(); String as=a.toString();//can I avoid this? String bs=b.toString(); return as.equals(bs); }