1/* GENERATED SOURCE. DO NOT MODIFY. */
2/*
3 *******************************************************************************
4 * Copyright (C) 2014, International Business Machines Corporation and
5 * others. All Rights Reserved.
6 *******************************************************************************
7 *
8 * created on: 2014feb10
9 * created by: Markus W. Scherer
10 */
11package android.icu.impl.coll;
12
13// TODO: There must be a Java class for a growable array of ints without auto-boxing to Integer?!
14// Keep the API parallel to the C++ version for ease of porting. Port methods only as needed.
15// If & when we start using something else, we might keep this as a thin wrapper for porting.
16/**
17 * @hide Only a subset of ICU is exposed in Android
18 */
19public final class UVector32 {
20    public UVector32() {}
21    public boolean isEmpty() { return length == 0; }
22    public int size() { return length; }
23    public int elementAti(int i) { return buffer[i]; }
24    public int[] getBuffer() { return buffer; }
25    public void addElement(int e) {
26        ensureAppendCapacity();
27        buffer[length++] = e;
28    }
29    public void setElementAt(int elem, int index) { buffer[index] = elem; }
30    public void insertElementAt(int elem, int index) {
31        ensureAppendCapacity();
32        System.arraycopy(buffer, index, buffer, index + 1, length - index);
33        buffer[index] = elem;
34        ++length;
35    }
36    public void removeAllElements() {
37        length = 0;
38    }
39
40    private void ensureAppendCapacity() {
41        if(length >= buffer.length) {
42            int newCapacity = buffer.length <= 0xffff ? 4 * buffer.length : 2 * buffer.length;
43            int[] newBuffer = new int[newCapacity];
44            System.arraycopy(buffer, 0, newBuffer, 0, length);
45            buffer = newBuffer;
46        }
47    }
48    private int[] buffer = new int[32];
49    private int length = 0;
50}
51