Code example for SortedMap

Methods: isEmpty, lastKey

0
    // to ensure that line doesn't end before the end of the screen 
 
    // this would be simply: start = mXY.lowerKey(start) but NavigableMap is 
    // available since API 9 
    SortedMap<Double, Double> headMap = mXY.headMap(start);
    if (!headMap.isEmpty()) {
      start = headMap.lastKey();
    } 
 
    // this would be simply: end = mXY.higherKey(end) but NavigableMap is 
    // available since API 9 
    // so we have to do this hack in order to support older versions 
    SortedMap<Double, Double> tailMap = mXY.tailMap(stop);
    if (!tailMap.isEmpty()) {
      Iterator<Double> tailIterator = tailMap.keySet().iterator();
      Double next = tailIterator.next();
      if (tailIterator.hasNext()) {
        stop = tailIterator.next();
      } else { 
        stop += next;
      }