@Test public void betweenSuccessor() { int start = 5; int stop = 3; int index = start + 1; for (Member test : ring.betweenSuccessor(members.get(start), members.get(stop))) { if (index == members.size()) { index = 0; } assertEquals("error at index: " + index, members.get(index), test); index++; } }
public Iterable<Member> betweenSuccessor(Member start, Member stop) { if (start.equals(stop)) { return Collections.emptyList(); } HashKey startHash = hash(start); HashKey stopHash = hash(stop); if (startHash.compareTo(stopHash) < 0) { return ring.subMap(startHash, false, stopHash, false).values(); } ConcurrentNavigableMap<HashKey, Member> headMap = ring.headMap(stopHash, false); ConcurrentNavigableMap<HashKey, Member> tailMap = ring.tailMap(startHash, false); Iterator<Member> head = headMap.values().iterator(); Iterator<Member> tail = tailMap.values().iterator(); return new Iterable<Member>() { @Override public Iterator<Member> iterator() { return new Iterator<Member>() { @Override public boolean hasNext() { return tail.hasNext() || head.hasNext(); } @Override public Member next() { return tail.hasNext() ? tail.next() : head.next(); } }; } }; }
Ring implements Iterable<Member> { public Iterable<Member> betweenSuccessor(Member start, Member stop) { if (start.equals(stop)) { return Collections.emptyList(); } HashKey startHash = hash(start); HashKey stopHash = hash(stop); if (startHash.compareTo(stopHash) < 0) { return ring.subMap(startHash, false, stopHash, false).values(); } ConcurrentNavigableMap<HashKey, Member> headMap = ring.headMap(stopHash, false); ConcurrentNavigableMap<HashKey, Member> tailMap = ring.tailMap(startHash, false); Iterator<Member> head = headMap.values().iterator(); Iterator<Member> tail = tailMap.values().iterator(); return new Iterable<Member>() { @Override public Iterator<Member> iterator() { return new Iterator<Member>() { @Override public boolean hasNext() { return tail.hasNext() || head.hasNext(); } @Override public Member next() { return tail.hasNext() ? tail.next() : head.next(); } }; } }; } }
Ring implements Iterable<Member> { public Iterable<Member> betweenSuccessor(Member start, Member stop) { if (start.equals(stop)) { return Collections.emptyList(); } HashKey startHash = hash(start); HashKey stopHash = hash(stop); if (startHash.compareTo(stopHash) < 0) { return ring.subMap(startHash, false, stopHash, false).values(); } ConcurrentNavigableMap<HashKey, Member> headMap = ring.headMap(stopHash, false); ConcurrentNavigableMap<HashKey, Member> tailMap = ring.tailMap(startHash, false); Iterator<Member> head = headMap.values().iterator(); Iterator<Member> tail = tailMap.values().iterator(); return new Iterable<Member>() { @Override public Iterator<Member> iterator() { return new Iterator<Member>() { @Override public boolean hasNext() { return tail.hasNext() || head.hasNext(); } @Override public Member next() { return tail.hasNext() ? tail.next() : head.next(); } }; } }; } Ring(int index); }
Ring implements Iterable<Member> { public Iterable<Member> betweenSuccessor(Member start, Member stop) { if (start.equals(stop)) { return Collections.emptyList(); } HashKey startHash = hash(start); HashKey stopHash = hash(stop); if (startHash.compareTo(stopHash) < 0) { return ring.subMap(startHash, false, stopHash, false).values(); } ConcurrentNavigableMap<HashKey, Member> headMap = ring.headMap(stopHash, false); ConcurrentNavigableMap<HashKey, Member> tailMap = ring.tailMap(startHash, false); Iterator<Member> head = headMap.values().iterator(); Iterator<Member> tail = tailMap.values().iterator(); return new Iterable<Member>() { @Override public Iterator<Member> iterator() { return new Iterator<Member>() { @Override public boolean hasNext() { return tail.hasNext() || head.hasNext(); } @Override public Member next() { return tail.hasNext() ? tail.next() : head.next(); } }; } }; } 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> betweenSuccessor(Member start, Member stop) { if (start.equals(stop)) { return Collections.emptyList(); } HashKey startHash = hash(start); HashKey stopHash = hash(stop); if (startHash.compareTo(stopHash) < 0) { return ring.subMap(startHash, false, stopHash, false).values(); } ConcurrentNavigableMap<HashKey, Member> headMap = ring.headMap(stopHash, false); ConcurrentNavigableMap<HashKey, Member> tailMap = ring.tailMap(startHash, false); Iterator<Member> head = headMap.values().iterator(); Iterator<Member> tail = tailMap.values().iterator(); return new Iterable<Member>() { @Override public Iterator<Member> iterator() { return new Iterator<Member>() { @Override public boolean hasNext() { return tail.hasNext() || head.hasNext(); } @Override public Member next() { return tail.hasNext() ? tail.next() : head.next(); } }; } }; } 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);  }