Advertisement
Guest User

boxhandler

a guest
Aug 14th, 2019
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.70 KB | None | 0 0
  1. package com.testdevlab.demo.handlers
  2.  
  3. import com.testdevlab.demo.BoxListener
  4. import com.testdevlab.demo.models.Chocolate
  5.  
  6. class BoxHandler(val listener: BoxListener) {
  7.  
  8. private val box = ArrayList<Chocolate>()
  9.  
  10. /**
  11. * Adds a new chocolate to the box
  12. * @param chocolate - The chocolate that will be added to the box
  13. */
  14. fun addChocolate(chocolate: Chocolate) {
  15. box.add(chocolate)
  16. listener.onBoxSizeChanged(box.size)
  17. }
  18.  
  19. /**
  20. * Remove last chocolate candy from the box
  21. */
  22. fun removeChocolate() {
  23. if (box.size != 0) {
  24. box.removeAt(box.size - 1)
  25. listener.onBoxSizeChanged(box.size)
  26. }
  27. }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement