CategorizedCircularBuffer { @SuppressWarnings("unchecked") public List<T> subListByKey(K key, int fromIndex, int toIndex) { LinkedList<T> typedList = typedLists.get(key); if (typedList == null) { return Collections.EMPTY_LIST; } return typedList.subList(fromIndex, toIndex); } CategorizedCircularBuffer(int maxCount); void add(K key, T value); List<T> subList(int fromIndex, int toIndex); int size(); @SuppressWarnings("unchecked") List<T> subListByKey(K key, int fromIndex, int toIndex); int sizeByKey(K key);  }
@Test public void testSubListByKey() { CategorizedCircularBuffer<String, Long> ccb = new CategorizedCircularBuffer<String, Long>(6); ccb.add(1L, "e0"); ccb.add(2L, "e1"); ccb.add(1L, "e2"); ccb.add(2L, "e3"); ccb.add(1L, "e4"); ccb.add(2L, "e5"); List<String> l = ccb.subListByKey(1L, 1, 3); assertEquals(2, l.size()); assertEquals("e2", l.get(0)); assertEquals("e0", l.get(1)); }