How to speedup multiple searches on an HashTable
<p>I have two files (with almost 5000 lines each) with logs. The files in each line has a set of rules associated too an email, like this:</p>

<pre><code>Y#12#EMAIL_1#RULE_1,RULE_2,RULE_3,RULE_4#time=993470174
Y#12#EMAIL_2#RULE_1,RULE_2,RULE_3,RULE_4#time=993470175
Y#12#EMAIL_3#RULE_1,RULE_2,RULE_3#time=9934701778
</code></pre>

<p>I use the following function to read the file, and get the rules for each email:</p>

<pre><code>private void processFile()
    {
           ArrayList&lt;String[]&gt; lSplitRules = new ArrayList&lt;&gt;();

        try {
            FileInputStream fileStream = new FileInputStream("log.log");
            DataInputStream fileIn = new DataInputStream(fileStream);
            BufferedReader fileBr = new BufferedReader(new InputStreamReader(fileIn));

            String strLine;

            while ((strLine = fileBr.readLine()) != null)
            {
                    String[] lTokens = strLineSpam.split("#");
                    String lRawRules =  lTokens[3];
                    lSplitRules.add(lRawRules.split(","));
            }


        } catch (FileNotFoundException e) {
            System.out.println("File: log.log, not found. Error: " + e.getMessage());
        } catch (IOException e) {
            System.out.println("Couldn't open log.log. Error: " + e.getMessage());
        }
</code></pre>

<p>So far so, good. In each "space" of the ArrayList I'll have an String[] containing the rules for each email. In other hand i have also an HashMap containing one unique list of rules and it's value like this:</p>

<pre><code>RULE_NAME - VALUE
RULE_1 - 0.1
RULE_2 - 0.5
RULE_3 - 0.6
...
</code></pre>

<p>I need to compare every rule of every email too see if it exists on the HashMap. If exist returns the value of the rule for some calculations
I use this function for that:</p>

<pre><code>private Double eval (String rule, Map&lt;String, Double&gt; scores)
{

    for (Entry&lt;String, Double&gt; entry : scores.entrySet()) {
        if (entry.getKey().equalsIgnoreCase(rule))
        {
            return entry.getValue();
        }
    }

    return 0.0;
}
</code></pre>

<p>The problem is that i need to compare every email and it's rules multiple times (more then 10.000), since I'm using a Genetic Algorithm to try to optimize the VALUE of each RULE. Is there anyway to optimize the comparison of the rules of each email through the HASHMAP? Since i need speed, I'm doing 100 verifications in 8 minutes now.</p>

<p>Sorry for my english.</p>

<p>Regards</p>
