Package org.cis1200

Class ColorMap

java.lang.Object
org.cis1200.ColorMap

public class ColorMap extends Object
This is a data structure that helps keep track of the frequency with which pixels of specific colors occur. It is a sorted map from Pixel to Integer. Do not change this file.
  • Constructor Details

    • ColorMap

      public ColorMap()
  • Method Details

    • put

      public void put(Pixel p, int v)
      Adds an element to the map or updates its value if the key already exists.
      Parameters:
      p - The Pixel to use as the key.
      v - The int to use as the value.
    • contains

      public boolean contains(Pixel p)
      Determine whether the map contains a given pixel.
      Parameters:
      p - The pixel to check for existence.
      Returns:
      true if the map contains the pixel; false otherwise.
    • getValue

      public int getValue(Pixel p)
      Retrieves the frequency with which a pixel was used. If the Pixel has not previously been stored in the ColorMap, this function throws a NullPointerException.
      Parameters:
      p - The pixel whose frequency should be retrieved.
      Returns:
      The frequency with which the given pixel was used.
    • size

      public int size()
      The number of elements in the map.
      Returns:
      The number of elements in the map.
    • getSortedPixels

      public Pixel[] getSortedPixels()
      Get an array of the pixels in the map sorted by frequency.
      Returns:
      An array of the pixels in the map sorted by frequency, in descending order. The first element in the array is the color with the highest frequency in the image.