//Default Index Values
int indexOne = -1;
int indexTwo = -1;
//Loop through Array
for(int i = 0;i<nextFreeIndex;i++)
{
/* If indexOne has not been set and the current Object is
* equal to Object one, set indexOne. Note the order of the
* conditions in the if statement. This is to maximize
* efficiency. When JAVA checks the statements that include
* AND, if the first statement is false, it doesn't even
* evaluate the proceeding conditions. Doing it this way
* increases efficiency because it doesn't need to check entries[i]
* and one for equality if indexOne has been set. Also note the
* use of .equals to compare objects instead of the == for numbers
*/
if(indexOne==-1 && entries[i].equals(one))
{
//Set IndexOne
indexOne = i;
/* Check if indexTwo has been set. If it has, then we
* know we have found both of our variables and we can
* stop looping. We stop the loop with the break; statement.
*/
if(indexTwo!=-1)
break;
}
//Check if indexTwo has been set.
if(indexTwo==-1 && entires[i].equals(two))
{
//Set IndexTwo
indexTwo = i;
//Check if indexOne has been set.
if(indexOne!=-1)
break;
}
/* This will continue to loop either both variables have been set or
* the loop reaches the end. We do not check indexOne and indexTwo for
* being set after the if statements, because that means the check will
* occur each time the loop is ran. By having the checks in each if
* statement, it only checks both variables when at least one of them
* has been found.
*/
}
//Check if either indexes were not found. If one wasn't found, return false.
if(indexOne==-1 || indexTwo==-1)
return false;