Package org.cis1200
Class ColorMap
java.lang.Object
org.cis1200.ColorMap
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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionboolean
Determine whether the map contains a given pixel.Pixel[]
Get an array of the pixels in the map sorted by frequency.int
Retrieves the frequency with which a pixel was used.void
Adds an element to the map or updates its value if the key already exists.int
size()
The number of elements in the map.
-
Constructor Details
-
ColorMap
public ColorMap()
-
-
Method Details
-
put
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
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
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
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.
-