Clean up UnboundedIntArray

This commit is contained in:
Dustin 2022-01-23 09:21:11 -07:00
parent 3daa74dceb
commit b90333af02
2 changed files with 12 additions and 3 deletions

View File

@ -1,13 +1,15 @@
package com.google.android.exoplayer2.extractor.avi; package com.google.android.exoplayer2.extractor.avi;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.VisibleForTesting;
import java.util.Arrays; import java.util.Arrays;
public class UnboundedIntArray { public class UnboundedIntArray {
@NonNull @NonNull
@VisibleForTesting
int[] array; int[] array;
//unint //unint
int size =0; private int size =0;
public UnboundedIntArray() { public UnboundedIntArray() {
this(8); this(8);
@ -32,7 +34,9 @@ public class UnboundedIntArray {
} }
public void pack() { public void pack() {
array = Arrays.copyOf(array, size); if (size != array.length) {
array = Arrays.copyOf(array, size);
}
} }
protected void grow() { protected void grow() {
@ -40,6 +44,11 @@ public class UnboundedIntArray {
array = Arrays.copyOf(array, increase + array.length + size); array = Arrays.copyOf(array, increase + array.length + size);
} }
public int[] getArray() {
pack();
return array;
}
/** /**
* Only works if values are in sequential order * Only works if values are in sequential order
* @param v * @param v

View File

@ -9,7 +9,7 @@ public class UnboundedIntArrayTest {
final UnboundedIntArray unboundedIntArray = new UnboundedIntArray(); final UnboundedIntArray unboundedIntArray = new UnboundedIntArray();
unboundedIntArray.add(4); unboundedIntArray.add(4);
Assert.assertEquals(1, unboundedIntArray.getSize()); Assert.assertEquals(1, unboundedIntArray.getSize());
Assert.assertEquals(unboundedIntArray.array[0], 4); Assert.assertEquals(unboundedIntArray.getArray()[0], 4);
} }
@Test @Test