@Override
    public synchronized BitList<E> subList(int fromIndex, int toIndex) {
        BitSet resultSet = (BitSet) rootSet.clone();
        List<E> copiedTailList = tailList == null ? null : new LinkedList<>(tailList);
        if (toIndex < size()) {
            if (toIndex < rootSet.cardinality()) {
                copiedTailList = null;
                resultSet.set(toIndex, resultSet.length(), false);
            } else {
                copiedTailList =
                        copiedTailList == null ? null : copiedTailList.subList(0, toIndex - rootSet.cardinality());
            }
        }
        if (fromIndex > 0) {
            if (fromIndex < rootSet.cardinality()) {
                resultSet.set(0, fromIndex, false);
            } else {
                resultSet.clear();
                copiedTailList = copiedTailList == null
                        ? null
                        : copiedTailList.subList(fromIndex - rootSet.cardinality(), copiedTailList.size());
            }
        }
        return new BitList<>(originList, resultSet, copiedTailList);
    }
@Test
    void testSubList() {
        List<String> list = Arrays.asList("A", "B", "C", "D", "E");
        BitList<String> bitList = new BitList<>(list);
        bitList.addAll(Arrays.asList("F", "G", "H", "I"));

        BitList<String> subList1 = bitList.subList(0, 5);
        Assertions.assertEquals(Arrays.asList("A", "B", "C", "D", "E"), subList1);

        BitList<String> subList2 = bitList.subList(1, 5);
        Assertions.assertEquals(Arrays.asList("B", "C", "D", "E"), subList2);

        BitList<String> subList3 = bitList.subList(0, 4);
        Assertions.assertEquals(Arrays.asList("A", "B", "C", "D"), subList3);

        BitList<String> subList4 = bitList.subList(1, 4);
        Assertions.assertEquals(Arrays.asList("B", "C", "D"), subList4);

        BitList<String> subList5 = bitList.subList(2, 3);
        Assertions.assertEquals(Collections.singletonList("C"), subList5);
        Assertions.assertFalse(subList5.hasMoreElementInTailList());

        BitList<String> subList6 = bitList.subList(0, 9);
        Assertions.assertEquals(Arrays.asList("A", "B", "C", "D", "E", "F", "G", "H", "I"), subList6);
        Assertions.assertEquals(Arrays.asList("F", "G", "H", "I"), subList6.getTailList());

        BitList<String> subList7 = bitList.subList(1, 8);
        Assertions.assertEquals(Arrays.asList("B", "C", "D", "E", "F", "G", "H"), subList7);
        Assertions.assertEquals(Arrays.asList("F", "G", "H"), subList7.getTailList());

        BitList<String> subList8 = bitList.subList(4, 8);
        Assertions.assertEquals(Arrays.asList("E", "F", "G", "H"), subList8);
        Assertions.assertEquals(Arrays.asList("F", "G", "H"), subList8.getTailList());

        BitList<String> subList9 = bitList.subList(5, 8);
        Assertions.assertEquals(Arrays.asList("F", "G", "H"), subList9);
        Assertions.assertEquals(Arrays.asList("F", "G", "H"), subList9.getTailList());

        BitList<String> subList10 = bitList.subList(6, 8);
        Assertions.assertEquals(Arrays.asList("G", "H"), subList10);
        Assertions.assertEquals(Arrays.asList("G", "H"), subList10.getTailList());

        BitList<String> subList11 = bitList.subList(6, 7);
        Assertions.assertEquals(Collections.singletonList("G"), subList11);
        Assertions.assertEquals(Collections.singletonList("G"), subList11.getTailList());
    }