java
算天數
DateFormat df = new SimpleDateFormat("yyyyMMdd" );
Date start = df.parse(startDate );
Date end = df.parse(endDate );
debug("diff: " + (end.getTime() - start.getTime() ) );
long cnt = TimeUnit.MILLISECONDS.toDays(end.getTime() - start.getTime() ) + 1;
debug("cnt: " + cnt );
效能化查重複資料
BloomFilter
// 判斷 UID 重覆
if(bloomFilter.contains(opUid.getUid() ) ) {
chkDup = false;
logger.info("UID 檔:{} 名單重覆-UID:{}", opUid.getActivity(), opUid.getUid() );
list = new ArrayList
}
else {
bloomFilter.add(opUid.getUid() );
list.add(opd );
}
字元中文判斷
public static boolean isChinese(char c ) {
boolean result = false;
Character.UnicodeBlock ub = Character.UnicodeBlock.of(c );
if(ub == Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS
|| ub == Character.UnicodeBlock.CJK_COMPATIBILITY_IDEOGRAPHS
|| ub == Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS_EXTENSION_A
|| ub == Character.UnicodeBlock.GENERAL_PUNCTUATION
|| ub == Character.UnicodeBlock.CJK_SYMBOLS_AND_PUNCTUATION
|| ub == Character.UnicodeBlock.HALFWIDTH_AND_FULLWIDTH_FORMS || c == '') {
result = true;
}
return result;
}
檢查 email
String EMAIL_PATTERN = "^[_A-Za-z0-9-]+(\\.[_A-Za-z0-9-]+)*@[_A-Za-z0-9\\_\\-]+(\\.[A-Za-z0-9\\_\\-]+)*(\\.[A-Za-z]{2,})$";
Pattern pattern = Pattern.compile(EMAIL_PATTERN );
Matcher matcher;
if(getMail_1().trim().equals("" ) ) { // 無檔案接收者
err.append("檔案接收者EMail未填\n" );
}
else {
matcher = pattern.matcher(getMail_1().trim() );
if(!matcher.matches() ) {
err.append("檔案接收者EMail格式錯誤\n" );
}
}
java file 找出所有 *RSN* 的檔案
使用 WildcardFileFilter
FileUtils.listFiles(directory, new WildcardFileFilter("*RSN*.txt"), null );