Skip to content

Instantly share code, notes, and snippets.

@ponzao
Created March 14, 2011 19:18
Show Gist options
  • Save ponzao/869689 to your computer and use it in GitHub Desktop.
Save ponzao/869689 to your computer and use it in GitHub Desktop.
Inspired by https://gist.github.com/869408. Forking didn't seem to work :(
import scala.collection.mutable.MultiMap
import java.net.URLEncoder
import scala.collection.mutable.{Set => MSet, HashMap, MultiMap}
class LinkBuilder(path: String) {
val attributes = new HashMap[String, MSet[String]] with MultiMap[String, String]
override def toString(): String
= path +
"?" +
(attributes flatMap { case (name, values) =>
values map { name + "=" + URLEncoder.encode(_, "utf-8") }
} mkString "&")
def +(name: String, value: String): LinkBuilder = {
if (value != null) {
attributes.addBinding(name, value)
}
this
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment