i finished the implementation
i used a database table (needed a database anyway)
here is the file with regexps
http://berty.110mb.com/files/telephone_number_analyse.xls
this is the class that does the analyses:
import java.sql.SQLException;
import java.util.ArrayList;
import main.DataConnector;
public class TelephoneAnalyser {
private static TelephoneAnalyser instance;
private static ArrayList> countries;
private static RegexpCountry belgium;
public static TelephoneAnalyser getInstance() {
if (instance == null) {
instance = new TelephoneAnalyser();
}
return instance;
}
public TelephoneAnalyser() {
try {
countries = DataConnector.getRegexpCountries();
belgium = DataConnector.getRegexpBelgium();
} catch (SQLException ex) {
System.out.println("Error, problem with getting regexps for cost analysis");
}
}
//number is input and is not changed en country and price are output parameters
public boolean analyse(String number, String countryCode, int price) {
System.out.println("start analyse");
System.out.println("number: " + number);
String num = number;
num.replaceFirst("^0*", "");
System.out.println("number: " + num);
int start = Integer.parseInt(num.substring(1, 2));
for (RegexpCountry country : countries.get(start - 1)) {
if (num.matches(country.getRegexpCountry())) {
countryCode = country.getCode();
if (num.matches(country.getRegexpMobile())) {
price = country.getPriceMobile();
} else {
price = country.getPriceFix();
}
return true;
}
}
return false;
}
}
countryregexp:public class RegexpCountry {
private String code;
private String labelEn;
private String labelNl;
private String regexpCountry;
private String regexpMobile;
private int priceFix;
private int priceMobile;
public RegexpCountry(String labelNl, String code) {
this.code = code;
this.labelNl = labelNl;
}
public RegexpCountry(String labelEn, String labelNl, String code, String regexpCountry, String regexpMobile, int priceFix, int priceMobile) {
this.code = code;
this.labelEn = labelEn;
this.labelNl = labelNl;
this.regexpCountry = regexpCountry;
this.regexpMobile = regexpMobile;
this.priceFix = priceFix;
this.priceMobile = priceMobile;
}
public String getCode() {
return code;
}
public String getLabelEn() {
return labelEn;
}
public String getLabelNl() {
return labelNl;
}
public int getPriceFix() {
return priceFix;
}
public int getPriceMobile() {
return priceMobile;
}
public String getRegexpCountry() {
return regexpCountry;
}
public String getRegexpMobile() {
return regexpMobile;
}
@Override
public String toString(){
return labelNl;
}
}