Skip to content

Commit

Permalink
Added access to internal components
Browse files Browse the repository at this point in the history
  • Loading branch information
prmr committed Apr 4, 2016
1 parent 174340f commit 0c4d228
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
9 changes: 8 additions & 1 deletion labtest01/labtest01/Corporation.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package labtest01;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

/**
* Represents a company that owns and operates
* one or more grocery stores, each with its own inventory.
*/
public class Corporation
public class Corporation implements Iterable<Inventory>
{
private Map<String, Inventory> aInventories = new HashMap<String, Inventory>();

Expand All @@ -19,4 +20,10 @@ public void addInventory(Inventory pInventory)
aInventories.put(pInventory.getName(), pInventory);
}

@Override
public Iterator<Inventory> iterator()
{
return aInventories.values().iterator();
}

}
11 changes: 9 additions & 2 deletions labtest01/labtest01/Inventory.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package labtest01;

import java.util.HashMap;
import java.util.Iterator;

/**
* Represents the inventory of a
* physical grocery store.
*/
public class Inventory
public class Inventory implements Iterable<Item>
{
private final String aName; // Unique
private final HashMap<Item, Integer> aInventory = new HashMap<>();
Expand Down Expand Up @@ -64,7 +65,7 @@ public void dispose(Item pItem, int pQuantity)
* @param pItem The item to check for availability.
* @return How many of the items are available in the inventory.
*/
public int pAvailable(Item pItem)
public int available(Item pItem)
{
if( aInventory.containsKey(pItem))
{
Expand All @@ -75,4 +76,10 @@ public int pAvailable(Item pItem)
return 0;
}
}

@Override
public Iterator<Item> iterator()
{
return aInventory.keySet().iterator();
}
}

0 comments on commit 0c4d228

Please sign in to comment.