ComponentSuffixGenerator.java 926 Bytes
/*
 * Decompiled with CFR 0_118.
 */
package com.day.cq.wcm.designimporter.util;

import java.util.HashMap;
import java.util.Map;
import java.util.Stack;

public class ComponentSuffixGenerator {
    private Stack<Map<String, Integer>> stack;

    public ComponentSuffixGenerator() {
        this.reset();
    }

    public String getSuffix(String componentName) {
        Map<String, Integer> nameMap = this.stack.peek();
        int suffix = -1;
        if (nameMap.containsKey(componentName)) {
            suffix = nameMap.get(componentName) + 1;
        }
        nameMap.put(componentName, suffix);
        return suffix > -1 ? "_" + suffix : "";
    }

    public void startComponentStack() {
        this.stack.push(new HashMap());
    }

    public void endComponentStack() {
        this.stack.pop();
    }

    public void reset() {
        this.stack = new Stack();
        this.stack.push(new HashMap());
    }
}