mirror of
https://github.com/ZhigalskiiIvan/TextStatisticsProject.git
synced 2024-11-22 07:11: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 = ""
|
||||||
|
|
||||||
|
var itWasNewParYet = false
|
||||||
readCycle@ while (true) {
|
readCycle@ while (true) {
|
||||||
val nextPart = scanner.next()
|
val nextPart = readln()
|
||||||
if (nextPart.isEmpty()) content += nextPart
|
if (nextPart.isBlank()) {
|
||||||
else break@readCycle
|
if (itWasNewParYet) break@readCycle
|
||||||
|
else itWasNewParYet = true
|
||||||
|
} else {
|
||||||
|
itWasNewParYet = false
|
||||||
|
content += nextPart
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
correctInputQuestion@ while (true) {
|
|
||||||
print("Input was correct?[yes, no]: ")
|
val correctInputRequest = Main.requestInput(listOf("yes", "no"))
|
||||||
when (readln()) {
|
correctInputRequest.first.exe()
|
||||||
"yes" -> addTextToData(name, content)
|
|
||||||
"no" -> readFromConsole()
|
if (correctInputRequest.second == "yes") addTextToData(name, content)
|
||||||
"return" -> return
|
else readFromConsole()
|
||||||
else -> {
|
|
||||||
println("Input only \"yes\" or \"no\" or \"return\" if you want to exit in main menu:")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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