Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.testdevlab.demo.handlers
- import com.testdevlab.demo.BoxListener
- import com.testdevlab.demo.models.Chocolate
- class BoxHandler(val listener: BoxListener) {
- private val box = ArrayList<Chocolate>()
- /**
- * Adds a new chocolate to the box
- * @param chocolate - The chocolate that will be added to the box
- */
- fun addChocolate(chocolate: Chocolate) {
- box.add(chocolate)
- listener.onBoxSizeChanged(box.size)
- }
- /**
- * Remove last chocolate candy from the box
- */
- fun removeChocolate() {
- if (box.size != 0) {
- box.removeAt(box.size - 1)
- listener.onBoxSizeChanged(box.size)
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement