Class PriceTree
- All Implemented Interfaces:
Serializable, Cloneable, Map<Float,Short>, NavigableMap<Float, Short>, SequencedMap<Float, Short>, SortedMap<Float, Short>
-
Nested Class Summary
Nested classes/interfaces inherited from class AbstractMap
AbstractMap.SimpleEntry<K,V>, AbstractMap.SimpleImmutableEntry<K, V> -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate voidaddAllItems(List<Float> prices, List<Short> itemIndices) Adds all items from lists of prices and indices to thePriceTree.private voidAdds an item to thePriceTreegiven its price and index.int[]findItemsInPriceRange(float minPrice, float maxPrice) Finds items within a specified price range.Methods inherited from class TreeMap
ceilingEntry, ceilingKey, clear, clone, comparator, compute, computeIfAbsent, computeIfPresent, containsKey, containsValue, descendingKeySet, descendingMap, entrySet, firstEntry, firstKey, floorEntry, floorKey, forEach, get, headMap, headMap, higherEntry, higherKey, keySet, lastEntry, lastKey, lowerEntry, lowerKey, merge, navigableKeySet, pollFirstEntry, pollLastEntry, put, putAll, putFirst, putIfAbsent, putLast, remove, replace, replace, replaceAll, size, subMap, subMap, tailMap, tailMap, valuesMethods inherited from class AbstractMap
equals, hashCode, isEmpty, toStringMethods inherited from interface NavigableMap
reversedMethods inherited from interface SequencedMap
sequencedEntrySet, sequencedKeySet, sequencedValues
-
Constructor Details
-
PriceTree
Creates aPriceTreefrom aTable.- Parameters:
table- A tablesawTablecontaining the item data, with each row representing an item and containing a price column and an index column.- Preconditions:
- table is not null and contains the expected columns for prices and item indices.
-
-
Method Details
-
addItem
Adds an item to thePriceTreegiven its price and index.- Parameters:
price- The price of the item to add.itemIndex- The index of the item in the original table to add.- Preconditions:
- price is a non-negative float representing the price of the item. itemIndex is a short representing the index of the item in the original table.
-
findItemsInPriceRange
public int[] findItemsInPriceRange(float minPrice, float maxPrice) Finds items within a specified price range.- Parameters:
minPrice- The minimum price of the range.maxPrice- The maximum price of the range.- Returns:
- An array of item indices that fall within the specified price range.
- Preconditions:
minPriceandmaxPriceare non-negative floats.minPriceis less than or equal tomaxPrice.
-
addAllItems
Adds all items from lists of prices and indices to thePriceTree.- Parameters:
prices- A list of prices for the items to add.itemIndices- A list of item indices corresponding to the prices.- Preconditions:
pricesanditemIndicesare not null.pricesanditemIndiceshave the same size.
-