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