Hello NormR1.
Thank you for responding.
The getNumber() method is supposed to select the smallest array contained within the Object array. The small array, which is assigned to number, feeds into another method for finding the intersection between the query array and the other simple arrays contained in the Object array.
Now, I have adjusted the code to show what miniNumber and Size are doing. It does select the smallest array in the collection, but the logic seems faulty. By the way, I have played around with the "if" statement combinations, to no avail.
public static int getNumber(Object[] collections)
{
int number = 0;
int count = 0;
int size = 0;
/*locate smallest array for query.*/
for(int i = 0; i < collections.length; i++)
{
Arrays.sort((Comparable[])collections[i]);
size = ((Comparable[])collections[i]).length - 1;
int miniNumber = ((Comparable[]) collections[number]).length - 1;
System.out.println(size + "size"); //Identify size variable.
System.out.println(miniNumber + "miniNumber"); //Identify miniNumber variable.
/*Here is where I am trying to make the comparison.*/
if(miniNumber > size)
{
number = i;
System.out.println("Query is array " + number);
}
}
return number; //Number is supposed to contain one array.
}
Here is the driver.
public static void main(String[] args)
{
Integer[] collection1 = {1, 2, 3, 4};
Integer[] collection2 = {1, 2, 3, 4, 5, 6, 7};
Integer[] collection3 = {1, 2, 3, 4, 5};
Integer[] collection4 = {1, 2, 3, 4, 5, 6};
Object[] storeAllArray = {collection2, collection1, collection3};
System.out.println(CommonElements.findCommonElements(storeAllArray));
System.out.println("Comparisons: " + CommonElements.getComparisons());
}
Here is the output.
6size
6miniNumber
3size
6miniNumber
Query is array 1
4size
3miniNumber
Do I need another for loop or do I have to increment miniNumber? Any suggestions? As stated before, I have tried several combinations.
Thanks for taking the time to help.
Sharon