code: private void compress() {
          if (sample.size() < 2) {
              return;
          }
  
          ListIterator<Item> it = sample.listIterator();
          int removed = 0;
  
          Item prev = null;
          Item next = it.next();
  
          while (it.hasNext()) {
              prev = next;
              next = it.next();
  
              if (prev.g + next.g + next.delta <= allowableError(it.previousIndex())) {
                  next.g += prev.g;
                  // Remove prev. it.remove() kills the last thing returned.
                  it.previous();
                  it.previous();
                  it.remove();
                  // it.next() is now equal to next, skip it back forward again
                  it.next();
                  removed++;
              }
          }
      }
docs: Try to remove extraneous items from the set of sampled items. This checks
  if an item is unnecessary based on the desired error bounds, and merges
  it with the adjacent item if it is.