class AgentRollupIds {

    public static List<String> getAgentRollupIds(String agentRollupId) {
        List<String> agentRollupIds = new ArrayList<>();
        agentRollupIds.add(agentRollupId);
        int separatorLen = "::".length();
        int lastFoundIndex;
        if (agentRollupId.endsWith("::")) {
            lastFoundIndex = agentRollupId.length() - separatorLen;
        } else {
            lastFoundIndex = agentRollupId.length();
        }
        int nextFoundIndex;
        // -1 because the agent rollup part must be at least 1 character
        while ((nextFoundIndex =
                agentRollupId.lastIndexOf("::", lastFoundIndex - separatorLen - 1)) != -1) {
            if (nextFoundIndex == 0) {
                break;
            }
            agentRollupIds.add(agentRollupId.substring(0, nextFoundIndex + separatorLen));
            lastFoundIndex = nextFoundIndex;
        }
        return agentRollupIds;
    }

    private  AgentRollupIds();

}