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