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