Class PriceTree

java.lang.Object
java.util.AbstractMap<Float,Short>
java.util.TreeMap<Float,Short>
org.troy.capstone.data_structures.PriceTree
All Implemented Interfaces:
Serializable, Cloneable, Map<Float,Short>, NavigableMap<Float,Short>, SequencedMap<Float,Short>, SortedMap<Float,Short>

public class PriceTree extends TreeMap<Float,Short>
A data TreeMap holding keys of prices and values of item indices, allowing for efficient retrieval of items within a specified price range.
See Also:
  • Constructor Details

    • PriceTree

      public PriceTree(Table table)
      Creates a PriceTree from a Table.
      Parameters:
      table - A tablesaw Table containing 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

      private void addItem(float price, Short itemIndex)
      Adds an item to the PriceTree given 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:
      minPrice and maxPrice are non-negative floats. minPrice is less than or equal to maxPrice.
    • addAllItems

      private void addAllItems(List<Float> prices, List<Short> itemIndices)
      Adds all items from lists of prices and indices to the PriceTree.
      Parameters:
      prices - A list of prices for the items to add.
      itemIndices - A list of item indices corresponding to the prices.
      Preconditions:
      prices and itemIndices are not null. prices and itemIndices have the same size.