Created
July 31, 2018 18:48
-
-
Save ahoy-jon/5c011ac7603d49f347cc4ec33860eb76 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
object ToMap_byHand2 { | |
def toMap(entity: Level1CC): Map[String, Any] = new ToMap_byHandWrapper(entity) | |
class ToMap_byHandWrapper(val entity: Level1CC) extends Map[String, Any] { | |
type A = String | |
type B = Any | |
override def size = 3 | |
def get(key: String): Option[Any] = | |
key match { | |
case "id" => Some(entity.id) | |
case "sub.timestamp" => Some(entity.sub.timestamp) | |
case "sub.value" => Some(entity.sub.value) | |
case _ => None | |
} | |
def iterator = Iterator(("id", entity.id), ("sub.timestamp", entity.sub.timestamp), ("sub.value", entity.sub.value)) | |
lazy val proxyMap: Map[A, Any] = iterator.toMap | |
override def updated[B1 >: B](key: A, value: B1): Map[A, B1] = proxyMap.updated(key, value) | |
def +[B1 >: B](kv: (A, B1)): Map[A, B1] = updated(kv._1, kv._2) | |
def -(key: A): Map[A, B] = proxyMap - key | |
override def foreach[U](f: ((A, B)) => U): Unit = { | |
f(("id",entity.id)) | |
f(("sub.timestamp", entity.sub.timestamp)) | |
f(("sub.value", entity.sub.value)) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment