/* Given an FTS, returns a new FTS having the same fields as the given
** one, but in the opposite order.
** Algorithm: Let the given FTS be x_0;x_1;x_2;...;x_n.
** This version employs a loop each iteration of which "adds" one more
** field to beginning of the FTS under construction, so that, after the
** k-th loop iteration, the FTS under construction has value
** x[k-1];x[k-2];x[k-3]; ... ;x[0];
*/
public static String reverseOf1(String fts) {
final int N = numberOfFields(fts);
String result = "";
for (int k=0; k != N; k = k+1) {
// place the k-th field of fts at the beginning of 'result'
String fieldToInsert = getField(fts,k);
result = fieldToInsert + ";" + result;
// alternative having same effect as line above:
//result = insertField(result, 0, fieldToInsert);
}
return result;
}
|