I am developing an application where with a certain number of rows and columns it is automatically generated using JQuery with the JQuery-Seat-Charts library .
In principle, I manage to do this generation perfectly through AJAX functions that send the request to the application and through Java; I create the map that the library requires.
An example of seats would be the following:
[
'aaa___aaa',
'aaaa_aaaa',
'aaaa_aaaa'
]
Where the 'a' would be seats and the '_' would be gaps. The problem I have is in the automatic generation of numbers that the library itself has, since the end user wants to be able to assign the numbers by hand, for this the library has a resource to overwrite these numbers directly on the map, like so:
[
'a[,NUMBUTACA1]a[,NUMBUTACA1]a___a[,NUMBUTACA1]aa',
'aaaa_aaaa[,JUST_LABEL1]',
'aaaa_aaaa'
]
And finally here comes the question: currently I save the map in a Java String and then I enable a function so that the user goes numbering the seats himself, with which I have to, after each 'a' add the necessary brackets to it. The problem is that currently, to make any changes to the seats, I am reading the String taking their positions (separating the lines with line breaks and iterating the String for each letter of the line) like so:
String[] lineas = mapa.split(SALTO_LINEA);
String[] pos = posicion.split("_");
int fila = Integer.valueOf(pos[0]) - 1;
int columna = Integer.valueOf(pos[1]) - 1;
for (int i = 0; i < lineas.length; i++) {
String linea = lineas[i];
for (int j = 0; j < linea.length(); j++) {
if (i == fila && j == columna) {
if (linea.charAt(j) == 'a') {
resultado += HUECO;
} else {
resultado += ASIENTO;
}
} else {
resultado += linea.charAt(j);
}
}
resultado += SALTO_LINEA;
}
and I see that if I start adding the brackets behind each seat this will no longer work for me since in the case of, for example, a[,2]_aa
to touch the last seat I would have to add 4 to the real position to match.
How could I add these brackets without compromising the positions? (or if there is some function either in Java or JQuery where I can do this in a more or less efficient way).
My recommendation is that you do not work on inappropriate formats and that you carry out the appropriate conversions (usually from A to B and from B to A is enough).
I have not understood the specific problem very well, but basically I suggest that you represent your data in a comfortable way to operate with them, for example your room could be an array of array of seat objects.
Suppose the seats
where
toFormat
it converts that seat to whatever representation it is (in your case something like_
ora[34]
or whatever you need (which I'm not clear on).Now to convert the string to your representation you can do
and the same for, given an array of seats, generate the final string
With this, we can see an example (which also serves as a test) that verifies the invariance of the identity resulting from combining the two previous conversions (if you have A you pass it to B and that B you pass it to A then you have the same as at the beginning if all went well).
With this, you can now easily work with your seats because they are objects in an array.
NOTE: the example array results in: