-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1.0.4 major changes added writer made stuff lazy , and made a lot of …
…implicit got rid of instance of
- Loading branch information
Showing
21 changed files
with
182 additions
and
69 deletions.
There are no files selected for viewing
Binary file not shown.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"1":2,"3":[-1,2,-3.005640e+00,4.356560e+00],"hello":true} |
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
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
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,15 @@ | ||
package com.json.traits | ||
|
||
abstract class JsonBoolTrait(b:Boolean) extends JsonValue with JsonKey{ | ||
override def copy(a:Any):JsonBoolTrait | ||
def copy(a:Boolean):JsonBoolTrait | ||
override def apply(key:JsonKey):JsonValue = throw new IllegalAccessException("JsonBooleanTrait does not supports apply, try getValue()") | ||
override def apply(key:Int):JsonValue = throw new IllegalAccessException("JsonBooleanTrait does not supports apply, try getValue()") | ||
override def getValue() = b | ||
override def getValue():Boolean = b | ||
|
||
override def getStringStream() = Stream(b.toString()) | ||
|
||
} | ||
|
||
object JsonBoolTrait { | ||
implicit def value2Bool(a:JsonValue) = a match { case e:JsonBoolTrait => e; | ||
case _ => throw new ClassCastException("Cannot cast "+a.getClass +" to "+this.getClass)} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,26 @@ | ||
package com.json.traits | ||
|
||
abstract class JsonListTrait(value:Seq[JsonValue]) extends JsonUnit with JsonValue { | ||
override def copy(a:Any):JsonListTrait | ||
def copy(a:Seq[JsonValue]):JsonListTrait | ||
|
||
override def apply(key:Int):JsonValue = value.applyOrElse(key, null) | ||
override def apply(key:JsonKey):JsonValue = throw new IllegalAccessException("JsonArrayTrait does not supports apply on JsonKey, try getValue()") | ||
override def getValue() = value | ||
override def apply(key:JsonKey):JsonValue = key match { | ||
case key:JsonNumberTrait => value.applyOrElse(key.getValue().toInt, null) | ||
case _ => throw new IllegalArgumentException("Non JsonNumber argument given ") | ||
} | ||
|
||
override def getValue():Seq[JsonValue] = value | ||
|
||
|
||
override def getStringStream() = { | ||
Stream("[")++value.toStream.flatMap(f => f.getStringStream() ++ Stream(","))++Stream("]") | ||
(value.toStream.flatMap(f => Stream(",")++f.getStringStream())) match { | ||
case Stream() => Stream("[")++Stream("]") | ||
case v => Stream("[")++v.tail++Stream("]") | ||
} | ||
} | ||
|
||
} | ||
|
||
object JsonListTrait { | ||
implicit def value2Array(a:JsonValue) = a match { case e:JsonListTrait => e; | ||
case _ => throw new ClassCastException("Cannot cast "+a.getClass +" to "+this.getClass)} | ||
} |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,22 @@ | ||
package com.json.traits | ||
|
||
abstract class JsonNumberTrait(num:Double) extends JsonKey with JsonValue { | ||
override def copy(a:Any):JsonNumberTrait | ||
def copy(a:Double):JsonNumberTrait | ||
override def apply(key:JsonKey):JsonValue = throw new IllegalAccessException("JsonNumberTrait does not supports apply, try getValue()") | ||
override def apply(key:Int):JsonValue = throw new IllegalAccessException("JsonNumberTrait does not supports apply, try getValue()") | ||
override def getValue() = num | ||
|
||
override def getStringStream() = Stream(num.toString()) | ||
override def getValue():Double = num | ||
|
||
override def getStringStream() = Stream( this.printDouble(num)) | ||
|
||
private def printDouble(a:Double) = { | ||
if(a < Int.MaxValue ) | ||
if((a - a.toInt) != 0) f"$a%e" else a.toInt.toString() | ||
else | ||
f"$a%e" | ||
} | ||
|
||
} | ||
|
||
object JsonNumberTrait { | ||
implicit def value2Number(a:JsonValue) = a match { case e:JsonNumberTrait => e; | ||
case _ => throw new ClassCastException("Cannot cast "+a.getClass +" to "+this.getClass)} | ||
} |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,6 @@ | ||
package com.json.traits | ||
|
||
trait JsonUnit { | ||
trait JsonUnit{ | ||
override def toString():String | ||
def getValue():Any | ||
def copy(a:Any):JsonUnit | ||
} |
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
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
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
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
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
Oops, something went wrong.