Skip to content
Snippets Groups Projects
Commit 14dbcef2 authored by Lucas Martin Thomaz's avatar Lucas Martin Thomaz
Browse files

commit message

parent d004efa3
No related branches found
No related tags found
1 merge request!1Initial version
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
......@@ -454,18 +454,21 @@ public class UserInterface
switch (ItemFieldEnum.valueOf(parameterUsedToFilter.toUpperCase()))
{
case DESCRIPTION -> sortedItemsMap =
(HashMap<String, Item>) itemSorter.filterItemDescription(
(HashMap<String, Item>) itemSorter.filterItemRegistry(
getUserInputString(
"Type description to sort by", false),
itemRegistry);
itemRegistry, ItemFieldEnum.DESCRIPTION);
case COLOR -> sortedItemsMap = (HashMap<String, Item>) itemSorter
.filterItemColor(getUserInputColor(false), itemRegistry);
.filterItemRegistry(getUserInputColor(false), itemRegistry,
ItemFieldEnum.COLOR);
case CATEGORY -> sortedItemsMap =
(HashMap<String, Item>) itemSorter.filterItemCategory(
getUserInputItemCategory(), itemRegistry);
(HashMap<String, Item>) itemSorter.filterItemRegistry(
String.valueOf(getUserInputItemCategory()), itemRegistry,
ItemFieldEnum.CATEGORY);
case BRAND -> sortedItemsMap = (HashMap<String, Item>)
itemSorter.filterItemBrand(getUserInputString(
"Type brand to sort by", false), itemRegistry);
itemSorter.filterItemRegistry(getUserInputString(
"Type brand to sort by", false), itemRegistry,
ItemFieldEnum.BRAND);
default ->
{
System.err.println("Neither description, brand, color or category "
......
package utility;
import itemhandler.Item;
import java.security.InvalidParameterException;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import staticconstants.ItemFieldEnum;
/**
* Class used to filter item description, brand, category and color.
*/
public class ItemFilter
{
/**
* Chooses which field is to be used to filter.
* @param stringUsedToFilter String used to filter itemRegistry
* @param itemMap map of Item
* @param field enum of the field to be used in filter
* @return filtered map
*/
public Map<String, Item> filterItemRegistry(String stringUsedToFilter,
Map<String, Item> itemMap, ItemFieldEnum field)
{
Map<String, Item> newMap;
switch (field)
{
case DESCRIPTION -> newMap = filterItemDescription(stringUsedToFilter, itemMap);
case COLOR -> newMap = filterItemColor(stringUsedToFilter, itemMap);
case CATEGORY -> newMap = filterItemCategory(Integer.parseInt(stringUsedToFilter),
itemMap);
case BRAND -> newMap = filterItemBrand(stringUsedToFilter, itemMap);
default -> throw new InvalidParameterException();
}
return newMap;
}
/**
* Filters item in item registry to return an ArrayList containing items that contain
* stringToUsedToFilter in the description.
......@@ -18,7 +44,7 @@ public class ItemFilter
* @param itemMap itemRegistry
* @return itemArrayList new ArrayList containing what was to be filtered
*/
public Map<String, Item> filterItemDescription(String stringToUsedToFilter,
private Map<String, Item> filterItemDescription(String stringToUsedToFilter,
Map<String, Item> itemMap)
{
Iterator<Item> it = itemMap.values().iterator();
......@@ -42,7 +68,7 @@ public class ItemFilter
* @param itemMap itemRegistry
* @return sortedItemMap
*/
public Map<String, Item> filterItemColor(String stringUsedToFilter, Map<String, Item> itemMap)
private Map<String, Item> filterItemColor(String stringUsedToFilter, Map<String, Item> itemMap)
{
Iterator<Item> itemRegistryIterator = itemMap.values().iterator();
HashMap<String, Item> sortedItemMap = new HashMap<>();
......@@ -65,7 +91,7 @@ public class ItemFilter
* @param itemMap itemRegistry
* @return sortedItemMap
*/
public Map<String, Item> filterItemCategory(int stringUsedToFilter,
private Map<String, Item> filterItemCategory(int stringUsedToFilter,
Map<String, Item> itemMap)
{
Iterator<Item> itemRegistryIterator = itemMap.values().iterator();
......@@ -90,7 +116,7 @@ public class ItemFilter
* @param itemMap itemRegistry
* @return sortedItemMap
*/
public Map<String, Item> filterItemBrand(String stringUsedToFilter,
private Map<String, Item> filterItemBrand(String stringUsedToFilter,
Map<String, Item> itemMap)
{
Iterator<Item> itemRegistryIterator = itemMap.values().iterator();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment