Guest User

Untitled

a guest
Sep 17th, 2019
101
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package ein.core.core
  2.  
  3.  
  4. interface ePrimitive {
  5. companion object {
  6. val EMPTY = ePrimitive("")
  7. operator fun invoke(v:String) = eString(v)
  8. operator fun invoke(v:Long) = eLong(v)
  9. operator fun invoke(v:Double) = eDouble(v)
  10. operator fun invoke(v:Boolean) = eBoolean(v)
  11. fun store(v:String) = eStore(v)
  12. fun record(v:String) = eRecord(v)
  13. fun json(v:String) = Json.parse(v)
  14. }
  15. val v:Any
  16. }
  17. class eString(override val v:String):ePrimitive
  18. class eInt(override val v:Int):ePrimitive
  19. class eLong(override val v:Long):ePrimitive
  20. class eDouble(override val v:Double):ePrimitive
  21. class eBoolean(override val v:Boolean):ePrimitive
  22. class eStore(override val v:String):ePrimitive
  23. class eRecord(override val v:String):ePrimitive
  24. class eJsonArray:MutableList<ePrimitive> by mutableListOf(), ePrimitive{
  25. override val v:MutableList<ePrimitive> = this
  26. }
  27. class eJsonObject:MutableMap<String, ePrimitive> by mutableMapOf(), ePrimitive{
  28. override val v:MutableMap<String, ePrimitive> = this
  29. operator fun invoke(key:String) = invoke(key.split("."))
  30. operator fun invoke(key:List<String>)= key.fold(this as ePrimitive){target, k->
  31. when(target){
  32. is eJsonObject->target[k]
  33. is eJsonArray->target[k.toInt()]
  34. else->null
  35. } ?: throw Throwable("invalid key:$k")
  36. }
  37. }
RAW Paste Data