package net.northking.cctp.common.util;

/**
 * @Title:
 * @Description:
 * @Company: 京北方信息技术股份有限公司
 * @Author: 谢秀松
 * @CreateDate: 2018/3/19
 * @UpdateUser:
 * @Version: 1.0
 */
public class CamelUtil
{
  private static final String UNDERLINE = "_";

  private CamelUtil()
  {
  }

  /**
   * 驼峰命名转下划线
   *
   * @param param
   * @return
   */
  public static String camelToUnderline(String param)
  {
    if (param == null || "".equals(param.trim()))
    {
      return "";
    }

    StringBuilder sb = new StringBuilder();
    for (int i = 0; i < param.length(); i++)
    {
      char c = param.charAt(i);
      if (i > 0 && Character.isUpperCase(c))
      {
        sb.append(UNDERLINE);
      }
      sb.append(c);
    }

    return sb.toString().toLowerCase();
  }

  /**
   * 下划线转驼峰命名
   *
   * @param s
   * @return
   */
  public static String underlineToCamel(String s)
  {
    StringBuilder javaName = new StringBuilder();
    String[] words = s.toLowerCase().split(UNDERLINE);
    for (String word : words)
    {
      javaName.append(word.substring(0, 1).toUpperCase());
      javaName.append(word.substring(1));

    }

    return javaName.toString();
  }
}
