feat(command): add clear command
This commit is contained in:
@@ -2,6 +2,7 @@ package app
|
||||
|
||||
import command.CommandManager
|
||||
import command.commands.Add
|
||||
import command.commands.Clear
|
||||
import command.commands.Exit
|
||||
import io.IOHandler
|
||||
import manager.CollectionManager
|
||||
@@ -16,5 +17,6 @@ class AppInitializer {
|
||||
|
||||
manager.register(Add(io, collectionManager))
|
||||
manager.register(Exit(io) { app.stop() })
|
||||
manager.register(Clear(io, collectionManager))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,13 +7,14 @@ import reader.ProductReader
|
||||
|
||||
class Add(
|
||||
private val io: IOHandler,
|
||||
private val manager: CollectionManager,
|
||||
private val collectionManager: CollectionManager,
|
||||
) : Command {
|
||||
override val name = "add"
|
||||
override val description = "add product"
|
||||
|
||||
override fun execute() {
|
||||
io.println("добавляем продукт")
|
||||
manager.addProduct(ProductReader(io).read())
|
||||
collectionManager.addProduct(ProductReader(io).read())
|
||||
io.println(collectionManager.getList().toString())
|
||||
}
|
||||
}
|
||||
|
||||
18
app/src/main/kotlin/command/commands/Clear.kt
Normal file
18
app/src/main/kotlin/command/commands/Clear.kt
Normal file
@@ -0,0 +1,18 @@
|
||||
package command.commands
|
||||
|
||||
import command.Command
|
||||
import io.IOHandler
|
||||
import manager.CollectionManager
|
||||
|
||||
class Clear(
|
||||
private val io: IOHandler,
|
||||
private val collectionManager: CollectionManager,
|
||||
) : Command {
|
||||
override val name = "clear"
|
||||
override val description = "clear colletion"
|
||||
|
||||
override fun execute() {
|
||||
collectionManager.getList().clear()
|
||||
io.println(collectionManager.getList().toString())
|
||||
}
|
||||
}
|
||||
@@ -13,7 +13,6 @@ class CollectionManager(
|
||||
|
||||
fun addProduct(product: Product) {
|
||||
list.add(generateId(product))
|
||||
io.println(list.toString())
|
||||
}
|
||||
|
||||
fun generateId(product: Product): Product {
|
||||
@@ -24,4 +23,6 @@ class CollectionManager(
|
||||
)
|
||||
return res
|
||||
}
|
||||
|
||||
fun getList(): LinkedList<Product> = list
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user