public static String addOrIncrementIndexInName(String name) {
        Matcher m = TRAILING_NUMBER_PATTERN.matcher(name);
        int index = 2;
        if (m.matches()) {
            try {
                int newIndex = Integer.parseInt(m.group(2)) + 1;
                if (newIndex > 2) {
                    index = newIndex;
                    name = m.group(1);
                }
            } catch (NumberFormatException ignored) {
            }
        }
        return name + '-' + index;
    }
@Test
    public void test_addIndexToName() {
        assertEquals("a-2", addOrIncrementIndexInName("a"));
        assertEquals("a-3", addOrIncrementIndexInName("a-2"));
        assertEquals("a-26", addOrIncrementIndexInName("a-25"));
        assertEquals("a-25x-2", addOrIncrementIndexInName("a-25x"));
        assertEquals("a-1351318168168168168168-2", addOrIncrementIndexInName("a-1351318168168168168168"));
        assertEquals("a-" + Integer.MAX_VALUE + "-2", addOrIncrementIndexInName("a-" + Integer.MAX_VALUE));
        assertEquals("a-0-2", addOrIncrementIndexInName("a-0"));
        assertEquals("a-1-2", addOrIncrementIndexInName("a-1"));
        assertEquals("a-1-3", addOrIncrementIndexInName("a-1-2"));
        assertEquals("a--1-2", addOrIncrementIndexInName("a--1"));
    }