From 5f0fba15eb052b16cdb2b4985ecc92353bb0aac7 Mon Sep 17 00:00:00 2001 From: Danila Fedorin Date: Mon, 7 Aug 2017 19:11:13 -0700 Subject: [PATCH] Add comments to the newly created Kotlin implementations. --- .../org/nwapw/abacus/tree/BinaryNode.kt | 11 ++++++++++ .../org/nwapw/abacus/tree/FunctionNode.kt | 21 +++++++++++++++++++ .../org/nwapw/abacus/tree/NumberNode.kt | 8 +++++++ .../kotlin/org/nwapw/abacus/tree/TreeNode.kt | 3 +++ .../kotlin/org/nwapw/abacus/tree/UnaryNode.kt | 9 ++++++++ 5 files changed, 52 insertions(+) diff --git a/src/main/kotlin/org/nwapw/abacus/tree/BinaryNode.kt b/src/main/kotlin/org/nwapw/abacus/tree/BinaryNode.kt index 3493515..7505f82 100644 --- a/src/main/kotlin/org/nwapw/abacus/tree/BinaryNode.kt +++ b/src/main/kotlin/org/nwapw/abacus/tree/BinaryNode.kt @@ -1,5 +1,16 @@ package org.nwapw.abacus.tree +/** + * A tree node that holds a binary operation. + * + * This node represents any binary operation, such as binary infix or binary postfix. The only + * currently implemented into Abacus is binary infix, but that has more to do with the parser than + * this class, which doesn't care about the order that its operation and nodes were found in text. + * + * @param operation the operation this node performs on its children. + * @param left the left node. + * @param right the right node. + */ data class BinaryNode(val operation: String, val left: TreeNode? = null, val right: TreeNode?) : TreeNode() { override fun reduce(reducer: Reducer): T? { diff --git a/src/main/kotlin/org/nwapw/abacus/tree/FunctionNode.kt b/src/main/kotlin/org/nwapw/abacus/tree/FunctionNode.kt index bb95f3f..ab25aaf 100644 --- a/src/main/kotlin/org/nwapw/abacus/tree/FunctionNode.kt +++ b/src/main/kotlin/org/nwapw/abacus/tree/FunctionNode.kt @@ -1,7 +1,18 @@ package org.nwapw.abacus.tree +/** + * A tree node that holds a function call. + * + * The function call node can hold any number of children, and passes the to the appropriate reducer, + * but that is its sole purpose. + * + * @param function the function string. + */ data class FunctionNode(val function: String) : TreeNode() { + /** + * List of function parameters added to this node. + */ val children: MutableList = mutableListOf() override fun reduce(reducer: Reducer): T? { @@ -20,10 +31,20 @@ data class FunctionNode(val function: String) : TreeNode() { return super.toString() } + /** + * Appends a child to this node's list of children. + * + * @node the node to append. + */ fun appendChild(node: TreeNode){ children.add(node) } + /** + * Prepends a child to this node's list of children. + * + * @node the node to prepend. + */ fun prependChild(node: TreeNode){ children.add(0, node) } diff --git a/src/main/kotlin/org/nwapw/abacus/tree/NumberNode.kt b/src/main/kotlin/org/nwapw/abacus/tree/NumberNode.kt index 5d9c09b..03b299d 100644 --- a/src/main/kotlin/org/nwapw/abacus/tree/NumberNode.kt +++ b/src/main/kotlin/org/nwapw/abacus/tree/NumberNode.kt @@ -2,6 +2,14 @@ package org.nwapw.abacus.tree import org.nwapw.abacus.number.NumberInterface +/** + * A tree node that holds a single number value. + * + * This is a tree node that holds a single NumberInterface, which represents any number, + * and is not defined during compile time. + * + * @number the number value of this node. + */ data class NumberNode(val number: NumberInterface) : TreeNode() { override fun reduce(reducer: Reducer): T? { diff --git a/src/main/kotlin/org/nwapw/abacus/tree/TreeNode.kt b/src/main/kotlin/org/nwapw/abacus/tree/TreeNode.kt index 5ebe978..bc1ae5e 100644 --- a/src/main/kotlin/org/nwapw/abacus/tree/TreeNode.kt +++ b/src/main/kotlin/org/nwapw/abacus/tree/TreeNode.kt @@ -1,5 +1,8 @@ package org.nwapw.abacus.tree +/** + * A tree node. + */ abstract class TreeNode { abstract fun reduce(reducer: Reducer) : T? diff --git a/src/main/kotlin/org/nwapw/abacus/tree/UnaryNode.kt b/src/main/kotlin/org/nwapw/abacus/tree/UnaryNode.kt index c9adc62..952c82f 100644 --- a/src/main/kotlin/org/nwapw/abacus/tree/UnaryNode.kt +++ b/src/main/kotlin/org/nwapw/abacus/tree/UnaryNode.kt @@ -1,5 +1,14 @@ package org.nwapw.abacus.tree +/** + * A tree node that holds a unary operation. + * + * This node holds a single operator applied to a single parameter, and does not care + * whether the operation was found before or after the parameter in the text. + * + * @param operation the operation applied to the given node. + * @param applyTo the node to which the operation will be applied. + */ data class UnaryNode(val operation: String, val applyTo: TreeNode? = null) : TreeNode() { override fun reduce(reducer: Reducer): T? {