tags:

views:

90

answers:

1

Please explain this code to me; I don't understand why the additional vector TempC is needed:

Vector A = new Vector();
Vector B = R.funcVector("TemporaryVector");

if(B!=null)
{
  for(int i=0;i<B.size();i++)
  {
    Vector TempC = new Vector();
    Vector D = new Vector();

    TempC = (Vector)B.elementAt(i);

     if(...)
     {
        D.addElement(TempC.elementAt(1);

        // ...

        A.addElement(D);
     }
  }
}
+1  A: 

First a question - did you write this code or can you blame somebody else? It is incorrect and quite obfuscated. Java has at least some naming conventions...

In this code - or at least, in the corrected version - you're storing vectors inside vectors. You take a Vector from B, assign it to a local variable, add the first element from this vector to vector A and the whole vector A to D.

You don't need 'TempC', but it adds at least a minimum of clarity to the code ;)

You could do a

D.addElement(((Vector) B.getElementAt(i)).elementAt(1));

aswell.

Edit

Here's the de-obfuscated code - at least how I understand it ;):

Vector<Vector<Object>> a = new Vector<Vector<Object>>();
Vector<Vector<Object>> b = createVector(r, "TemporaryVector");

if (b != null) {
  for(Vector<Object> tempC: b) {
    Vector d = new Vector<Object>();

    if(isOk()) {
      d.addElement(TempC.elementAt(1));

      // more calculations

      a.addElement(d);
    }
  }
}
Andreas_D