001: /*
002: * $Id: Arrays.java,v 1.2 2002/09/16 08:05:07 jkl Exp $
003: *
004: * Copyright (c) 2002 Njet Communications Ltd. All Rights Reserved.
005: *
006: * Use is subject to license terms, as defined in
007: * Anvil Sofware License, Version 1.1. See LICENSE
008: * file, or http://njet.org/license-1.1.txt
009: */
010: package anvil.util;
011:
012: public class Arrays {
013:
014: public static final boolean[] extend(boolean[] array) {
015: int length = array.length;
016: boolean[] newarray = new boolean[length + 1];
017: System.arraycopy(array, 0, newarray, 0, length);
018: return newarray;
019: }
020:
021: public static final char[] extend(char[] array) {
022: int length = array.length;
023: char[] newarray = new char[length + 1];
024: System.arraycopy(array, 0, newarray, 0, length);
025: return newarray;
026: }
027:
028: public static final short[] extend(short[] array) {
029: int length = array.length;
030: short[] newarray = new short[length + 1];
031: System.arraycopy(array, 0, newarray, 0, length);
032: return newarray;
033: }
034:
035: public static final int[] extend(int[] array) {
036: int length = array.length;
037: int[] newarray = new int[length + 1];
038: System.arraycopy(array, 0, newarray, 0, length);
039: return newarray;
040: }
041:
042: public static final long[] extend(long[] array) {
043: int length = array.length;
044: long[] newarray = new long[length + 1];
045: System.arraycopy(array, 0, newarray, 0, length);
046: return newarray;
047: }
048:
049: public static final float[] extend(float[] array) {
050: int length = array.length;
051: float[] newarray = new float[length + 1];
052: System.arraycopy(array, 0, newarray, 0, length);
053: return newarray;
054: }
055:
056: public static final double[] extend(double[] array) {
057: int length = array.length;
058: double[] newarray = new double[length + 1];
059: System.arraycopy(array, 0, newarray, 0, length);
060: return newarray;
061: }
062:
063: public static final String[] extend(String[] array) {
064: int length = array.length;
065: String[] newarray = new String[length + 1];
066: System.arraycopy(array, 0, newarray, 0, length);
067: return newarray;
068: }
069:
070: public static final Object[] extend(Object[] array) {
071: int length = array.length;
072: Object[] newarray = new Object[length + 1];
073: System.arraycopy(array, 0, newarray, 0, length);
074: return newarray;
075: }
076:
077: public static final Object[] extend(Object[] array, Class ofType) {
078: int length = array.length;
079: Object[] newarray = (Object[]) java.lang.reflect.Array
080: .newInstance(ofType, length);
081: System.arraycopy(array, 0, newarray, 0, length);
082: return newarray;
083: }
084:
085: public static final boolean[] extend(boolean[] array, int newlength) {
086: boolean[] newarray = new boolean[newlength];
087: System.arraycopy(array, 0, newarray, 0, array.length);
088: return newarray;
089: }
090:
091: public static final char[] extend(char[] array, int newlength) {
092: char[] newarray = new char[newlength];
093: System.arraycopy(array, 0, newarray, 0, array.length);
094: return newarray;
095: }
096:
097: public static final short[] extend(short[] array, int newlength) {
098: short[] newarray = new short[newlength];
099: System.arraycopy(array, 0, newarray, 0, array.length);
100: return newarray;
101: }
102:
103: public static final int[] extend(int[] array, int newlength) {
104: int[] newarray = new int[newlength];
105: System.arraycopy(array, 0, newarray, 0, array.length);
106: return newarray;
107: }
108:
109: public static final long[] extend(long[] array, int newlength) {
110: long[] newarray = new long[newlength];
111: System.arraycopy(array, 0, newarray, 0, array.length);
112: return newarray;
113: }
114:
115: public static final float[] extend(float[] array, int newlength) {
116: float[] newarray = new float[newlength];
117: System.arraycopy(array, 0, newarray, 0, array.length);
118: return newarray;
119: }
120:
121: public static final double[] extend(double[] array, int newlength) {
122: double[] newarray = new double[newlength];
123: System.arraycopy(array, 0, newarray, 0, array.length);
124: return newarray;
125: }
126:
127: public static final String[] extend(String[] array, int newlength) {
128: String[] newarray = new String[newlength];
129: System.arraycopy(array, 0, newarray, 0, array.length);
130: return newarray;
131: }
132:
133: public static final Object[] extend(Object[] array, int newlength) {
134: Object[] newarray = new Object[newlength];
135: System.arraycopy(array, 0, newarray, 0, array.length);
136: return newarray;
137: }
138:
139: public static final Object[] extend(Object[] array, int newlength,
140: Class ofType) {
141: Object[] newarray = (Object[]) java.lang.reflect.Array
142: .newInstance(ofType, newlength);
143: System.arraycopy(array, 0, newarray, 0, array.length);
144: return newarray;
145: }
146:
147: public static final boolean[] append(boolean[] array, boolean item) {
148: int length = array.length;
149: boolean[] newarray = new boolean[length + 1];
150: System.arraycopy(array, 0, newarray, 0, length);
151: newarray[length] = item;
152: return newarray;
153: }
154:
155: public static final char[] append(char[] array, char item) {
156: int length = array.length;
157: char[] newarray = new char[length + 1];
158: System.arraycopy(array, 0, newarray, 0, length);
159: newarray[length] = item;
160: return newarray;
161: }
162:
163: public static final short[] append(short[] array, short item) {
164: int length = array.length;
165: short[] newarray = new short[length + 1];
166: System.arraycopy(array, 0, newarray, 0, length);
167: newarray[length] = item;
168: return newarray;
169: }
170:
171: public static final int[] append(int[] array, int item) {
172: int length = array.length;
173: int[] newarray = new int[length + 1];
174: System.arraycopy(array, 0, newarray, 0, length);
175: newarray[length] = item;
176: return newarray;
177: }
178:
179: public static final long[] append(long[] array, long item) {
180: int length = array.length;
181: long[] newarray = new long[length + 1];
182: System.arraycopy(array, 0, newarray, 0, length);
183: newarray[length] = item;
184: return newarray;
185: }
186:
187: public static final float[] append(float[] array, float item) {
188: int length = array.length;
189: float[] newarray = new float[length + 1];
190: System.arraycopy(array, 0, newarray, 0, length);
191: newarray[length] = item;
192: return newarray;
193: }
194:
195: public static final double[] append(double[] array, double item) {
196: int length = array.length;
197: double[] newarray = new double[length + 1];
198: System.arraycopy(array, 0, newarray, 0, length);
199: newarray[length] = item;
200: return newarray;
201: }
202:
203: public static final String[] append(String[] array, String item) {
204: int length = array.length;
205: String[] newarray = new String[length + 1];
206: System.arraycopy(array, 0, newarray, 0, length);
207: newarray[length] = item;
208: return newarray;
209: }
210:
211: public static final Object[] append(Object[] array, Object item) {
212: int length = array.length;
213: Object[] newarray = new Object[length + 1];
214: System.arraycopy(array, 0, newarray, 0, length);
215: newarray[length] = item;
216: return newarray;
217: }
218:
219: public static final Object[] append(Object[] array, Class ofType,
220: Object item) {
221: int length = array.length;
222: Object[] newarray = (Object[]) java.lang.reflect.Array
223: .newInstance(ofType, length);
224: System.arraycopy(array, 0, newarray, 0, length);
225: newarray[length] = item;
226: return newarray;
227: }
228:
229: }
|