How often do you look within the bowels of your age-old "helper" classes? For most, including Sean, the answer is almost never. Why bother when it works just fine? Well, one reason might be to see what interesting techniques your predecessors employed in solving the simplest of problems... such as a case-insensitive search...

Fortunately, the original programmer never had to search for an 8 character string ...

final private static String andvariants[]=
   {"AND", "aND", "AnD", "ANd", "anD", "and", "And", "aNd"};
final private static String notvariants[]=
   {"NOT", "nOT", "NoT", "NOt", "noT", "not", "Not", "nOt"};
final private static String orvariants[]=
   {"OR", "Or", "oR", "or"};


/* Returns the index of the next occurrance of "AND" in 
 * <code>expression</code>starting from <code>begin</code>,
 * without regard to case, or -1 if "AND" cannot be found.
 */
private static int findAnd(String expression, int begin)
{
    boolean found=false;
    int min=expression.length();
       
    for (int i=0; i<andvariants.length; i++)
    {
        if (expression.indexOf(andvariants[i], begin)!=-1
            && expression.indexOf(andvariants[i], begin)<min)
        {
            found=true;
            min=expression.indexOf(andvariants[i], begin);
        }
    }
    return (found ? min : -1);
}

/* Returns the index of the next occurrance of "OR" in 
 * <code>expression</code>starting from <code>begin</code>,
 * without regard to case, or -1 if "OR" cannot be found.
 */
private static int findOr(String expression, int begin)
{
    boolean found=false;
    int min=expression.length();
       
    for (int i=0; i<orvariants.length; i++)
    {
        if (expression.indexOf(orvariants[i], begin)!=-1
            && expression.indexOf(orvariants[i], begin)<min)
        {
            found=true;
            min=expression.indexOf(orvariants[i], begin);
        }
    }
    return (found ? min : -1);
}

/* Returns the index of the next occurrance of "NOT" in 
 * <code>expression</code>starting from <code>begin</code>,
 * without regard to case, or -1 if "NOT" cannot be found.
 */
private static int findNot(String expression, int begin)
{
    boolean found=false;
    int min=expression.length();
       
    for (int i=0; i<notvariants.length; i++)
    {
        if (expression.indexOf(notvariants[i], begin)!=-1
            && expression.indexOf(notvariants[i], begin)<min)
        {
            found=true;
            min=expression.indexOf(notvariants[i], begin);
        }
    }
    return (found ? min : -1);
}