mirror of
https://github.com/ZhigalskiiIvan/TextStatisticsProject.git
synced 2024-11-21 23:01:52 +03:00
debug text reading
This commit is contained in:
parent
d9c5ac32bc
commit
ac5e03640f
@ -4,12 +4,12 @@ import kotlin.system.exitProcess
|
|||||||
import org.jetbrains.letsPlot.*
|
import org.jetbrains.letsPlot.*
|
||||||
import org.jetbrains.letsPlot.geom.geomBar
|
import org.jetbrains.letsPlot.geom.geomBar
|
||||||
import org.jetbrains.letsPlot.intern.Plot
|
import org.jetbrains.letsPlot.intern.Plot
|
||||||
import kotlin.reflect.KType
|
|
||||||
import kotlin.reflect.typeOf
|
import kotlin.reflect.typeOf
|
||||||
|
|
||||||
|
|
||||||
val scanner = Scanner(System.`in`)
|
val scanner = Scanner(System.`in`)
|
||||||
|
|
||||||
|
|
||||||
object StatisticBuilder {
|
object StatisticBuilder {
|
||||||
|
|
||||||
fun askAndExecuteSelfCommands() {
|
fun askAndExecuteSelfCommands() {
|
||||||
@ -66,6 +66,7 @@ object StatisticBuilder {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
object TextReader {
|
object TextReader {
|
||||||
fun askAndExecuteSelfCommands() {
|
fun askAndExecuteSelfCommands() {
|
||||||
|
|
||||||
@ -87,23 +88,25 @@ object TextReader {
|
|||||||
|
|
||||||
println("Input a text content:")
|
println("Input a text content:")
|
||||||
var content = ""
|
var content = ""
|
||||||
readCycle@ while (true) {
|
|
||||||
val nextPart = scanner.next()
|
|
||||||
if (nextPart.isEmpty()) content += nextPart
|
|
||||||
else break@readCycle
|
|
||||||
}
|
|
||||||
|
|
||||||
correctInputQuestion@ while (true) {
|
var itWasNewParYet = false
|
||||||
print("Input was correct?[yes, no]: ")
|
readCycle@ while (true) {
|
||||||
when (readln()) {
|
val nextPart = readln()
|
||||||
"yes" -> addTextToData(name, content)
|
if (nextPart.isBlank()) {
|
||||||
"no" -> readFromConsole()
|
if (itWasNewParYet) break@readCycle
|
||||||
"return" -> return
|
else itWasNewParYet = true
|
||||||
else -> {
|
} else {
|
||||||
println("Input only \"yes\" or \"no\" or \"return\" if you want to exit in main menu:")
|
itWasNewParYet = false
|
||||||
}
|
content += nextPart
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
val correctInputRequest = Main.requestInput(listOf("yes", "no"))
|
||||||
|
correctInputRequest.first.exe()
|
||||||
|
|
||||||
|
if (correctInputRequest.second == "yes") addTextToData(name, content)
|
||||||
|
else readFromConsole()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun readFromFile() {
|
private fun readFromFile() {
|
||||||
@ -214,6 +217,7 @@ object TextData {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
fun exit(): Nothing {
|
fun exit(): Nothing {
|
||||||
println("bye!")
|
println("bye!")
|
||||||
exitProcess(0)
|
exitProcess(0)
|
||||||
@ -229,14 +233,15 @@ object CommandCenter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun readCommandFromConsole(): () -> Unit {
|
fun readCommandFromConsole(): () -> Unit {
|
||||||
println("Input one Of the commands: ${Commands.values().joinToString { it.name.lowercase() }}:")
|
println("Input one Of the commands: ${Commands.values().joinToString { it.name }}:")
|
||||||
val funNameInUpCase = scanner.nextLine().uppercase()
|
|
||||||
|
|
||||||
return if (funNameInUpCase in Commands.values().map { it.name })
|
val commandNameRequest = Main.requestInput(Commands.values().map { it.name })
|
||||||
Commands.valueOf(funNameInUpCase).executingFun
|
commandNameRequest.first.exe()
|
||||||
else ::readCommandFromConsole
|
|
||||||
|
val funName = commandNameRequest.second.toString()
|
||||||
|
|
||||||
|
return Commands.valueOf(funName).executingFun
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -249,14 +254,13 @@ object ContinueCommand : InputOutcomeCommand {
|
|||||||
}
|
}
|
||||||
|
|
||||||
object ReturnCommand : InputOutcomeCommand {
|
object ReturnCommand : InputOutcomeCommand {
|
||||||
override val exe: () -> Unit = { Main.work() }
|
override val exe: () -> Unit = { Main.workCycle() }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class InvalidInputTypeException(expectedType: String) : Exception(expectedType) {
|
class InvalidInputTypeException(expectedType: String) : Exception(expectedType) {
|
||||||
override val message: String = expectedType
|
override val message: String = expectedType
|
||||||
get() = "Was expected type: $field, but it's impossible to convert input in it."
|
get() = "Was expected type: $field, but it's impossible to convert input in it."
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class InvalidElemInInputException() : Exception()
|
class InvalidElemInInputException() : Exception()
|
||||||
@ -264,7 +268,7 @@ class InvalidElemInInputException() : Exception()
|
|||||||
|
|
||||||
object Main {
|
object Main {
|
||||||
|
|
||||||
fun work() {
|
fun workCycle() {
|
||||||
mainCycle@ while (true) {
|
mainCycle@ while (true) {
|
||||||
(CommandCenter.readCommandFromConsole())()
|
(CommandCenter.readCommandFromConsole())()
|
||||||
}
|
}
|
||||||
@ -319,6 +323,7 @@ object Main {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
fun main() {
|
fun main() {
|
||||||
Main.work()
|
Main.workCycle()
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user