/** * Locates the last entry. * * @return the last entry of this subset, or <code>null</code> if the subset is empty. */ public LongAVLTreeSet.Entry lastEntry() { if (tree == null) return null; // If this subset goes to infinity, we return the main set last entry; otherwise, we locate // the end of the set. LongAVLTreeSet.Entry e; if (top) e = lastEntry; else { e = locateKey(to); // If we find something smaller than the end we're OK. if (compare(e.key, to) >= 0) e = e.prev(); } // Finally, if this subset doesn't go to -infinity, we check that the resulting key isn't // smaller than the start. if (e == null || !bottom && compare(e.key, from) < 0) return null; return e; }
/** * Locates the first entry. * * @return the first entry of this subset, or <code>null</code> if the subset is empty. */ public LongAVLTreeSet.Entry firstEntry() { if (tree == null) return null; // If this subset goes to -infinity, we return the main set first entry; otherwise, we locate // the start of the set. LongAVLTreeSet.Entry e; if (bottom) e = firstEntry; else { e = locateKey(from); // If we find either the start or something greater we're OK. if (compare(e.key, from) < 0) e = e.next(); } // Finally, if this subset doesn't go to infinity, we check that the resulting key isn't // greater than the end. if (e == null || !top && compare(e.key, to) >= 0) return null; return e; }