### Question:
CategorizedCircularBuffer { public void add(K key, T value) { mainList.addFirst(new Pair<T, K>(key, value)); while (mainList.size() > maxSize) { removeLastEntry(); } LinkedList<T> typedList = typedLists.get(key); if (typedList == null) { typedList = new LinkedList<T>(); typedLists.put(key, typedList); } typedList.addFirst(value); } CategorizedCircularBuffer(int maxCount); void add(K key, T value); List<T> subList(int fromIndex, int toIndex); int size(); List<T> subListByKey(K key, int fromIndex, int toIndex); int sizeByKey(K key);  }### Answer:
@Test public void testAdd() { CategorizedCircularBuffer<String, Long> ccb = new CategorizedCircularBuffer<String, Long>(4); ccb.add(1l, "e0"); assertEquals(1, ccb.size()); assertEquals(1, ccb.sizeByKey(1l)); assertEquals(0, ccb.sizeByKey(999l)); ccb.add(1l, "e1"); assertEquals(2, ccb.size()); assertEquals(2, ccb.sizeByKey(1l)); assertEquals(0, ccb.sizeByKey(999l)); ccb.add(2l, "e2"); assertEquals(3, ccb.size()); assertEquals(2, ccb.sizeByKey(1l)); assertEquals(1, ccb.sizeByKey(2l)); assertEquals(0, ccb.sizeByKey(999l)); ccb.add(3l, "e2"); assertEquals(4, ccb.size()); ccb.add(4l, "e0"); assertEquals(4, ccb.size()); assertEquals(1, ccb.sizeByKey(1l)); }