Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Web-CAT tells us that the removeLocation() and removeStore() methods aren't covered.
- Write a JUnit test to accomplish this.
- The constructor() for Store is:
- public Store(String name, String address, String city)
- */
- import java.util.*;
- import java.io.*;
- /**
- * Maps locations to stores
- *
- * @author Joe Student
- * @version 11/10/13
- */
- public class LocationMap
- {
- /** Internal map */
- private Map<String, Set<Store>> map;
- /**
- * Create new location map
- */
- public LocationMap()
- {
- map = new HashMap<String, Set<Store>>();
- }
- /**
- * Add a location to the map
- * @param location name of location
- */
- public void addLocation(String location)
- {
- map.put(location, new HashSet<Store>());
- }
- /**
- * Remove a location from map
- *
- * @param location Location to remove
- * @return Set Set of stores in location
- */
- public Set<Store> removeLocation(String location)
- {
- return map.remove(location);
- }
- /**
- * Gets stores in location
- *
- * @param location Name of location
- * @return Set Set of stores in location
- */
- public Set<Store> getStores(String location)
- {
- return map.get(location);
- }
- /**
- * Removes a store from the map
- *
- * @param store Store to remove
- */
- public void removeStore(Store store)
- {
- //remove each instance of the store
- for (Map.Entry<String, Set<Store>> pair : map.entrySet())
- {
- Set<Store> stores = pair.getValue();
- stores.remove(store);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment