001package edu.wpi.first.wpilibj.networktables2.util; 002 003/** 004 * A helper super class for collections that use a resizing array 005 * 006 * @author Mitchell 007 * 008 */ 009public class ResizeableArrayObject { 010 private static final int GROW_FACTOR = 3; 011 012 protected Object[] array; 013 014 protected ResizeableArrayObject(){ 015 this(10); 016 } 017 protected ResizeableArrayObject(int initialSize){ 018 array = new Object[initialSize]; 019 } 020 protected int arraySize(){ 021 return array.length; 022 } 023 protected void ensureSize(int size){ 024 if(size>array.length){ 025 int newSize = array.length; 026 while(size>newSize) 027 newSize *= GROW_FACTOR; 028 Object[] newArray = new Object[newSize]; 029 System.arraycopy(array, 0, newArray, 0, array.length); 030 array = newArray; 031 } 032 } 033}