public class Main {
public static void main(String[] argv) {
String s = "book2s";
System.out.println(methodToPropertyName(s));
}
public static String methodToPropertyName(String s) {
s = removeMethodAccessor(s);
return firstCharLowerCase(s);
}
public static String removeMethodAccessor(String s) {
if (isNotEmptyWithTrim(s)) {
if (s.startsWith("get")) {
return s.length() > 3 ? s.substring(3) : s;
} else if (s.startsWith("is")) {
return s.length() > 2 ? s.substring(2) : s;
} else if (s.startsWith("set")) {
return s.length() > 3 ? s.substring(3) : s;
}
}
return s;
}
public static String firstCharLowerCase(String s) {
if (isNotEmptyWithTrim(s)) {
return Character.toLowerCase(s.charAt(0))
+ (s.length() > 1 ? s.substring(1) : "");
}
return s;
}
public static boolean isNotEmptyWithTrim(String s) {
return !isEmptyWithTrim(s);
}
public static boolean isEmptyWithTrim(String s) {
return s == null || s.trim().length() == 0;
}
}
將方法名稱轉(zhuǎn)為屬性名稱
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。
相關(guān)閱讀更多精彩內(nèi)容
- 文章來源: 量化小課堂 本篇文章實(shí)現(xiàn)將日線數(shù)據(jù)轉(zhuǎn)換為周線數(shù)據(jù),并保存到csv格式文件中。
- 由于python存在python2和python3兩個(gè)主要的版本方向,經(jīng)常會(huì)有將python2的代碼轉(zhuǎn)到pytho...
- 2018年4月8日 星期日 陰 學(xué)經(jīng)人員:琪佳媽、琪琪、佳佳。 寶貝年齡:琪琪9歲,佳佳8歲。 學(xué)經(jīng)周期:3年。 ...