The old code:
private void init() throws IOException {
int i, j;
byte [] delim = new byte[3];
byte [] buf = new byte[SEGMENT_RECORD_LENGTH];
if (file == null) {
// distributed service only
for (i = 0; i < 233;i++){
hashmapcountryCodetoindex.put(countryCode[i],new Integer(i));
hashmapcountryNametoindex.put(countryName[i],new Integer(i));
}
...
----------
For the new code, I do the hashmap init in a static bloc, since the variables are static:
static {
if(countryCode.length!=countryName.length)
throw new AssertionError("countryCode.length!=countryName.length");
for (int i = 0; i < countryCode.length; i++){
hashmapcountryCodetoindex.put(countryCode[i], Integer.valueOf(i));
hashmapcountryNametoindex.put(countryName[i], Integer.valueOf(i));
}
}
and the "Location getLocationwithdnsservice(String str)"
has been made static, because it can and doesn't have to wait for the init() anymore.
private void init() throws IOException {
int i, j;
byte [] delim = new byte[3];
byte [] buf = new byte[SEGMENT_RECORD_LENGTH];
if (file == null) {
return;
}
...