I need to be able to search through multiple 2D arrays and search the data in the array and compare it to the data being put into the method when it is called. I tried to use .getClass().getSimpleName() however that only returns int[][] which all of the arrays i am searching through are of this type so it will not help me distinguish between them.
I am using this series of code to determine the proper array to call:
public void tempSelection78 (int fRate, int wbTemp, int rcTons, int a, int r)
{
setTitle(TONS_05_78.getClass().getSimpleName());
for (int model = 0; model < 7; model++)
{
String tonChart = tons78FCharts[model];
for (int col = 0; col < 9; col++)
{
for (int row = 0; row < 8; row++)
{
int t = 0;
if (tonChart.equals(TONS_03_78.getClass().getSimpleName()))
{
t = TONS_03_78[col][row];
}
if (tonChart.equals(TONS_04_78.getClass().getSimpleName()))
{
t = TONS_04_78[col][row];
}
if (tonChart.equals(TONS_05_78.getClass().getSimpleName()))
{
t = TONS_05_78[col][row];
}
if (tonChart.equals(TONS_07_78.getClass().getSimpleName()))
{
t = TONS_07_78[col][row];
}
if (tonChart.equals(TONS_09_78.getClass().getSimpleName()))
{
t = TONS_09_78[col][row];
}
if (tonChart.equals(TONS_11_78.getClass().getSimpleName()))
{
t = TONS_11_78[col][row];
}
if (tonChart.equals(TONS_15_78.getClass().getSimpleName()))
{
t = TONS_15_78[col][row];
}
if (rcTons == t)
{
tableButton = new JButton(new ImageIcon(tablesFor78[model], tablesFor78[model]));
break;
}
else
{
tableButton = new JButton(new ImageIcon("CANNOT_FIND_MODEL.GIF", "SCROLL"));
}
}
}
}
for (int model = 0; model < 7; model++)
{
String flowChart = flow78FCharts[model];
for (int col = 0; col < 9; col++)
{
for (int row = 0; row < 8; row++)
{
int t = 0;
if (flowChart.equals(FLOW_03_78.getClass().getSimpleName()))
{
t = FLOW_03_78[col][row];
}
if (flowChart.equals(FLOW_04_78.getClass().getSimpleName()))
{
t = FLOW_04_78[col][row];
}
if (flowChart.equals(FLOW_05_78.getClass().getSimpleName()))
{
t = FLOW_05_78[col][row];
}
if (flowChart.equals(FLOW_07_78.getClass().getSimpleName()))
{
t = FLOW_07_78[col][row];
}
if (flowChart.equals(FLOW_09_78.getClass().getSimpleName()))
{
t = FLOW_09_78[col][row];
}
if (flowChart.equals(FLOW_11_78.getClass().getSimpleName()))
{
t = FLOW_11_78[col][row];
}
if (flowChart.equals(FLOW_15_78.getClass().getSimpleName()))
{
t = FLOW_15_78[col][row];
}
if (fRate == t)
{
tableButton = new JButton(new ImageIcon(tablesFor78[model], tablesFor78[model]));
break;
}
else
{
tableButton = new JButton(new ImageIcon("CANNOT_FIND_MODEL.GIF", "SCROLL"));
}
}
}
}
what i want to happen is the tonChart be set to one of the strings containing the possible 2d arrays to search through which it does. However the .getClass().getSimpleName never gets set to anything other than int[][] and causes the program to always divert to the else statement at the end of each triple nested loop.
any suggestions?
Here is an example of the arrays that are called:
public final int [][] TONS_03_78 =
{{27, 32, 37, 41, 45, 48, -1, -1, -1},
{-1, 41, 45, 50, 55, 59, 64, 68, 70},
{-1, 49, 55, 60, 65, 70, 75, 80, 85},
{-1, -1, 64, 70, 75, 81, 86, 91, 97},
{-1, -1, -1, 80, 86, 92, 98, 103, 109},
{-1, -1, -1, -1, 97, 103, 109, 116, 122},
{-1, -1, -1, -1, -1, 114, 122, 128, 135},
{-1, -1, -1, -1, -1, -1, -1, -1, -1}};
public final int [][] FLOW_03_78 =
{{205, 160, 137, 122, 112, 103, -1, -1, -1},
{-1, 203, 170, 150, 137, 127, 120, 113, 105},
{-1, 245, 205, 180, 163, 150, 140, 133, 127},
{-1, -1, 240, 210, 188, 173, 162, 152, 145},
{-1, -1, -1, 240, 215, 197, 183, 172, 163},
{-1, -1, -1, -1, 242, 220, 205, 193, 183},
{-1, -1, -1, -1, -1, 245, 228, 213, 202},
{-1, -1, -1, -1, -1, -1, -1, -1, -1}};
I’d change your Paradigm.
I’m not entirely sure what your specific problem is, so the following approach might change, but If I were you, I’d build a class or a struct which contains a 2-d array and then some sort of identifier. (it can be a string, or an int, or an enum, or whatever else you want).
Not only will that kind of approach reduce your code size, but It will make it more readable for both you and us.