Skip to content

Commit e5df33b

Browse files
committed
add API Doc to tree package
1 parent ccddf2e commit e5df33b

File tree

14 files changed

+142
-6
lines changed

14 files changed

+142
-6
lines changed

src/main/scala/com/celadari/jsonlogicscala/evaluate/EvaluatorLogic.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ class EvaluatorLogic(implicit val conf: EvaluatorLogicConf) {
6262
// scalastyle:off return null
6363
protected[this] def evaluateValueLogic(condition: ValueLogic[_]): Any = {
6464
val value = condition.valueOpt.get
65-
val typeValueOpt = condition.typeCodenameOpt
65+
val typeValueOpt = condition.typeOpt
6666
if (typeValueOpt.isEmpty) return null
6767

6868
val evaluatorClassOpt = conf.valueLogicTypeToReducer.get(typeValueOpt.get)

src/main/scala/com/celadari/jsonlogicscala/serialize/Serializer.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ class Serializer(implicit val conf: SerializerConf) {
108108
val (jsType, jsonLogicDatum) = valueLogic
109109
.valueOpt
110110
.map(value => {
111-
val typeCodenameOpt = valueLogic.typeCodenameOpt
111+
val typeCodenameOpt = valueLogic.typeOpt
112112
if (typeCodenameOpt.isEmpty) throw new InvalidValueLogicException("ValueLogic with defined value must define a typeCodename as well")
113113
val marshaller = getMarshaller(typeCodenameOpt.get)
114114
(Json.toJson(typeCodenameOpt.get), marshaller.marshal(value))

src/main/scala/com/celadari/jsonlogicscala/tree/ComposeLogic.scala

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
1+
// Copyright 2019 celadari. All rights reserved. MIT license.
12
package com.celadari.jsonlogicscala.tree
23

34
import play.api.libs.json.{JsResult, JsValue, Reads, Writes}
45
import com.celadari.jsonlogicscala.deserialize.Deserializer
56
import com.celadari.jsonlogicscala.serialize.Serializer
67

78

9+
/**
10+
* Companion object holding implicit reader and writer json.
11+
*/
812
object ComposeLogic {
913

1014
implicit def composeLogicReads(implicit deserializer: Deserializer): Reads[ComposeLogic] = new Reads[ComposeLogic] {
@@ -21,9 +25,25 @@ object ComposeLogic {
2125
def unapply(composeLogic: ComposeLogic): Some[(String, Array[JsonLogicCore])] = Some((composeLogic.operator, composeLogic.conditions))
2226
}
2327

28+
/**
29+
* Represents an internal node in syntax tree. It is an operator node.
30+
* Scala data structures representing expressions from json-logic-typed format are based on abstract syntax tree.
31+
* @param operator: string codename.
32+
* @param _conditions: children [[JsonLogicCore]] nodes. They are the operands the operator must be applied to.
33+
*/
2434
class ComposeLogic(override val operator: String, private[this] var _conditions: Array[JsonLogicCore]) extends JsonLogicCore(operator) {
2535

36+
/**
37+
* Returns array of children nodes.
38+
* @return _conditions.
39+
*/
2640
def conditions: Array[JsonLogicCore] = _conditions
41+
42+
/**
43+
* Sets children nodes.
44+
* Useful with composed operators.
45+
* @param conds: new set of children nodes array.
46+
*/
2747
def conditions_=(conds: Array[JsonLogicCore]): Unit = _conditions = conds
2848

2949
}

src/main/scala/com/celadari/jsonlogicscala/tree/JsonLogicCore.scala

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
1+
// Copyright 2019 celadari. All rights reserved. MIT license.
12
package com.celadari.jsonlogicscala.tree
23

34
import play.api.libs.json._
45
import com.celadari.jsonlogicscala.deserialize.Deserializer
56
import com.celadari.jsonlogicscala.serialize.Serializer
67

78

9+
/**
10+
* Companion object holding implicit reader and writer json.
11+
* Also defines methods to traverse abstract syntax tree and return string representation.
12+
*/
813
object JsonLogicCore {
914

1015
implicit def jsonLogicCoreReads(implicit deserializer: Deserializer): Reads[JsonLogicCore] = new Reads[JsonLogicCore] {
@@ -31,6 +36,13 @@ object JsonLogicCore {
3136
}
3237
}
3338

39+
/**
40+
* Returns string representation of JsonLogicCore object. Used for root node.
41+
* @param jsonLogicCore: the [[com.celadari.jsonlogicscala.tree.JsonLogicCore]] to be represented in tree view.
42+
* @param errorConditionOpt: optional node in tree view representing an error node. Used during evaluation if something
43+
* goes wrong.
44+
* @return string tree view of [[com.celadari.jsonlogicscala.tree.JsonLogicCore]].
45+
*/
3446
def traverseRoot(jsonLogicCore: JsonLogicCore, errorConditionOpt: Option[JsonLogicCore]): String = {
3547
val errorString = errorConditionOpt.filter(_ == jsonLogicCore).map(_ => "ERROR AT: ").getOrElse("")
3648

@@ -59,6 +71,14 @@ object JsonLogicCore {
5971
}
6072
}
6173

74+
/**
75+
* Returns string representation of JsonLogicCore object. Used for non root node.
76+
* @param sb: string builder that is used to accumulate string as syntax tree is traversed.
77+
* @param padding: prefix/space from left to right between parent and children.
78+
* @param pointer: defines if first|internal|last child node.
79+
* @param jsonLogicCore: node to be explored.
80+
* @param errorConditionOpt: optional error node to be highlighted in final string representation.
81+
*/
6282
def traverseNodes(
6383
sb: StringBuilder,
6484
padding: String,
@@ -102,9 +122,17 @@ object JsonLogicCore {
102122

103123
}
104124

105-
125+
/**
126+
* Represents a json-logic-typed scala data structure.
127+
* Scala data structures representing expressions from json-logic-typed format are based on abstract syntax tree.
128+
* @param operator: name of operator this object represents.
129+
*/
106130
abstract class JsonLogicCore(val operator: String) {
107131

132+
/**
133+
* Returns a string tree view of the expression this object represents.
134+
* @return string tree view.
135+
*/
108136
def treeString: String = {
109137
JsonLogicCore.traverseRoot(this, None)
110138
}

src/main/scala/com/celadari/jsonlogicscala/tree/ValueLogic.scala

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// Copyright 2019 celadari. All rights reserved. MIT license.
12
package com.celadari.jsonlogicscala.tree
23

34
import java.util.UUID
@@ -7,6 +8,9 @@ import com.celadari.jsonlogicscala.exceptions.TreeException
78
import com.celadari.jsonlogicscala.tree.types.TypeValue
89

910

11+
/**
12+
* Companion object holding implicit reader json.
13+
*/
1014
object ValueLogic {
1115
val OPERATOR_CODENAME: String = "var"
1216

@@ -17,9 +21,19 @@ object ValueLogic {
1721
}
1822
}
1923

24+
25+
/**
26+
* Represents a leaf node in syntax tree. It is a data node.
27+
* Scala data structures representing expressions from json-logic-typed format are based on abstract syntax tree.
28+
* @param valueOpt: optional data value represented by this node.
29+
* @param typeOpt: optional [[com.celadari.jsonlogicscala.tree.types.TypeValue]]. None value only under composed operators (advanced use).
30+
* @param variableNameOpt: optional string of variableNameOpt. Only defined under composed operators.
31+
* @param pathNameOpt: optional string to represent name of data in json-format-type. Also used as variable name under composed operators.
32+
* @note inherited operator has fixed value of "var".
33+
*/
2034
case class ValueLogic[T](
2135
valueOpt: Option[T],
22-
typeCodenameOpt: Option[TypeValue] = None,
36+
typeOpt: Option[TypeValue] = None,
2337
variableNameOpt: Option[String] = None,
2438
pathNameOpt: Option[String] = Some(UUID.randomUUID().toString)
2539
) extends JsonLogicCore(ValueLogic.OPERATOR_CODENAME) {

src/main/scala/com/celadari/jsonlogicscala/tree/VariableLogic.scala

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
1+
// Copyright 2019 celadari. All rights reserved. MIT license.
12
package com.celadari.jsonlogicscala.tree
23

4+
5+
/**
6+
* Represents an internal node in syntax tree. It is an operator node that represents a variable node in a composed operator.
7+
* Scala data structures representing expressions from json-logic-typed format are based on abstract syntax tree.
8+
* @param variableName: string codename.
9+
* @param composeOperator: sub-parent node this node is variable of.
10+
*/
311
case class VariableLogic(
412
variableName: String,
513
composeOperator: ComposeLogic

src/main/scala/com/celadari/jsonlogicscala/tree/types/AnyTypeValue.scala

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
1+
// Copyright 2019 celadari. All rights reserved. MIT license.
12
package com.celadari.jsonlogicscala.tree.types
23

34
import play.api.libs.json.{JsValue, Writes}
45

56

7+
/**
8+
* Represents an unknown type. Evaluating, serializing, deserializing a tree with a leaf node with
9+
* [[com.celadari.jsonlogicscala.tree.types.AnyTypeValue]] as typeOpt parameters throws an exception.
10+
* Can only be used to manipulate a [[com.celadari.jsonlogicscala.tree.ValueLogic]] as temporary scala data structure
11+
* before setting correct typeOpt parameter.
12+
*/
613
object AnyTypeValue extends TypeValue("anyTypeValue") {
714
val CODENAME_TYPE: String = codename
815

src/main/scala/com/celadari/jsonlogicscala/tree/types/ArrayTypeValue.scala

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
1+
// Copyright 2019 celadari. All rights reserved. MIT license.
12
package com.celadari.jsonlogicscala.tree.types
23

34
import play.api.libs.json.{JsValue, Writes}
45

56

7+
/**
8+
* Companion object holding implicit writer json and constant codename for [[com.celadari.jsonlogicscala.tree.types.ArrayTypeValue]].
9+
*/
610
object ArrayTypeValue {
711
val CODENAME_TYPE: String = "array"
812

@@ -11,4 +15,9 @@ object ArrayTypeValue {
1115
}
1216
}
1317

18+
/**
19+
* Represents a Array[paramType] type.
20+
* @param paramType: parameter type this array is of.
21+
* @note inherited operator has fixed value of "array".
22+
*/
1423
case class ArrayTypeValue(paramType: TypeValue) extends TypeValue(ArrayTypeValue.CODENAME_TYPE)

src/main/scala/com/celadari/jsonlogicscala/tree/types/DefaultTypes.scala

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
1+
// Copyright 2019 celadari. All rights reserved. MIT license.
12
package com.celadari.jsonlogicscala.tree.types
23

4+
5+
/**
6+
* Contains codename of default types.
7+
*/
38
object DefaultTypes {
49

510
val BYTE_CODENAME: String = "byte"

src/main/scala/com/celadari/jsonlogicscala/tree/types/MapTypeValue.scala

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
1+
// Copyright 2019 celadari. All rights reserved. MIT license.
12
package com.celadari.jsonlogicscala.tree.types
23

34
import play.api.libs.json.{JsValue, Writes}
45

56

7+
/**
8+
* Companion object holding implicit writer json and constant codename for [[com.celadari.jsonlogicscala.tree.types.MapTypeValue]].
9+
*/
610
object MapTypeValue {
711
val CODENAME_TYPE: String = "map"
812

@@ -11,4 +15,9 @@ object MapTypeValue {
1115
}
1216
}
1317

18+
/**
19+
* Represents a Map[String, paramType] type.
20+
* @param paramType: parameter type this map is of.
21+
* @note inherited operator has fixed value of "map".
22+
*/
1423
case class MapTypeValue(paramType: TypeValue) extends TypeValue(MapTypeValue.CODENAME_TYPE)

0 commit comments

Comments
 (0)