Created
March 14, 2011 19:18
-
-
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 :(
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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