Class Histogram

java.lang.Object
it.unimi.di.prog2.e17.Histogram
All Implemented Interfaces:
Iterable<Rectangle>

public class Histogram extends Object implements Iterable<Rectangle>
A class to handle a list of rectangles and organize them as in histogram.

The rectangles are organized in decreasing height order, more specifically the iterator returns the rectangles in this order.

  • Constructor Details

    • Histogram

      public Histogram()
      Creates an empty histogram.
  • Method Details

    • add

      public void add(Rectangle rectangle)
      Adds a Rectangle to this histogram.
      Parameters:
      rectangle - the rectangle to add.
    • changeBase

      public void changeBase(Rectangle rectangle, int newBase)
      Changes the base of the given rectangle
      Parameters:
      rectangle - the rectangle.
      newBase - the new base.
      Throws:
      NoSuchElementException - if the rectangle is not in the histogram.
    • iterator

      public Iterator<Rectangle> iterator()
      Returns an iterator that produces the rectangles in this histogram in decreasing height order.
      Specified by:
      iterator in interface Iterable<Rectangle>
      Returns:
      the iterator over the rectangles in this histogram.