feat(command): add RemoveFirst command
This commit is contained in:
@@ -7,6 +7,7 @@ import command.commands.Exit
|
||||
import command.commands.Help
|
||||
import command.commands.Info
|
||||
import command.commands.RemoveById
|
||||
import command.commands.RemoveFirst
|
||||
import command.commands.Show
|
||||
import command.commands.Update
|
||||
import io.IOHandler
|
||||
@@ -28,5 +29,6 @@ class AppInitializer {
|
||||
commandManager.register(Info(io, collectionManager))
|
||||
commandManager.register(Update(io, collectionManager))
|
||||
commandManager.register(RemoveById(io, collectionManager))
|
||||
commandManager.register(RemoveFirst(io, collectionManager))
|
||||
}
|
||||
}
|
||||
|
||||
22
app/src/main/kotlin/command/commands/RemoveFirst.kt
Normal file
22
app/src/main/kotlin/command/commands/RemoveFirst.kt
Normal file
@@ -0,0 +1,22 @@
|
||||
package command.commands
|
||||
|
||||
import command.Command
|
||||
import io.IOHandler
|
||||
import manager.CollectionManager
|
||||
import reader.ProductReader
|
||||
|
||||
class RemoveFirst(
|
||||
private val io: IOHandler,
|
||||
private val collectionManager: CollectionManager,
|
||||
) : Command {
|
||||
override val name = "remove_first"
|
||||
override val description = "remove first element"
|
||||
|
||||
override fun execute(args: String) {
|
||||
if (collectionManager.getCollection().isNotEmpty()) {
|
||||
collectionManager.removeFirst()
|
||||
} else {
|
||||
io.println("коллекция пустая, невозможно удалить первый элемент")
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -59,6 +59,11 @@ class CollectionManager(
|
||||
io.println("элемент удален")
|
||||
}
|
||||
|
||||
fun removeFirst() {
|
||||
list.removeFirst()
|
||||
io.println("первый элемент удален")
|
||||
}
|
||||
|
||||
fun getCollection(): LinkedList<Product> = list
|
||||
|
||||
fun clear() {
|
||||
|
||||
Reference in New Issue
Block a user