feat(command): add RemoveFirst command

This commit is contained in:
2026-03-04 12:18:22 +03:00
parent 20d98bf74b
commit 956e3c15a9
3 changed files with 29 additions and 0 deletions

View File

@@ -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))
}
}

View 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("коллекция пустая, невозможно удалить первый элемент")
}
}
}

View File

@@ -59,6 +59,11 @@ class CollectionManager(
io.println("элемент удален")
}
fun removeFirst() {
list.removeFirst()
io.println("первый элемент удален")
}
fun getCollection(): LinkedList<Product> = list
fun clear() {