All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.adobe.aemds.guide.utils.NameUtils Maven / Gradle / Ivy

/*************************************************************************
 *
 * ADOBE CONFIDENTIAL
 * __________________
 *
 *  Copyright 2017 Adobe Systems Incorporated
 *  All Rights Reserved.
 *
 * NOTICE:  All information contained herein is, and remains
 * the property of Adobe Systems Incorporated and its suppliers,
 * if any.  The intellectual and technical concepts contained
 * herein are proprietary to Adobe Systems Incorporated and its
 * suppliers and may be covered by U.S. and Foreign Patents,
 * patents in process, and are protected by trade secret or copyright law.
 * Dissemination of this information or reproduction of this material
 * is strictly forbidden unless prior written permission is obtained
 * from Adobe Systems Incorporated.
 **************************************************************************/

package com.adobe.aemds.guide.utils;

import org.apache.commons.lang3.text.WordUtils;

import java.util.HashMap;


public final class NameUtils {
    private NameUtils() {
        throw new UnsupportedOperationException();
    }

    /**
     * Replaces all occurances of '.' with '_' as Dot isn't allowed to ba part of naming of components.
     * Also, ensures that all the names generated are unique.
     *
     * @param localName
     * @param nameCountMap
     * @pad.exclude Exclude from Published API.
     */
    public static String getOrGenerateUniqueName(String localName, HashMap nameCountMap) {
        String normalizedName = localName.replace('.', '_');
        if (GuideConstants.GUIDE_RESERVED_WORDS.contains(normalizedName) || nameCountMap.containsKey(normalizedName)) {
            int count = nameCountMap.getOrDefault(normalizedName, 0) + 1;
            nameCountMap.put(normalizedName, count);
            normalizedName = normalizedName + "_" + count;
        } else {
            nameCountMap.put(normalizedName, 0);
        }
        return normalizedName;
    }

    /**
     * @param name
     * @pad.exclude Exclude from Published API.
     */
    public static String humanize(String name) {
        if (name == null) {
            return null;
        }
        String humanizedName = name.replaceAll("_", " ");
        humanizedName =
                humanizedName.replaceAll("([A-Z][a-z]+)", " $1") // Words beginning with UC
                        .replaceAll("([A-Z][A-Z]+)", " $1") // "Words" of only UC
                        .replaceAll("([^A-Za-z ]+)", " $1") // "Words" of non-letters
                        .trim();
        humanizedName = WordUtils.capitalize(humanizedName);
        return humanizedName;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy