Commit b90333af by Dustin

Clean up UnboundedIntArray

parent 3daa74dc
package com.google.android.exoplayer2.extractor.avi;
import androidx.annotation.NonNull;
import androidx.annotation.VisibleForTesting;
import java.util.Arrays;
public class UnboundedIntArray {
@NonNull
@VisibleForTesting
int[] array;
//unint
int size =0;
private int size =0;
public UnboundedIntArray() {
this(8);
......@@ -32,7 +34,9 @@ public class UnboundedIntArray {
}
public void pack() {
array = Arrays.copyOf(array, size);
if (size != array.length) {
array = Arrays.copyOf(array, size);
}
}
protected void grow() {
......@@ -40,6 +44,11 @@ public class UnboundedIntArray {
array = Arrays.copyOf(array, increase + array.length + size);
}
public int[] getArray() {
pack();
return array;
}
/**
* Only works if values are in sequential order
* @param v
......
......@@ -9,7 +9,7 @@ public class UnboundedIntArrayTest {
final UnboundedIntArray unboundedIntArray = new UnboundedIntArray();
unboundedIntArray.add(4);
Assert.assertEquals(1, unboundedIntArray.getSize());
Assert.assertEquals(unboundedIntArray.array[0], 4);
Assert.assertEquals(unboundedIntArray.getArray()[0], 4);
}
@Test
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment