SetIterator(final float k) { if ((next = locateKey(k)) != null) { if (compare(next.key, k) <= 0) { prev = next; next = next.next(); } else prev = next.prev(); } } @Override
/** * Locates the first entry. * * @return the first entry of this subset, or {@code null} if the subset is * empty. */ public FloatAVLTreeSet.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. FloatAVLTreeSet.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; } /**
/** * Locates the last entry. * * @return the last entry of this subset, or {@code null} if the subset is * empty. */ public FloatAVLTreeSet.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. FloatAVLTreeSet.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; } @Override
SubsetIterator(final float k) { this(); if (next != null) { if (!bottom && compare(k, next.key) < 0) prev = null; else if (!top && compare(k, (prev = lastEntry()).key) >= 0) next = null; else { next = locateKey(k); if (compare(next.key, k) <= 0) { prev = next; next = next.next(); } else prev = next.prev(); } } } @Override