I have the following concern for which I am looking for the best solution, if possible in Java. I clarify, that the routine of for
includes an error that is just the origin of the concern.
I declare constants, for example:
Map<String, Map<Integer, String>> mAlgo = new HashMap();
Map<Integer, String> mPartes = new HashMap();
String[] aPartes = {"top", "left", ...};
String[] aEstados = {"Solido", "Flexible", ...};
String[][] topSolido = {
{"parte11", "parte12", "parte13"},
{"parte21", "parte22", "parte23"},
...
};
String[][] topFlexible = {
{"parte11", "parte12", "parte13"},
{"parte21", "parte22", "parte23"},
...
};
String[][] leftSolido = {
{"parte11", "parte12", "parte13"},
{"parte21", "parte22", "parte23"},
...
};
String[][] leftFlexible = {
{"parte11", "parte12", "parte13"},
{"parte21", "parte22", "parte23"},
...
};
for (String sParte : aPartes) {
for (String sEstado : aEstados) {
String sEnsamble = sParte + sEstado;
for (int f=0; f<sEnsamble.length; f++) {
for (int c=0; c<sEnsamble[f].length; c++) {
mPartes.put(c, sEnsamble[f][c]);
}
mAlgo.put(sEnsamble, mPartes);
mPartes.clear();
}
}
}
The crucial part of the exercise is that it throws an obvious error, it is when you try to traverse the variable, as if it were outside the matrix to which its value refers. After the next assignment:
String sEnsamble = sParte + sEstado;
That is ...
for (int f=0; f<sEnsamble.length; f++) {
...
}
This in practice causes sEnsamble
to take the values "topSolido"
, "topFlexible"
, "leftSolido"
, "leftFlexible"
successively, which match the names of each one of the matrices previously declared.
Is there a mechanism in Java that allows you to do something similar to what is proposed? o Is it possible to load map information "mAlgo"
with the proposed structure Map<String, Map<Integer, String>>
as a constant eg: "M_ALGO"
from the beginning without having to perform this conversion in any method?