RendezvousHash { public N getOne(byte[] key) { final TreeMap<Long, N> nodeMap = generateOrderedNodeMapForKey(key); return nodeMap.descendingMap().values().stream().findFirst().orElse(null); } RendezvousHash(Funnel<N> nodeFunnel, Collection<? extends N> init); void add(N node); void remove(N node); void refresh(List<N> list); N getOne(byte[] key); List<N> get(byte[] key, int listSize);  }
@Test void simpleGet() { Map<String, String> map = new ImmutableMap.Builder<String, String>() .put("a", "1") .put("b", "2") .put("c", "3") .put("d", "4") .put("e", "5") .build(); RendezvousHash<CharSequence> hasher = new RendezvousHash<>(Funnels.stringFunnel(XrpcConstants.DEFAULT_CHARSET), map.keySet()); String k1 = "foo"; String k2 = "bar"; String k3 = "baz"; assertEquals(hasher.getOne(k1.getBytes()), hasher.getOne(k1.getBytes())); assertEquals(hasher.getOne(k2.getBytes()), hasher.getOne(k2.getBytes())); assertEquals(hasher.getOne(k3.getBytes()), hasher.getOne(k3.getBytes())); String k4 = "biz"; assertEquals(hasher.getOne(k4.getBytes()), hasher.getOne(k4.getBytes())); System.out.println(hasher.getOne(k1.getBytes())); System.out.println(hasher.getOne(k2.getBytes())); System.out.println(hasher.getOne(k3.getBytes())); System.out.println(hasher.getOne(k4.getBytes())); System.out.println(hasher.getOne(k1.getBytes())); System.out.println(hasher.getOne(k2.getBytes())); System.out.println(hasher.getOne(k3.getBytes())); System.out.println(hasher.getOne(k4.getBytes())); assertNotEquals(hasher.getOne(k1.getBytes()), hasher.getOne(k4.getBytes())); }