Created
January 27, 2013 20:35
-
-
Save alextp/4650335 to your computer and use it in GitHub Desktop.
This file contains 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
class StringMapCubbie[T](val m: mutable.Map[String,T]) extends Cubbie { | |
var akeys : Seq[String] = null | |
var avalues: Seq[T] = null | |
setMap(new mutable.Map[String, Any] { | |
override def update(key: String, value: Any): Unit = { | |
if (key == "keys") { | |
akeys = value.asInstanceOf[Traversable[String]].toSeq | |
} else if (key == "values") { | |
assert(keys != null) | |
avalues = value.asInstanceOf[Traversable[T]].toSeq | |
for (i <- 0 until keys.size) { | |
m(akeys(i)) = avalues(i) | |
} | |
} | |
} | |
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 (key == "keys") Some(m.keys.toTraversable) else if (key == "values") Some(m.values.toTraversable) else None | |
def iterator: Iterator[(String, Any)] = Seq(("keys", get("keys")), ("values", get("values"))).iterator | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment