1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 package org.openoffice.xmerge.util; 25 26 import java.util.ArrayList; 27 import java.lang.Integer; 28 29 /** 30 * This is a convenience class used to create an 31 * <code>ArrayList</code> of integers. 32 */ 33 public class IntArrayList { 34 35 /** The list to hold our integers. */ 36 private ArrayList list; 37 38 /** 39 * Constructor. 40 * Creates the list with 0 length. 41 */ IntArrayList()42 public IntArrayList() { 43 list = new ArrayList(); 44 } 45 46 47 /** 48 * Constructor. 49 * 50 * @param initialCapacity Initial capacity of the list. 51 */ IntArrayList(int initialCapacity)52 public IntArrayList(int initialCapacity) { 53 list = new ArrayList(initialCapacity); 54 } 55 56 57 /** 58 * This method ensures that the list is large enough for 59 * <code>minCapacity</code> elements. 60 * 61 * @param minCapacity The minimum capacity of the list. 62 */ ensureCapacity(int minCapacity)63 public void ensureCapacity(int minCapacity) { 64 65 list.ensureCapacity(minCapacity); 66 } 67 68 69 /** 70 * This method ensures that the list is large enough for 71 * <code>minCapacity</code> elements. It also fills in the 72 * new slots in the list with the integer value input as 73 * <code>fillValue</code>. 74 * 75 * @param minCapacity The minimum capacity of the list. 76 * @param fillValue This method adds in a integer for each 77 * slot that was added to ensure that the 78 * list meets the minimum capacity. 79 * <code>fillValue</code> is the value 80 * used as the initial value of these 81 * added elements. 82 */ ensureCapacityAndFill(int minCapacity, int fillValue)83 public void ensureCapacityAndFill(int minCapacity, int fillValue) { 84 85 list.ensureCapacity(minCapacity); 86 87 int needToAdd = minCapacity - list.size(); 88 if (needToAdd > 0) { 89 for (int i = 0; i < needToAdd; i++) { 90 list.add(new Integer(fillValue)); 91 } 92 } 93 } 94 95 96 /** 97 * This method sets an element of the list to the input 98 * integer value. 99 * 100 * @param index The index in the list of the element 101 * we wish to set. 102 * @param value The integer value that we assign to the 103 * selected element of the list. 104 */ set(int index, int value)105 public void set(int index, int value) { 106 list.set(index, new Integer(value)); 107 } 108 109 110 /** 111 * This method appends an element to the list. 112 * 113 * @param value The integer value that we assign to the 114 * element that we are appending to the list. 115 */ add(int value)116 public void add(int value) { 117 list.add(new Integer(value)); 118 } 119 120 121 /** 122 * This method gets the integer value stored in element index. 123 * 124 * @param index The index in the list of the element 125 * we wish to get the value from. 126 * 127 * @return The value of the data stored in element index. 128 */ get(int index)129 public int get(int index) { 130 return ((Integer)list.get(index)).intValue(); 131 } 132 133 134 /** 135 * This method gets the size of the list. 136 * 137 * @return The size of the list. 138 */ size()139 public int size() { 140 return list.size(); 141 } 142 } 143 144