commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Bruce Collie (JIRA)" <>
Subject [jira] Commented: (VALIDATOR-266) DomainValidator uses an O(n) method where an O(1) would be more appropriate
Date Thu, 16 Apr 2009 13:54:15 GMT


Bruce Collie commented on VALIDATOR-266:

A better solution would be to sort the arrays within a static block


Then use Arrays.binarySearch in the various isvalidXXX() calls
    public boolean isValidInfrastructureTld(String iTld) {
        return Arrays.binarySearch(INFRASTRUCTURE_TLDS,chompLeadingDot(iTld.toLowerCase()))>=0;

That way the lists are obsolete and you save a little memory at the same time 

> DomainValidator uses an O(n) method where an O(1) would be more appropriate
> ---------------------------------------------------------------------------
>                 Key: VALIDATOR-266
>                 URL:
>             Project: Commons Validator
>          Issue Type: Bug
>          Components: Routines
>    Affects Versions: 1.4
>            Reporter: Chris Wareham
>            Priority: Minor
> The class org.apache.commons.validator.routines.DomainValidator contains several hard
coded arrays of TLD names. Quite apart from whether these should be in a properties file rather
than the source file itself, they are then used to populate List instances via Arrays.asList()
and the List.contains() method used when validating a TLD. This is almost inevitably an O(n)
operation on each list, and could be improved by populating a single HashSet which would provide
O(1) performance.

This message is automatically generated by JIRA.
You can reply to this email to add a comment to the issue online.

View raw message