Skip to content

Instantly share code, notes, and snippets.

@alextp
Created January 26, 2013 19:46
Show Gist options
  • Select an option

  • Save alextp/4644129 to your computer and use it in GitHub Desktop.

Select an option

Save alextp/4644129 to your computer and use it in GitHub Desktop.

Revisions

  1. alextp created this gist Jan 26, 2013.
    14 changes: 14 additions & 0 deletions Serialize.scala
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,14 @@
    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
    })
    }