Skip to content

Instantly share code, notes, and snippets.

@alextp
Created January 26, 2013 19:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alextp/4644129 to your computer and use it in GitHub Desktop.
Save alextp/4644129 to your computer and use it in GitHub Desktop.
class StringMapCubbie[T](val m: mutable.Map[String,T]) extends Cubbie {
setMap(new mutable.Map[String, Any] {
override def update(key: String, value: Any): Unit = {
value match {
case v: T => m(key) = v
case _ => throw new InvalidClassException(value.getClass.getName + " is not of the proper type.")
}
}
def += (kv: (String, Any)): this.type = { update(kv._1, kv._2); this }
def -= (key: String): this.type = sys.error("Can't remove slots from cubbie map!")
def get(key: String): Option[Any] = if (m.contains(key)) Some(m(key)) else None
def iterator: Iterator[(String, Any)] = m.iterator
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment