Skip to content

Commit

Permalink
Change HallMenu and DiningMenu models
Browse files Browse the repository at this point in the history
Changed these models in accordance with concerns in #1
  • Loading branch information
switchswap committed Jun 5, 2020
1 parent 7210e6b commit 1fb86ed
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 13 deletions.
20 changes: 16 additions & 4 deletions src/main/kotlin/models/DiningMenu.kt
Original file line number Diff line number Diff line change
@@ -1,12 +1,24 @@
package models

import java.util.*
import kotlin.collections.HashMap

data class DiningMenu (val date: Date,
val parkside: HallMenu = HallMenu(date),
val village: HallMenu = HallMenu(date),
val evk: HallMenu = HallMenu(date)) {
/**
* This class represents a full menu for a given day
*/
data class DiningMenu (val date: Date, val halls: HashMap<String, HallMenu> = HashMap()) {

val parkside: HallMenu = halls.getOrPut(DiningHallType.PARKSIDE.name) { HallMenu(date, DiningHallType.PARKSIDE) }
val village: HallMenu = halls.getOrPut(DiningHallType.VILLAGE.name) { HallMenu(date, DiningHallType.VILLAGE) }
val evk: HallMenu = halls.getOrPut(DiningHallType.EVK.name) { HallMenu(date, DiningHallType.EVK) }

/**
* Add item to the dining menu
*
* @param menuItem The [MenuItem] to add
* @param itemType The [ItemType] of the item
* @param diningHallType The [DiningHallType] of the item
*/
fun addItem(menuItem: MenuItem, itemType: ItemType, diningHallType: DiningHallType) {
when (diningHallType) {
DiningHallType.PARKSIDE -> parkside.addItem(menuItem, itemType)
Expand Down
29 changes: 20 additions & 9 deletions src/main/kotlin/models/HallMenu.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,43 @@ package models
import java.util.*
import kotlin.collections.HashMap

data class HallMenu (val date: Date,
val breakfast: HashMap<String, MenuItem> = HashMap(),
val brunch: HashMap<String, MenuItem> = HashMap(),
val lunch: HashMap<String, MenuItem> = HashMap(),
val dinner: HashMap<String, MenuItem> = HashMap()) {
/**
* This class represents a dining hall menu
*/
data class HallMenu(val date: Date, val hallType: DiningHallType,
val menus: HashMap<String, HashMap<String, MenuItem>> = HashMap()) {

val breakfast: HashMap<String, MenuItem> = menus.getOrPut(ItemType.BREAKFAST.typeName) { HashMap() }
val brunch: HashMap<String, MenuItem> = menus.getOrPut(ItemType.BRUNCH.typeName) { HashMap() }
val lunch: HashMap<String, MenuItem> = menus.getOrPut(ItemType.LUNCH.typeName) { HashMap() }
val dinner: HashMap<String, MenuItem> = menus.getOrPut(ItemType.DINNER.typeName) { HashMap() }

fun hasBreakfast(): Boolean {
return !breakfast.isEmpty()
return breakfast.isNotEmpty()
}

fun hasBrunch(): Boolean {
return !brunch.isEmpty()
return brunch.isNotEmpty()
}

fun hasLunch(): Boolean {
return !lunch.isEmpty()
return lunch.isNotEmpty()
}

fun hasDinner(): Boolean {
return !dinner.isEmpty()
return dinner.isNotEmpty()
}

fun isClosed(): Boolean {
return breakfast.isEmpty() && brunch.isEmpty() && lunch.isEmpty() && dinner.isEmpty()
}

/**
* Add item to dining hall menu
*
* @param menuItem The [MenuItem] to add
* @param itemType The [ItemType] of the item
*/
fun addItem(menuItem: MenuItem, itemType: ItemType) {
val itemName: String = menuItem.itemName.toLowerCase()
when (itemType) {
Expand Down

0 comments on commit 1fb86ed

Please sign in to comment.