package clarity.decoder.prop;

import java.util.ArrayList;
import java.util.List;

import clarity.decoder.EntityBitStream;
import clarity.decoder.Util;
import clarity.model.Prop;

public class ArrayDecoder implements PropDecoder<List<Object>> {

    @Override
    public List<Object> decode(EntityBitStream stream, Prop prop) {
        int count = stream.readNumericBits(Util.calcBitsNeededFor(prop.getNumElements() - 1));
        List<Object> result = new ArrayList<Object>(count);
        PropDecoder<?> decoder = prop.getTemplate().getType().getDecoder();
        while (count > 0) {
            count--;
            Object x = decoder.decode(stream, prop.getTemplate());
            result.add(x);
        }
        return result;
    }

}

@@ -30,63 +30,8 @@
 %0D%0A%0D%0A
-import java.util.ArrayList;%0D%0Aimport java.util.List;%0D%0A%0D%0A
 impo
@@ -176,28 +176,24 @@
 Decoder%3C
-List%3C
 Object
-%3E
+%5B%5D
 %3E %7B%0D%0A%0D%0A 
@@ -217,28 +217,24 @@
  public 
-List%3C
 Object
-%3E
+%5B%5D
  decode(
@@ -375,28 +375,24 @@
         
-List%3C
 Object
-%3E
+%5B%5D
  result 
@@ -401,32 +401,21 @@
 new 
-ArrayList%3C
 Object
-%3E(
+%5B
 count
-)
+%5D
 ;%0D%0A 
@@ -502,49 +502,47 @@
     
-while (count %3E 0) %7B%0D%0A           
+int i = 0;%0D%0A        while (i %3C
  count
---;
+) %7B
 %0D%0A  
@@ -555,16 +555,17 @@
     
-Object x
+result%5Bi%5D
  = d
@@ -624,21 +624,11 @@
     
-result.add(x)
+i++
 ;%0D%0A 

make array decoder return an array instead of a list