Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

#13 there is 253 country in the code, but the array scan is 233

open
nobody
None
5
2009-05-22
2009-05-22
Quartz12h
No

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;
}
...

Discussion