SHARE
TWEET

boxhandler

a guest Aug 14th, 2019 68 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top