1 /* SizeSequence.java --
2 Copyright (C) 2002 Free Software Foundation, Inc.
4 This file is part of GNU Classpath.
6 GNU Classpath is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 GNU Classpath is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Classpath; see the file COPYING. If not, write to the
18 Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
21 Linking this library statically or dynamically with other modules is
22 making a combined work based on this library. Thus, the terms and
23 conditions of the GNU General Public License cover the whole
26 As a special exception, the copyright holders of this library give you
27 permission to link this library with independent modules to produce an
28 executable, regardless of the license terms of these independent
29 modules, and to copy and distribute the resulting executable under
30 terms of your choice, provided that you also meet, for each linked
31 independent module, the terms and conditions of the license of that
32 module. An independent module is a module which is not derived from
33 or based on this library. If you modify this library, you may extend
34 this exception to your version of the library, but you are not
35 obligated to do so. If you do not wish to do so, delete this
36 exception statement from your version. */
42 * @author Andrew Selkirk
45 public class SizeSequence {
47 //-------------------------------------------------------------
48 // Variables --------------------------------------------------
49 //-------------------------------------------------------------
54 private int[] sizes = new int[0];
57 //-------------------------------------------------------------
58 // Initialization ---------------------------------------------
59 //-------------------------------------------------------------
62 * Constructor SizeSequence
64 public SizeSequence() {
69 * Constructor SizeSequence
70 * @param numEntries TODO
72 public SizeSequence(int numEntries) {
77 * Constructor SizeSequence
78 * @param numEntries TODO
81 public SizeSequence(int numEntries, int value) {
82 insertEntries(0, numEntries, value);
86 * Constructor SizeSequence
89 public SizeSequence(int[] sizes) {
94 //-------------------------------------------------------------
95 // Methods ----------------------------------------------------
96 //-------------------------------------------------------------
103 public void setSize(int index, int size) {
109 * @param position TODO
112 public int getIndex(int position) {
121 public int getSize(int index) {
129 public void setSizes(int[] sizes) {
135 this.sizes = new int[sizes.length];
136 for (index = 0; index < sizes.length; index++) {
137 this.sizes[index] = sizes[index];
146 public int[] getSizes() {
153 array = new int[sizes.length];
154 for (index = 0; index < sizes.length; index++) {
155 array[index] = sizes[index];
158 // Return Newly created array
168 public int getPosition(int index) {
176 for (loop = 0; loop < index; loop++) {
177 position += sizes[loop];
191 public void insertEntries(int start, int length, int value) {
200 array = new int[sizes.length + length];
202 for (index = 0; index < sizes.length; index++) {
203 if (index == start) {
204 for (loop = 0; loop < length; loop++) {
205 array[arrayIndex] = value;
209 array[arrayIndex] = sizes[index];
221 public void removeEntries(int start, int length) {
229 if ((start + length) > sizes.length) {
230 throw new IllegalArgumentException("Specified start/length that " +
231 "is greater than available sizes");
235 array = new int[sizes.length - length];
237 for (index = 0; index < sizes.length; index++) {
238 if (index == start) {
241 array[arrayIndex] = sizes[index];