@Test public void predecessors() { Collection<Member> predecessors = ring.streamPredecessors(members.get(5), m -> m.equals(members.get(members.size() - 3))) .collect(Collectors.toList()); assertFalse(predecessors.isEmpty()); assertEquals(7, predecessors.size()); }
public Iterable<Member> predecessors(HashKey location, Predicate<Member> predicate) { Iterator<Member> tail = ring.tailMap(location, false).descendingMap().values().iterator(); Iterator<Member> head = ring.headMap(location, false).descendingMap().values().iterator(); Iterator<Member> iterator = new Iterator<Member>() { private Member next = nextMember(); @Override public boolean hasNext() { return next != null; } @Override public Member next() { if (next == null) { throw new NoSuchElementException(); } Member current = next; next = nextMember(); return current; } private Member nextMember() { while (head.hasNext()) { Member next = head.next(); return predicate.test(next) ? null : next; } while (tail.hasNext()) { Member next = tail.next(); return predicate.test(next) ? null : next; } return null; } }; return new Iterable<Member>() { @Override public Iterator<Member> iterator() { return iterator; } }; }
Ring implements Iterable<Member> { public Iterable<Member> predecessors(HashKey location, Predicate<Member> predicate) { Iterator<Member> tail = ring.tailMap(location, false).descendingMap().values().iterator(); Iterator<Member> head = ring.headMap(location, false).descendingMap().values().iterator(); Iterator<Member> iterator = new Iterator<Member>() { private Member next = nextMember(); @Override public boolean hasNext() { return next != null; } @Override public Member next() { if (next == null) { throw new NoSuchElementException(); } Member current = next; next = nextMember(); return current; } private Member nextMember() { while (head.hasNext()) { Member next = head.next(); return predicate.test(next) ? null : next; } while (tail.hasNext()) { Member next = tail.next(); return predicate.test(next) ? null : next; } return null; } }; return new Iterable<Member>() { @Override public Iterator<Member> iterator() { return iterator; } }; } }
Ring implements Iterable<Member> { public Iterable<Member> predecessors(HashKey location, Predicate<Member> predicate) { Iterator<Member> tail = ring.tailMap(location, false).descendingMap().values().iterator(); Iterator<Member> head = ring.headMap(location, false).descendingMap().values().iterator(); Iterator<Member> iterator = new Iterator<Member>() { private Member next = nextMember(); @Override public boolean hasNext() { return next != null; } @Override public Member next() { if (next == null) { throw new NoSuchElementException(); } Member current = next; next = nextMember(); return current; } private Member nextMember() { while (head.hasNext()) { Member next = head.next(); return predicate.test(next) ? null : next; } while (tail.hasNext()) { Member next = tail.next(); return predicate.test(next) ? null : next; } return null; } }; return new Iterable<Member>() { @Override public Iterator<Member> iterator() { return iterator; } }; } Ring(int index); }
Ring implements Iterable<Member> { public Iterable<Member> predecessors(HashKey location, Predicate<Member> predicate) { Iterator<Member> tail = ring.tailMap(location, false).descendingMap().values().iterator(); Iterator<Member> head = ring.headMap(location, false).descendingMap().values().iterator(); Iterator<Member> iterator = new Iterator<Member>() { private Member next = nextMember(); @Override public boolean hasNext() { return next != null; } @Override public Member next() { if (next == null) { throw new NoSuchElementException(); } Member current = next; next = nextMember(); return current; } private Member nextMember() { while (head.hasNext()) { Member next = head.next(); return predicate.test(next) ? null : next; } while (tail.hasNext()) { Member next = tail.next(); return predicate.test(next) ? null : next; } return null; } }; return new Iterable<Member>() { @Override public Iterator<Member> iterator() { return iterator; } }; } Ring(int index); Iterable<Member> betweenPredecessors(Member start, Member stop); Iterable<Member> betweenSuccessor(Member start, Member stop); int getIndex(); Member insert(Member m); boolean isBetween(Member predecessor, Member item, Member successor); @Override Iterator<Member> iterator(); NavigableSet<HashKey> members(); Member predecessor(Member m); Member predecessor(Member m, Predicate<Member> predicate); Iterable<Member> predecessors(HashKey location, Predicate<Member> predicate); Iterable<Member> predecessors(Member start, Predicate<Member> predicate); int rank(HashKey item, HashKey dest); int rank(HashKey item, Member dest); int rank(Member item, Member dest); int size(); Stream<Member> streamPredecessors(HashKey location, Predicate<Member> predicate); Stream<Member> streamPredecessors(Member m, Predicate<Member> predicate); Stream<Member> streamSuccessors(HashKey location, Predicate<Member> predicate); Stream<Member> streamSuccessors(Member m, Predicate<Member> predicate); Member successor(HashKey hash); Member successor(HashKey hash, Predicate<Member> predicate); Member successor(Member m); Member successor(Member m, Predicate<Member> predicate); Iterable<Member> successors(HashKey location, Predicate<Member> predicate); Iterable<Member> successors(Member m, Predicate<Member> predicate); @Override String toString(); Iterable<Member> traverse(Member member); }
Ring implements Iterable<Member> { public Iterable<Member> predecessors(HashKey location, Predicate<Member> predicate) { Iterator<Member> tail = ring.tailMap(location, false).descendingMap().values().iterator(); Iterator<Member> head = ring.headMap(location, false).descendingMap().values().iterator(); Iterator<Member> iterator = new Iterator<Member>() { private Member next = nextMember(); @Override public boolean hasNext() { return next != null; } @Override public Member next() { if (next == null) { throw new NoSuchElementException(); } Member current = next; next = nextMember(); return current; } private Member nextMember() { while (head.hasNext()) { Member next = head.next(); return predicate.test(next) ? null : next; } while (tail.hasNext()) { Member next = tail.next(); return predicate.test(next) ? null : next; } return null; } }; return new Iterable<Member>() { @Override public Iterator<Member> iterator() { return iterator; } }; } Ring(int index); Iterable<Member> betweenPredecessors(Member start, Member stop); Iterable<Member> betweenSuccessor(Member start, Member stop); int getIndex(); Member insert(Member m); boolean isBetween(Member predecessor, Member item, Member successor); @Override Iterator<Member> iterator(); NavigableSet<HashKey> members(); Member predecessor(Member m); Member predecessor(Member m, Predicate<Member> predicate); Iterable<Member> predecessors(HashKey location, Predicate<Member> predicate); Iterable<Member> predecessors(Member start, Predicate<Member> predicate); int rank(HashKey item, HashKey dest); int rank(HashKey item, Member dest); int rank(Member item, Member dest); int size(); Stream<Member> streamPredecessors(HashKey location, Predicate<Member> predicate); Stream<Member> streamPredecessors(Member m, Predicate<Member> predicate); Stream<Member> streamSuccessors(HashKey location, Predicate<Member> predicate); Stream<Member> streamSuccessors(Member m, Predicate<Member> predicate); Member successor(HashKey hash); Member successor(HashKey hash, Predicate<Member> predicate); Member successor(Member m); Member successor(Member m, Predicate<Member> predicate); Iterable<Member> successors(HashKey location, Predicate<Member> predicate); Iterable<Member> successors(Member m, Predicate<Member> predicate); @Override String toString(); Iterable<Member> traverse(Member member);  }