mirror of
https://github.com/chatopera/cosin.git
synced 2025-08-01 16:38:02 +08:00
Reformat class MobileNumberUtils
This commit is contained in:
parent
27a6666f14
commit
6b96cef408
@ -21,12 +21,13 @@ import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.*;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class MobileNumberUtils {
|
||||
private static final Logger logger = LoggerFactory.getLogger(MobileNumberUtils.class);
|
||||
private static Map<String , MobileAddress> mobileAddressMap = new HashMap<String ,MobileAddress>();
|
||||
private static final Map<String, MobileAddress> mobileAddressMap = new HashMap<>();
|
||||
private static boolean isInited = false;
|
||||
|
||||
public static int init() throws IOException {
|
||||
@ -34,10 +35,10 @@ public class MobileNumberUtils {
|
||||
logger.info("init with file [{}]", file.getAbsolutePath());
|
||||
if (file.exists()) {
|
||||
FileInputStream reader = new FileInputStream(file);
|
||||
InputStreamReader isr = new InputStreamReader(reader , "UTF-8");
|
||||
InputStreamReader isr = new InputStreamReader(reader, StandardCharsets.UTF_8);
|
||||
BufferedReader bf = new BufferedReader(isr);
|
||||
try {
|
||||
String data = null ;
|
||||
String data;
|
||||
while ((data = bf.readLine()) != null) {
|
||||
String[] group = data.split("[\t ]");
|
||||
MobileAddress address = null;
|
||||
@ -47,12 +48,8 @@ public class MobileNumberUtils {
|
||||
address = new MobileAddress(group[0], group[1], group[2], group[2], group[3]);
|
||||
}
|
||||
if (address != null) {
|
||||
if(mobileAddressMap.get(address.getCode()) == null){
|
||||
mobileAddressMap.put(address.getCode(), address) ;
|
||||
}
|
||||
if(mobileAddressMap.get(address.getAreacode()) == null){
|
||||
mobileAddressMap.put(address.getAreacode(), address) ;
|
||||
}
|
||||
mobileAddressMap.putIfAbsent(address.getCode(), address);
|
||||
mobileAddressMap.putIfAbsent(address.getAreacode(), address);
|
||||
}
|
||||
}
|
||||
isInited = true;
|
||||
@ -67,10 +64,9 @@ public class MobileNumberUtils {
|
||||
}
|
||||
return mobileAddressMap.size();
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据呼入号码 找到对应 城市 , 需要传入的号码是 手机号 或者 固话号码,位数为 11位
|
||||
* @param phoneNumber
|
||||
* @return
|
||||
*/
|
||||
public static MobileAddress getAddress(String phoneNumber) {
|
||||
if (!isInited) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user