Java/Collections Data Structure/Array Insert Remove
Версия от 18:01, 31 мая 2010; (обсуждение)
Содержание
- 1 Adds all the elements of the given arrays into a new boolean-value array.
- 2 Adds all the elements of the given arrays into a new byte-type array.
- 3 Adds all the elements of the given arrays into a new char-type array.
- 4 Adds all the elements of the given arrays into a new double-type array.
- 5 Adds all the elements of the given arrays into a new float-type array.
- 6 Adds all the elements of the given arrays into a new int-type array.
- 7 Adds all the elements of the given arrays into a new long-type array.
- 8 Adds all the elements of the given arrays into a new short-type array.
- 9 Array Copy Utilities
- 10 Concatenate Java arrays
- 11 Copies the given array and adds the given element at the end of the new array.(boolean value type)
- 12 Copies the given array and adds the given element at the end of the new array.(byte value type)
- 13 Copies the given array and adds the given element at the end of the new array. (char type value)
- 14 Copies the given array and adds the given element at the end of the new array.(double type value)
- 15 Copies the given array and adds the given element at the end of the new array. (float type value)
- 16 Copies the given array and adds the given element at the end of the new array.(int value type)
- 17 Copies the given array and adds the given element at the end of the new array. (long value type)
- 18 Copies the given array and adds the given element at the end of the new array. (object value type)
- 19 Copies the given array and adds the given element at the end of the new array.(short type array)
- 20 Inserts the specified element at the specified position in the array.
- 21 Inserts the specified element at the specified position in the boolean-type-value array.
- 22 Inserts the specified element at the specified position in the byte-type-value array.
- 23 Inserts the specified element at the specified position in the char-type-value array.
- 24 Inserts the specified element at the specified position in the double-type-value array.
- 25 Inserts the specified element at the specified position in the float-value-type array.
- 26 Inserts the specified element at the specified position in the int-type-value array.
- 27 Inserts the specified element at the specified position in the long-type-value array.
- 28 Inserts the specified element at the specified position in the short-value-type array.
- 29 Insert value to array
- 30 Removes the element at the specified position from the specified array.
- 31 Removes the element at the specified position from the specified long type array.
- 32 Removes the first occurrence of the specified element from the specified array.
- 33 Removes the first occurrence of the specified element from the specified long value array.
Adds all the elements of the given arrays into a new boolean-value array.
/* Copyright 2004 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import java.lang.reflect.Array;
/**
* <p>Operations on arrays, primitive arrays (like <code>int[]</code>) and
* primitive wrapper arrays (like <code>Integer[]</code>).</p>
*
* <p>This class tries to handle <code>null</code> input gracefully.
* An exception will not be thrown for a <code>null</code>
* array input. However, an Object array that contains a <code>null</code>
* element may throw an exception. Each method documents its behaviour.</p>
*
* @author Stephen Colebourne
* @author Moritz Petersen
* @author
* @author Maarten Coene
* @since 2.0
* @version $Id: ArrayUtils.java 632503 2008-03-01 00:21:52Z ggregory $
*/
public class Main {
/**
* <p>Adds all the elements of the given arrays into a new array.</p>
* <p>The new array contains all of the element of <code>array1</code> followed
* by all of the elements <code>array2</code>. When an array is returned, it is always
* a new array.</p>
*
* <pre>
* ArrayUtils.addAll(array1, null) = cloned copy of array1
* ArrayUtils.addAll(null, array2) = cloned copy of array2
* ArrayUtils.addAll([], []) = []
* </pre>
*
* @param array1 the first array whose elements are added to the new array.
* @param array2 the second array whose elements are added to the new array.
* @return The new boolean[] array.
* @since 2.1
*/
public static boolean[] addAll(boolean[] array1, boolean[] array2) {
if (array1 == null) {
return clone(array2);
} else if (array2 == null) {
return clone(array1);
}
boolean[] joinedArray = new boolean[array1.length + array2.length];
System.arraycopy(array1, 0, joinedArray, 0, array1.length);
System.arraycopy(array2, 0, joinedArray, array1.length, array2.length);
return joinedArray;
}
/**
* <p>Shallow clones an array returning a typecast result and handling
* <code>null</code>.</p>
*
* <p>The objects in the array are not cloned, thus there is no special
* handling for multi-dimensional arrays.</p>
*
* <p>This method returns <code>null</code> for a <code>null</code> input array.</p>
*
* @param array the array to shallow clone, may be <code>null</code>
* @return the cloned array, <code>null</code> if <code>null</code> input
*/
public static boolean[] clone(boolean[] array) {
if (array == null) {
return null;
}
return (boolean[]) array.clone();
}
}
Adds all the elements of the given arrays into a new byte-type array.
/* Copyright 2004 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import java.lang.reflect.Array;
/**
* <p>Operations on arrays, primitive arrays (like <code>int[]</code>) and
* primitive wrapper arrays (like <code>Integer[]</code>).</p>
*
* <p>This class tries to handle <code>null</code> input gracefully.
* An exception will not be thrown for a <code>null</code>
* array input. However, an Object array that contains a <code>null</code>
* element may throw an exception. Each method documents its behaviour.</p>
*
* @author Stephen Colebourne
* @author Moritz Petersen
* @author
* @author Maarten Coene
* @since 2.0
* @version $Id: ArrayUtils.java 632503 2008-03-01 00:21:52Z ggregory $
*/
public class Main {
/**
* <p>Adds all the elements of the given arrays into a new array.</p>
* <p>The new array contains all of the element of <code>array1</code> followed
* by all of the elements <code>array2</code>. When an array is returned, it is always
* a new array.</p>
*
* <pre>
* ArrayUtils.addAll(array1, null) = cloned copy of array1
* ArrayUtils.addAll(null, array2) = cloned copy of array2
* ArrayUtils.addAll([], []) = []
* </pre>
*
* @param array1 the first array whose elements are added to the new array.
* @param array2 the second array whose elements are added to the new array.
* @return The new byte[] array.
* @since 2.1
*/
public static byte[] addAll(byte[] array1, byte[] array2) {
if (array1 == null) {
return clone(array2);
} else if (array2 == null) {
return clone(array1);
}
byte[] joinedArray = new byte[array1.length + array2.length];
System.arraycopy(array1, 0, joinedArray, 0, array1.length);
System.arraycopy(array2, 0, joinedArray, array1.length, array2.length);
return joinedArray;
}
/**
* <p>Shallow clones an array returning a typecast result and handling
* <code>null</code>.</p>
*
* <p>The objects in the array are not cloned, thus there is no special
* handling for multi-dimensional arrays.</p>
*
* <p>This method returns <code>null</code> for a <code>null</code> input array.</p>
*
* @param array the array to shallow clone, may be <code>null</code>
* @return the cloned array, <code>null</code> if <code>null</code> input
*/
public static byte[] clone(byte[] array) {
if (array == null) {
return null;
}
return (byte[]) array.clone();
}
}
Adds all the elements of the given arrays into a new char-type array.
/* Copyright 2004 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import java.lang.reflect.Array;
/**
* <p>Operations on arrays, primitive arrays (like <code>int[]</code>) and
* primitive wrapper arrays (like <code>Integer[]</code>).</p>
*
* <p>This class tries to handle <code>null</code> input gracefully.
* An exception will not be thrown for a <code>null</code>
* array input. However, an Object array that contains a <code>null</code>
* element may throw an exception. Each method documents its behaviour.</p>
*
* @author Stephen Colebourne
* @author Moritz Petersen
* @author
* @author Maarten Coene
* @since 2.0
* @version $Id: ArrayUtils.java 632503 2008-03-01 00:21:52Z ggregory $
*/
public class Main {
/**
* <p>Adds all the elements of the given arrays into a new array.</p>
* <p>The new array contains all of the element of <code>array1</code> followed
* by all of the elements <code>array2</code>. When an array is returned, it is always
* a new array.</p>
*
* <pre>
* ArrayUtils.addAll(array1, null) = cloned copy of array1
* ArrayUtils.addAll(null, array2) = cloned copy of array2
* ArrayUtils.addAll([], []) = []
* </pre>
*
* @param array1 the first array whose elements are added to the new array.
* @param array2 the second array whose elements are added to the new array.
* @return The new char[] array.
* @since 2.1
*/
public static char[] addAll(char[] array1, char[] array2) {
if (array1 == null) {
return clone(array2);
} else if (array2 == null) {
return clone(array1);
}
char[] joinedArray = new char[array1.length + array2.length];
System.arraycopy(array1, 0, joinedArray, 0, array1.length);
System.arraycopy(array2, 0, joinedArray, array1.length, array2.length);
return joinedArray;
}
/**
* <p>Shallow clones an array returning a typecast result and handling
* <code>null</code>.</p>
*
* <p>The objects in the array are not cloned, thus there is no special
* handling for multi-dimensional arrays.</p>
*
* <p>This method returns <code>null</code> for a <code>null</code> input array.</p>
*
* @param array the array to shallow clone, may be <code>null</code>
* @return the cloned array, <code>null</code> if <code>null</code> input
*/
public static char[] clone(char[] array) {
if (array == null) {
return null;
}
return (char[]) array.clone();
}
}
Adds all the elements of the given arrays into a new double-type array.
/* Copyright 2004 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import java.lang.reflect.Array;
/**
* <p>Operations on arrays, primitive arrays (like <code>int[]</code>) and
* primitive wrapper arrays (like <code>Integer[]</code>).</p>
*
* <p>This class tries to handle <code>null</code> input gracefully.
* An exception will not be thrown for a <code>null</code>
* array input. However, an Object array that contains a <code>null</code>
* element may throw an exception. Each method documents its behaviour.</p>
*
* @author Stephen Colebourne
* @author Moritz Petersen
* @author
* @author Maarten Coene
* @since 2.0
* @version $Id: ArrayUtils.java 632503 2008-03-01 00:21:52Z ggregory $
*/
public class Main {
/**
* <p>Adds all the elements of the given arrays into a new array.</p>
* <p>The new array contains all of the element of <code>array1</code> followed
* by all of the elements <code>array2</code>. When an array is returned, it is always
* a new array.</p>
*
* <pre>
* ArrayUtils.addAll(array1, null) = cloned copy of array1
* ArrayUtils.addAll(null, array2) = cloned copy of array2
* ArrayUtils.addAll([], []) = []
* </pre>
*
* @param array1 the first array whose elements are added to the new array.
* @param array2 the second array whose elements are added to the new array.
* @return The new double[] array.
* @since 2.1
*/
public static double[] addAll(double[] array1, double[] array2) {
if (array1 == null) {
return clone(array2);
} else if (array2 == null) {
return clone(array1);
}
double[] joinedArray = new double[array1.length + array2.length];
System.arraycopy(array1, 0, joinedArray, 0, array1.length);
System.arraycopy(array2, 0, joinedArray, array1.length, array2.length);
return joinedArray;
}
/**
* <p>Shallow clones an array returning a typecast result and handling
* <code>null</code>.</p>
*
* <p>The objects in the array are not cloned, thus there is no special
* handling for multi-dimensional arrays.</p>
*
* <p>This method returns <code>null</code> for a <code>null</code> input array.</p>
*
* @param array the array to shallow clone, may be <code>null</code>
* @return the cloned array, <code>null</code> if <code>null</code> input
*/
public static double[] clone(double[] array) {
if (array == null) {
return null;
}
return (double[]) array.clone();
}
}
Adds all the elements of the given arrays into a new float-type array.
/* Copyright 2004 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import java.lang.reflect.Array;
/**
* <p>Operations on arrays, primitive arrays (like <code>int[]</code>) and
* primitive wrapper arrays (like <code>Integer[]</code>).</p>
*
* <p>This class tries to handle <code>null</code> input gracefully.
* An exception will not be thrown for a <code>null</code>
* array input. However, an Object array that contains a <code>null</code>
* element may throw an exception. Each method documents its behaviour.</p>
*
* @author Stephen Colebourne
* @author Moritz Petersen
* @author
* @author Maarten Coene
* @since 2.0
* @version $Id: ArrayUtils.java 632503 2008-03-01 00:21:52Z ggregory $
*/
public class Main {
/**
* <p>Adds all the elements of the given arrays into a new array.</p>
* <p>The new array contains all of the element of <code>array1</code> followed
* by all of the elements <code>array2</code>. When an array is returned, it is always
* a new array.</p>
*
* <pre>
* ArrayUtils.addAll(array1, null) = cloned copy of array1
* ArrayUtils.addAll(null, array2) = cloned copy of array2
* ArrayUtils.addAll([], []) = []
* </pre>
*
* @param array1 the first array whose elements are added to the new array.
* @param array2 the second array whose elements are added to the new array.
* @return The new float[] array.
* @since 2.1
*/
public static float[] addAll(float[] array1, float[] array2) {
if (array1 == null) {
return clone(array2);
} else if (array2 == null) {
return clone(array1);
}
float[] joinedArray = new float[array1.length + array2.length];
System.arraycopy(array1, 0, joinedArray, 0, array1.length);
System.arraycopy(array2, 0, joinedArray, array1.length, array2.length);
return joinedArray;
}
/**
* <p>Shallow clones an array returning a typecast result and handling
* <code>null</code>.</p>
*
* <p>The objects in the array are not cloned, thus there is no special
* handling for multi-dimensional arrays.</p>
*
* <p>This method returns <code>null</code> for a <code>null</code> input array.</p>
*
* @param array the array to shallow clone, may be <code>null</code>
* @return the cloned array, <code>null</code> if <code>null</code> input
*/
public static float[] clone(float[] array) {
if (array == null) {
return null;
}
return (float[]) array.clone();
}
}
Adds all the elements of the given arrays into a new int-type array.
/* Copyright 2004 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import java.lang.reflect.Array;
/**
* <p>Operations on arrays, primitive arrays (like <code>int[]</code>) and
* primitive wrapper arrays (like <code>Integer[]</code>).</p>
*
* <p>This class tries to handle <code>null</code> input gracefully.
* An exception will not be thrown for a <code>null</code>
* array input. However, an Object array that contains a <code>null</code>
* element may throw an exception. Each method documents its behaviour.</p>
*
* @author Stephen Colebourne
* @author Moritz Petersen
* @author
* @author Maarten Coene
* @since 2.0
* @version $Id: ArrayUtils.java 632503 2008-03-01 00:21:52Z ggregory $
*/
public class Main {
/**
* <p>Adds all the elements of the given arrays into a new array.</p>
* <p>The new array contains all of the element of <code>array1</code> followed
* by all of the elements <code>array2</code>. When an array is returned, it is always
* a new array.</p>
*
* <pre>
* ArrayUtils.addAll(array1, null) = cloned copy of array1
* ArrayUtils.addAll(null, array2) = cloned copy of array2
* ArrayUtils.addAll([], []) = []
* </pre>
*
* @param array1 the first array whose elements are added to the new array.
* @param array2 the second array whose elements are added to the new array.
* @return The new int[] array.
* @since 2.1
*/
public static int[] addAll(int[] array1, int[] array2) {
if (array1 == null) {
return clone(array2);
} else if (array2 == null) {
return clone(array1);
}
int[] joinedArray = new int[array1.length + array2.length];
System.arraycopy(array1, 0, joinedArray, 0, array1.length);
System.arraycopy(array2, 0, joinedArray, array1.length, array2.length);
return joinedArray;
}
/**
* <p>Shallow clones an array returning a typecast result and handling
* <code>null</code>.</p>
*
* <p>The objects in the array are not cloned, thus there is no special
* handling for multi-dimensional arrays.</p>
*
* <p>This method returns <code>null</code> for a <code>null</code> input array.</p>
*
* @param array the array to shallow clone, may be <code>null</code>
* @return the cloned array, <code>null</code> if <code>null</code> input
*/
public static int[] clone(int[] array) {
if (array == null) {
return null;
}
return (int[]) array.clone();
}
}
Adds all the elements of the given arrays into a new long-type array.
/* Copyright 2004 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import java.lang.reflect.Array;
/**
* <p>Operations on arrays, primitive arrays (like <code>int[]</code>) and
* primitive wrapper arrays (like <code>Integer[]</code>).</p>
*
* <p>This class tries to handle <code>null</code> input gracefully.
* An exception will not be thrown for a <code>null</code>
* array input. However, an Object array that contains a <code>null</code>
* element may throw an exception. Each method documents its behaviour.</p>
*
* @author Stephen Colebourne
* @author Moritz Petersen
* @author
* @author Maarten Coene
* @since 2.0
* @version $Id: ArrayUtils.java 632503 2008-03-01 00:21:52Z ggregory $
*/
public class Main {
/**
* <p>Adds all the elements of the given arrays into a new array.</p>
* <p>The new array contains all of the element of <code>array1</code> followed
* by all of the elements <code>array2</code>. When an array is returned, it is always
* a new array.</p>
*
* <pre>
* ArrayUtils.addAll(array1, null) = cloned copy of array1
* ArrayUtils.addAll(null, array2) = cloned copy of array2
* ArrayUtils.addAll([], []) = []
* </pre>
*
* @param array1 the first array whose elements are added to the new array.
* @param array2 the second array whose elements are added to the new array.
* @return The new long[] array.
* @since 2.1
*/
public static long[] addAll(long[] array1, long[] array2) {
if (array1 == null) {
return clone(array2);
} else if (array2 == null) {
return clone(array1);
}
long[] joinedArray = new long[array1.length + array2.length];
System.arraycopy(array1, 0, joinedArray, 0, array1.length);
System.arraycopy(array2, 0, joinedArray, array1.length, array2.length);
return joinedArray;
}
/**
* <p>Shallow clones an array returning a typecast result and handling
* <code>null</code>.</p>
*
* <p>The objects in the array are not cloned, thus there is no special
* handling for multi-dimensional arrays.</p>
*
* <p>This method returns <code>null</code> for a <code>null</code> input array.</p>
*
* @param array the array to shallow clone, may be <code>null</code>
* @return the cloned array, <code>null</code> if <code>null</code> input
*/
public static long[] clone(long[] array) {
if (array == null) {
return null;
}
return (long[]) array.clone();
}
}
Adds all the elements of the given arrays into a new short-type array.
/* Copyright 2004 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import java.lang.reflect.Array;
/**
* <p>Operations on arrays, primitive arrays (like <code>int[]</code>) and
* primitive wrapper arrays (like <code>Integer[]</code>).</p>
*
* <p>This class tries to handle <code>null</code> input gracefully.
* An exception will not be thrown for a <code>null</code>
* array input. However, an Object array that contains a <code>null</code>
* element may throw an exception. Each method documents its behaviour.</p>
*
* @author Stephen Colebourne
* @author Moritz Petersen
* @author
* @author Maarten Coene
* @since 2.0
* @version $Id: ArrayUtils.java 632503 2008-03-01 00:21:52Z ggregory $
*/
public class Main {
/**
* <p>Adds all the elements of the given arrays into a new array.</p>
* <p>The new array contains all of the element of <code>array1</code> followed
* by all of the elements <code>array2</code>. When an array is returned, it is always
* a new array.</p>
*
* <pre>
* ArrayUtils.addAll(array1, null) = cloned copy of array1
* ArrayUtils.addAll(null, array2) = cloned copy of array2
* ArrayUtils.addAll([], []) = []
* </pre>
*
* @param array1 the first array whose elements are added to the new array.
* @param array2 the second array whose elements are added to the new array.
* @return The new short[] array.
* @since 2.1
*/
public static short[] addAll(short[] array1, short[] array2) {
if (array1 == null) {
return clone(array2);
} else if (array2 == null) {
return clone(array1);
}
short[] joinedArray = new short[array1.length + array2.length];
System.arraycopy(array1, 0, joinedArray, 0, array1.length);
System.arraycopy(array2, 0, joinedArray, array1.length, array2.length);
return joinedArray;
}
/**
* <p>Shallow clones an array returning a typecast result and handling
* <code>null</code>.</p>
*
* <p>The objects in the array are not cloned, thus there is no special
* handling for multi-dimensional arrays.</p>
*
* <p>This method returns <code>null</code> for a <code>null</code> input array.</p>
*
* @param array the array to shallow clone, may be <code>null</code>
* @return the cloned array, <code>null</code> if <code>null</code> input
*/
public static short[] clone(short[] array) {
if (array == null) {
return null;
}
return (short[]) array.clone();
}
}
Array Copy Utilities
// Revised from marf
import java.util.ruparator;
import java.util.Vector;
/**
* <p><code>marf.util.Arrays</code> is an extension of <code>java.util.Arrays</code>
* to group a lot of commonly used arrays-related functionality in one place. This class
* can do whatever <code>java.util.Arrays</code> can, plus allows copying array portions,
* including cases when the source and destination arrays are of different types, and providing
* array-to-Vector and array-to-delimited-String conversions. For the type-conversion
* routines a proper casting to the destination type is performed when needed. It also
* allows inheritance from the class, so that anyone wishing to extend it is welcome to
* do so without the pain of re-wrapping the methods.</p>
*
* TODO: optimize.
*
* <p>NOTE: the <code>java.util.Arrays</code> compliance is true as of JDK 1.4.</p>
*
* <p>NOTE: it does not actually inherit (extend) from <code>java.util.Arrays</code>, but rather wraps
* existing methods, plus adds the <code>copy()</code> wrappers of <code>System.arraycopy()</code>,
* and <code>arrayToVector()</code> methods.</p>
*
* <p>$Id: Arrays.java,v 1.38 2006/09/09 17:26:58 mokhov Exp $</p>
*
* @author Serguei Mokhov
* @author Shuxin Fan
*
* @version $Revision: 1.38 $
* @since 0.3.0.1
*
* @see java.util.Arrays
* @see System#arraycopy(Object, int, Object, int, int)
*/
public class Arrays
{
/**
* The protected default constructor is provided
* to allow making extension of this class if
* developers desire to do so. Normally, you would
* not need to instantiate this class, but in order
* not to re-wrap our calls in possible extensions
* this constructor is available.
*/
protected Arrays()
{
}
/*
* -------
* Copying
* -------
*/
/**
* Generic <code>copy()</code> routine is based on <code>System.arraycopy()</code>.
*
* @param poDestination destination array of copy
* @param piDestinationStartIndex where in the destination array start placing the values
* @param poSource source of elements
* @param piSourceStartIndex where in the source array start copying the values from
* @param piHowMany how many elements should be copied from the source to destination
*/
public static void copy
(
Object poDestination,
final int piDestinationStartIndex,
Object poSource,
final int piSourceStartIndex,
final int piHowMany
)
{
System.arraycopy
(
poSource,
piSourceStartIndex,
poDestination,
piDestinationStartIndex,
piHowMany
);
}
/**
* Generic <code>copy()</code> routine is based on <code>System.arraycopy()</code>
* for Object arrays.
*
* @param paoDestination destination array of objects to copy to
* @param piDestinationStartIndex where in the destination array start placing the values
* @param paoSource source of Object elements
* @param piSourceStartIndex where in the source array start copying the values from
* @param piHowMany how many elements should be copied from the source to destination
*/
public static void copy
(
Object[] paoDestination,
final int piDestinationStartIndex,
Object[] paoSource,
final int piSourceStartIndex,
final int piHowMany
)
{
System.arraycopy
(
paoSource,
piSourceStartIndex,
paoDestination,
piDestinationStartIndex,
piHowMany
);
}
/**
* Copies N boolean elements from source to destination starting at certain index in the <b>destination</b>.
* A wrapper call to <code>System.arraycopy()</code>.
*
* @param pabDestination array to copy to
* @param piDestinationStartIndex starting index in the destination to start copying to
* @param pabSource array of booleans to copy from
* @param piSourceStartIndex starting index in the source to start copying from
* @param piHowMany N; the number of elements to copy from the source to the destination
*/
public static void copy
(
boolean[] pabDestination,
final int piDestinationStartIndex,
boolean[] pabSource,
final int piSourceStartIndex,
final int piHowMany
)
{
System.arraycopy
(
pabSource,
piSourceStartIndex,
pabDestination,
piDestinationStartIndex,
piHowMany
);
}
/**
* Copies N byte elements from source to destination starting at certain index in the <b>destination</b>.
* A wrapper call to <code>System.arraycopy()</code>.
*
* @param patDestination array to copy to
* @param piDestinationStartIndex starting index in the destination to start copying to
* @param patSource array of bytes to copy from
* @param piSourceStartIndex starting index in the source to start copying from
* @param piHowMany N; the number of elements to copy from the source to the destination
*/
public static void copy
(
byte[] patDestination,
final int piDestinationStartIndex,
byte[] patSource,
final int piSourceStartIndex,
final int piHowMany
)
{
System.arraycopy
(
patSource,
piSourceStartIndex,
patDestination,
piDestinationStartIndex,
piHowMany
);
}
/**
* Copies N character elements from source to destination starting at certain index in the <b>destination</b>.
* A wrapper call to <code>System.arraycopy()</code>.
*
* @param pacDestination array to copy to
* @param piDestinationStartIndex starting index in the destination to start copying to
* @param pacSource array of characters to copy from
* @param piSourceStartIndex starting index in the source to start copying from
* @param piHowMany N; the number of elements to copy from the source to the destination
*/
public static void copy
(
char[] pacDestination,
final int piDestinationStartIndex,
char[] pacSource,
final int piSourceStartIndex,
final int piHowMany
)
{
System.arraycopy
(
pacSource,
piSourceStartIndex,
pacDestination,
piDestinationStartIndex,
piHowMany
);
}
/**
* Copies N integer elements from source to destination starting at certain index in the <b>destination</b>.
* A wrapper call to <code>System.arraycopy()</code>.
*
* @param paiDestination array to copy to
* @param piDestinationStartIndex starting index in the destination to start copying to
* @param paiSource array of integers to copy from
* @param piSourceStartIndex starting index in the source to start copying from
* @param piHowMany N; the number of elements to copy from the source to the destination
*/
public static void copy
(
int[] paiDestination,
final int piDestinationStartIndex,
int[] paiSource,
final int piSourceStartIndex,
final int piHowMany
)
{
System.arraycopy
(
paiSource,
piSourceStartIndex,
paiDestination,
piDestinationStartIndex,
piHowMany
);
}
/**
* Copies N short elements from source to destination starting at certain index in the <b>destination</b>.
* A wrapper call to <code>System.arraycopy()</code>.
*
* @param pasDestination array to copy to
* @param piDestinationStartIndex starting index in the destination to start copying to
* @param pasSource array of shorts to copy from
* @param piSourceStartIndex starting index in the source to start copying from
* @param piHowMany N; the number of elements to copy from the source to the destination
*/
public static void copy
(
short[] pasDestination,
final int piDestinationStartIndex,
short[] pasSource,
final int piSourceStartIndex,
final int piHowMany
)
{
System.arraycopy
(
pasSource,
piSourceStartIndex,
pasDestination,
piDestinationStartIndex,
piHowMany
);
}
/**
* Copies N long elements from source to destination starting at certain index in the <b>destination</b>.
* A wrapper call to <code>System.arraycopy()</code>.
*
* @param palDestination array to copy to
* @param piDestinationStartIndex starting index in the destination to start copying to
* @param palSource array of longs to copy from
* @param piSourceStartIndex starting index in the source to start copying from
* @param piHowMany N; the number of elements to copy from the source to the destination
*/
public static void copy
(
long[] palDestination,
final int piDestinationStartIndex,
long[] palSource,
final int piSourceStartIndex,
final int piHowMany
)
{
System.arraycopy
(
palSource,
piSourceStartIndex,
palDestination,
piDestinationStartIndex,
piHowMany
);
}
/**
* Copies N float elements from source to destination starting at certain index in the <b>destination</b>.
* A wrapper call to <code>System.arraycopy()</code>.
*
* @param pafDestination array to copy to
* @param piDestinationStartIndex starting index in the destination to start copying to
* @param pafSource array of float to copy from
* @param piSourceStartIndex starting index in the source to start copying from
* @param piHowMany N; the number of elements to copy from the source to the destination
*/
public static void copy
(
float[] pafDestination,
final int piDestinationStartIndex,
float[] pafSource,
final int piSourceStartIndex,
final int piHowMany
)
{
System.arraycopy
(
pafSource,
piSourceStartIndex,
pafDestination,
piDestinationStartIndex,
piHowMany
);
}
/**
* Copies N double elements from source to destination starting at certain index in the <b>destination</b>.
* A wrapper call to <code>System.arraycopy()</code>.
*
* @param padDestination array to copy to
* @param piDestinationStartIndex starting index in the destination to start copying to
* @param padSource array of doubles to copy from
* @param piSourceStartIndex starting index in the source to start copying from
* @param piHowMany N; the number of elements to copy from the source to the destination
*
* @throws ArrayIndexOutOfBoundsException if one of the indices is out of range
*/
public static void copy
(
double[] padDestination,
final int piDestinationStartIndex,
double[] padSource,
final int piSourceStartIndex,
final int piHowMany
)
{
System.arraycopy
(
padSource,
piSourceStartIndex,
padDestination,
piDestinationStartIndex,
piHowMany
);
}
/**
* Generic <code>copy()</code> routine is based on <code>System.arraycopy()</code>.
*
* @param poDestination destination array of copy
* @param piStartIndex where in the destination array start placing the values
* @param poSource source of elements
* @param piHowMany how many elements should be copied from the source to destination
*/
public static void copy(Object poDestination, final int piStartIndex, Object poSource, final int piHowMany)
{
copy(poDestination, piStartIndex, poSource, 0, piHowMany);
}
/**
* Generic <code>copy()</code> routine is based on <code>System.arraycopy()</code>
* for Object arrays.
*
* @param paoDestination destination array of objects to copy to
* @param piStartIndex where in the destination array start placing the values
* @param paoSource source of Object elements
* @param piHowMany how many elements should be copied from the source to destination
*/
public static void copy(Object[] paoDestination, final int piStartIndex, Object[] paoSource, final int piHowMany)
{
copy(paoDestination, piStartIndex, paoSource, 0, piHowMany);
}
/**
* Copies N character elements from source to destination starting at certain index in the <b>destination</b>.
*
* @param pacDestination array to copy to
* @param piStartIndex starting index in the destination to start copying to
* @param pacSource array of characters to copy from
* @param piHowMany N; the number of elements to copy from the source to the destination
*/
public static void copy(char[] pacDestination, final int piStartIndex, char[] pacSource, final int piHowMany)
{
copy(pacDestination, piStartIndex, pacSource, 0, piHowMany);
}
/**
* Copies N boolean elements from source to destination starting at certain index in the <b>destination</b>.
*
* @param pabDestination array to copy to
* @param piStartIndex starting index in the destination to start copying to
* @param pabSource array of booleans to copy from
* @param piHowMany N; the number of elements to copy from the source to the destination
*/
public static void copy(boolean[] pabDestination, final int piStartIndex, boolean[] pabSource, final int piHowMany)
{
copy(pabDestination, piStartIndex, pabSource, 0, piHowMany);
}
/**
* Copies N byte elements from source to destination starting at certain index in the <b>destination</b>.
*
* @param patDestination array to copy to
* @param piStartIndex starting index in the destination to start copying to
* @param patSource array of bytes to copy from
* @param piHowMany N; the number of elements to copy from the source to the destination
*/
public static void copy(byte[] patDestination, final int piStartIndex, byte[] patSource, final int piHowMany)
{
copy(patDestination, piStartIndex, patSource, 0, piHowMany);
}
/**
* Copies N integer elements from source to destination starting at certain index in the <b>destination</b>.
*
* @param paiDestination array to copy to
* @param piStartIndex starting index in the destination to start copying to
* @param paiSource array of integers to copy from
* @param piHowMany N; the number of elements to copy from the source to the destination
*/
public static void copy(int[] paiDestination, final int piStartIndex, int[] paiSource, final int piHowMany)
{
copy(paiDestination, piStartIndex, paiSource, 0, piHowMany);
}
/**
* Copies N short elements from source to destination starting at certain index in the <b>destination</b>.
*
* @param pasDestination array to copy to
* @param piStartIndex starting index in the destination to start copying to
* @param pasSource array of shorts to copy from
* @param piHowMany N; the number of elements to copy from the source to the destination
*/
public static void copy(short[] pasDestination, final int piStartIndex, short[] pasSource, final int piHowMany)
{
copy(pasDestination, piStartIndex, pasSource, 0, piHowMany);
}
/**
* Copies N long elements from source to destination starting at certain index in the <b>destination</b>.
*
* @param palDestination array to copy to
* @param piStartIndex starting index in the destination to start copying to
* @param palSource array of longs to copy from
* @param piHowMany N; the number of elements to copy from the source to the destination
*/
public static void copy(long[] palDestination, final int piStartIndex, long[] palSource, final int piHowMany)
{
copy(palDestination, piStartIndex, palSource, 0, piHowMany);
}
/**
* Copies N float elements from source to destination starting at certain index in the <b>destination</b>.
*
* @param pafDestination array to copy to
* @param piStartIndex starting index in the destination to start copying to
* @param pafSource array of floats to copy from
* @param piHowMany N; the number of elements to copy from the source to the destination
*/
public static void copy(float[] pafDestination, final int piStartIndex, float[] pafSource, final int piHowMany)
{
copy(pafDestination, piStartIndex, pafSource, 0, piHowMany);
}
/**
* Copies N double elements from source to destination starting at certain index in the <b>destination</b>.
*
* @param padDestination array to copy to
* @param piStartIndex starting index in the destination to start copying to
* @param padSource array of doubles to copy from
* @param piHowMany N; the number of elements to copy from the source to the destination
*/
public static void copy(double[] padDestination, final int piStartIndex, double[] padSource, final int piHowMany)
{
copy(padDestination, piStartIndex, padSource, 0, piHowMany);
}
/**
* Generic <code>copy()</code> routine is based on <code>System.arraycopy()</code>
* for Object arrays.
*
* @param paoDestination destination array of objects to copy to
* @param piStartIndex starting index in the destination to start copying to
* @param paoSource source of object elements
*/
public static void copy(Object[] paoDestination, final int piStartIndex, Object[] paoSource)
{
copy(paoDestination, piStartIndex, paoSource, paoSource.length);
}
/**
* Copies source to destination starting at certain index in the <b>destination</b>.
*
* @param pabDestination array to copy to
* @param piStartIndex starting index in the destination to start copying to
* @param pabSource array of booleans to copy from
*/
public static void copy(boolean[] pabDestination, final int piStartIndex, boolean[] pabSource)
{
copy(pabDestination, piStartIndex, pabSource, pabSource.length);
}
/**
* Copies source to destination starting at certain index in the <b>destination</b>.
*
* @param patDestination array to copy to
* @param piStartIndex starting index in the destination to start copying to
* @param patSource array of bytes to copy from
*/
public static void copy(byte[] patDestination, final int piStartIndex, byte[] patSource)
{
copy(patDestination, piStartIndex, patSource, patSource.length);
}
/**
* Copies source to destination starting at certain index in the <b>destination</b>.
*
* @param pacDestination array to copy to
* @param piStartIndex starting index in the destination to start copying to
* @param pacSource array of characters to copy from
*/
public static void copy(char[] pacDestination, final int piStartIndex, char[] pacSource)
{
copy(pacDestination, piStartIndex, pacSource, pacSource.length);
}
/**
* Copies source to destination starting at certain index in the <b>destination</b>.
*
* @param paiDestination array to copy to
* @param piStartIndex starting index in the destination to start copying to
* @param paiSource array of integers to copy from
*/
public static void copy(int[] paiDestination, final int piStartIndex, int[] paiSource)
{
copy(paiDestination, piStartIndex, paiSource, paiSource.length);
}
/**
* Copies source to destination starting at certain index in the <b>destination</b>.
*
* @param pasDestination array to copy to
* @param piStartIndex starting index in the destination to start copying to
* @param pasSource array of shorts to copy from
*/
public static void copy(short[] pasDestination, final int piStartIndex, short[] pasSource)
{
copy(pasDestination, piStartIndex, pasSource, pasSource.length);
}
/**
* Copies source to destination starting at certain index in the <b>destination</b>.
*
* @param palDestination array to copy to
* @param piStartIndex starting index in the destination to start copying to
* @param palSource array of longs to copy from
*/
public static void copy(long[] palDestination, final int piStartIndex, long[] palSource)
{
copy(palDestination, piStartIndex, palSource, palSource.length);
}
/**
* Copies source to destination starting at certain index in the <b>destination</b>.
*
* @param pafDestination array to copy to
* @param piStartIndex starting index in the destination to start copying to
* @param pafSource array of floats to copy from
*/
public static void copy(float[] pafDestination, final int piStartIndex, float[] pafSource)
{
copy(pafDestination, piStartIndex, pafSource, pafSource.length);
}
/**
* Copies source to destination starting at certain index in the <b>destination</b>.
*
* @param padDestination array to copy to
* @param piStartIndex starting index in the destination to start copying to
* @param padSource array of doubles to copy from
*/
public static void copy(double[] padDestination, final int piStartIndex, double[] padSource)
{
copy(padDestination, piStartIndex, padSource, padSource.length);
}
/**
* Generic <code>copy()</code> routine is based on <code>System.arraycopy()</code>.
*
* @param poDestination destination array of copy
* @param poSource source of elements
* @param piHowMany N; the number of elements to copy from the source to the destination
*/
public static void copy(Object poDestination, Object poSource, final int piHowMany)
{
copy(poDestination, 0, poSource, piHowMany);
}
/**
* Generic <code>copy()</code> routine is based on <code>System.arraycopy()</code>
* for Object arrays.
*
* @param paoDestination array to copy to
* @param paoSource source of object elements
* @param piHowMany N; the number of elements to copy from the source to the destination
*/
public static void copy(Object[] paoDestination, Object[] paoSource, final int piHowMany)
{
copy(paoDestination, 0, paoSource, piHowMany);
}
/**
* Copies N character elements from source to destination.
*
* @param pacDestination array to copy to
* @param pacSource array of characters to copy from
* @param piHowMany N; the number of elements to copy from the source to the destination
*/
public static void copy(char[] pacDestination, char[] pacSource, final int piHowMany)
{
copy(pacDestination, 0, pacSource, piHowMany);
}
/**
* Copies N boolean elements from source to destination.
*
* @param pabDestination array to copy to
* @param pabSource array of boolean to copy from
* @param piHowMany N; the number of elements to copy from the source to the destination
*/
public static void copy(boolean[] pabDestination, boolean[] pabSource, final int piHowMany)
{
copy(pabDestination, 0, pabSource, piHowMany);
}
/**
* Copies N byte elements from source to destination.
*
* @param patDestination array to copy to
* @param patSource array of bytes to copy from
* @param piHowMany N; the number of elements to copy from the source to the destination
*/
public static void copy(byte[] patDestination, byte[] patSource, final int piHowMany)
{
copy(patDestination, 0, patSource, piHowMany);
}
/**
* Copies N short elements from source to destination.
*
* @param pasDestination array to copy to
* @param pasSource array of shorts to copy from
* @param piHowMany N; the number of elements to copy from the source to the destination
*/
public static void copy(short[] pasDestination, short[] pasSource, final int piHowMany)
{
copy(pasDestination, 0, pasSource, piHowMany);
}
/**
* Copies N long elements from source to destination.
*
* @param palDestination array to copy to
* @param palSource array of longs to copy from
* @param piHowMany N; the number of elements to copy from the source to the destination
*/
public static void copy(long[] palDestination, long[] palSource, final int piHowMany)
{
copy(palDestination, 0, palSource, piHowMany);
}
/**
* Copies N float elements from source to destination.
*
* @param pafDestination array to copy to
* @param pafSource array of floats to copy from
* @param piHowMany N; the number of elements to copy from the source to the destination
*/
public static void copy(float[] pafDestination, float[] pafSource, final int piHowMany)
{
copy(pafDestination, 0, pafSource, piHowMany);
}
/**
* Copies N double elements from source to destination.
*
* @param padDestination array to copy to
* @param padSource array of doubles to copy from
* @param piHowMany N; the number of elements to copy from the source to the destination
*/
public static void copy(double[] padDestination, double[] padSource, final int piHowMany)
{
copy(padDestination, 0, padSource, piHowMany);
}
/**
* Copies N int elements from source to destination.
*
* @param paiDestination array to copy to
* @param paiSource array of ints to copy from
* @param piHowMany N; the number of elements to copy from the source to the destination
*/
public static void copy(int[] paiDestination, int[] paiSource, final int piHowMany)
{
copy(paiDestination, 0, paiSource, 0, piHowMany);
}
/*
* -------------
* Concatenation
* -------------
*/
/**
* Concatenates two arrays of objects and returns a newly
* allocated array of the concatenated pieces.
* @param paoLHS first array piece
* @param paoRHS second array piece
* @return new combined array
* @since 0.3.0.4
*/
public static Object[] concatenate(final Object[] paoLHS, final Object[] paoRHS)
{
Object[] aoConcatenated = new Object[paoLHS.length + paoRHS.length];
System.arraycopy(paoLHS, 0, aoConcatenated, 0, paoLHS.length);
System.arraycopy(paoRHS, 0, aoConcatenated, paoLHS.length,paoRHS.length);
return aoConcatenated;
}
/**
* Concatenates two arrays of Strings and returns a newly
* allocated array of the concatenated pieces.
* @param pastrLHS first array piece
* @param pastrRHS second array piece
* @return new combined array
* @since 0.3.0.4
*/
public static String[] concatenate(final String[] pastrLHS, final String[] pastrRHS)
{
String[] astrConcatenated = new String[pastrLHS.length + pastrRHS.length];
System.arraycopy(pastrLHS, 0, astrConcatenated, 0, pastrLHS.length);
System.arraycopy(pastrRHS, 0, astrConcatenated, pastrLHS.length, pastrRHS.length);
return astrConcatenated;
}
/**
* Concatenates two arrays of doubles and returns a newly
* allocated array of the concatenated pieces.
* @param padLHS first array piece
* @param padRHS second array piece
* @return new combined array
* @since 0.3.0.4
*/
public static double[] concatenate(final double[] padLHS, final double[] padRHS)
{
double[] adConcatenated = new double[padLHS.length + padRHS.length];
System.arraycopy(padLHS, 0, adConcatenated, 0, padLHS.length);
System.arraycopy(padRHS, 0, adConcatenated, padLHS.length, padRHS.length);
return adConcatenated;
}
/**
* Concatenates two arrays of booleans and returns a newly
* allocated array of the concatenated pieces.
* @param pabLHS first array piece
* @param pabRHS second array piece
* @return new combined array
* @since 0.3.0.4
*/
public static boolean[] concatenate(final boolean[] pabLHS, final boolean[] pabRHS)
{
boolean[] abConcatenated = new boolean[pabLHS.length + pabRHS.length];
System.arraycopy(pabLHS, 0, abConcatenated, 0, pabLHS.length);
System.arraycopy(pabRHS, 0, abConcatenated, pabLHS.length, pabRHS.length);
return abConcatenated;
}
/**
* Concatenates two arrays of bytes and returns a newly
* allocated array of the concatenated pieces.
* @param patLHS first array piece
* @param patRHS second array piece
* @return new combined array
* @since 0.3.0.4
*/
public static byte[] concatenate(final byte[] patLHS, final byte[] patRHS)
{
byte[] atConcatenated = new byte[patLHS.length + patRHS.length];
System.arraycopy(patLHS, 0, atConcatenated, 0, patLHS.length);
System.arraycopy(patRHS, 0, atConcatenated, patLHS.length, patRHS.length);
return atConcatenated;
}
/**
* Concatenates two arrays of characters and returns a newly
* allocated array of the concatenated pieces.
* @param pacLHS first array piece
* @param pacRHS second array piece
* @return new combined array
* @since 0.3.0.4
*/
public static char[] concatenate(final char[] pacLHS, final char[] pacRHS)
{
char[] acConcatenated = new char[pacLHS.length + pacRHS.length];
System.arraycopy(pacLHS, 0, acConcatenated, 0, pacLHS.length);
System.arraycopy(pacRHS, 0, acConcatenated, pacLHS.length, pacRHS.length);
return acConcatenated;
}
/**
* Concatenates two arrays of integers and returns a newly
* allocated array of the concatenated pieces.
* @param paiLHS first array piece
* @param paiRHS second array piece
* @return new combined array
* @since 0.3.0.4
*/
public static int[] concatenate(final int[] paiLHS, final int[] paiRHS)
{
int[] aiConcatenated = new int[paiLHS.length + paiRHS.length];
System.arraycopy(paiLHS, 0, aiConcatenated, 0, paiLHS.length);
System.arraycopy(paiRHS, 0, aiConcatenated, paiLHS.length, paiRHS.length);
return aiConcatenated;
}
/**
* Concatenates two arrays of shorts and returns a newly
* allocated array of the concatenated pieces.
* @param pasLHS first array piece
* @param pasRHS second array piece
* @return new combined array
* @since 0.3.0.4
*/
public static short[] concatenate(final short[] pasLHS, final short[] pasRHS)
{
short[] asConcatenated = new short[pasLHS.length + pasRHS.length];
System.arraycopy(pasLHS, 0, asConcatenated, 0, pasLHS.length);
System.arraycopy(pasRHS, 0, asConcatenated, pasLHS.length, pasRHS.length);
return asConcatenated;
}
/**
* Concatenates two arrays of floats and returns a newly
* allocated array of the concatenated pieces.
* @param pafLHS first array piece
* @param pafRHS second array piece
* @return new combined array
* @since 0.3.0.4
*/
public static float[] concatenate(final float[] pafLHS, final float[] pafRHS)
{
float[] afConcatenated = new float[pafLHS.length + pafRHS.length];
System.arraycopy(pafLHS, 0, afConcatenated, 0, pafLHS.length);
System.arraycopy(pafRHS, 0, afConcatenated, pafLHS.length, pafRHS.length);
return afConcatenated;
}
/**
* Concatenates two arrays of longs and returns a newly
* allocated array of the concatenated pieces.
* @param palLHS first array piece
* @param palRHS second array piece
* @return new combined array
* @since 0.3.0.4
*/
public static long[] concatenate(final long[] palLHS, final long[] palRHS)
{
long[] alConcatenated = new long[palLHS.length + palRHS.length];
System.arraycopy(palLHS, 0, alConcatenated, 0, palLHS.length);
System.arraycopy(palRHS, 0, alConcatenated, palLHS.length, palRHS.length);
return alConcatenated;
}
/*
* --------
* Equality
* --------
*/
/**
* The <code>equals()</code> routine is based on <code>java.util.Arrays.equals()</code>.
*
* @param pabArray1 the first array of booleans to be compared for equality
* @param pabArray2 the second array of booleans to be compared for equality
* @return a boolean value <code> true </code> if the two arrays are equal
*/
public static boolean equals(boolean[] pabArray1, boolean[] pabArray2)
{
return java.util.Arrays.equals(pabArray1, pabArray2);
}
/**
* The <code>equals()</code> routine is based on <code>java.util.Arrays.equals()</code>.
*
* @param patArray1 the first array of bytes to be compared for equality
* @param patArray2 the second array of bytes to be compared for equality
* @return a boolean value <code> true </code> if the two arrays are equal
*/
public static boolean equals(byte[] patArray1, byte[] patArray2)
{
return java.util.Arrays.equals(patArray1, patArray2);
}
/**
* The <code>equals()</code> routine is based on <code>java.util.Arrays.equals()</code>.
*
* @param pacArray1 the first array of characters to be compared for equality
* @param pacArray2 the second array of characters to be compared for equality
* @return a boolean value <code> true </code> if the two arrays are equal
*/
public static boolean equals(char[] pacArray1, char[] pacArray2)
{
return java.util.Arrays.equals(pacArray1, pacArray2);
}
/**
* The <code>equals()</code> routine is based on <code>java.util.Arrays.equals()</code>.
*
* @param padArray1 the first array of doubles to be compared for equality
* @param padArray2 the second array of doubles to be compared for equality
* @return a boolean value <code> true </code> if the two arrays are equal
*/
public static boolean equals(double[] padArray1, double[] padArray2)
{
return java.util.Arrays.equals(padArray1, padArray2);
}
/**
* The <code>equals()</code> routine is based on <code>java.util.Arrays.equals()</code>.
*
* @param pafArray1 the first array of floats to be compared for equality
* @param pafArray2 the second array of floats to be compared for equality
* @return a boolean value <code> true </code> if the two arrays are equal
*/
public static boolean equals(float[] pafArray1, float[] pafArray2)
{
return java.util.Arrays.equals(pafArray1, pafArray2);
}
/**
* The <code>equals()</code> routine is based on <code>java.util.Arrays.equals()</code>.
*
* @param paiArray1 the first array of integers to be compared for equality
* @param paiArray2 the second array of integers to be compared for equality
* @return a boolean value <code> true </code> if the two arrays are equal
*/
public static boolean equals(int[] paiArray1, int[] paiArray2)
{
return java.util.Arrays.equals(paiArray1, paiArray2);
}
/**
* The <code>equals()</code> routine is based on <code>java.util.Arrays.equals()</code>.
*
* @param palArray1 the first array of longs to be compared for equality
* @param palArray2 the second array of longs to be compared for equality
* @return a boolean value <code> true </code> if the two arrays are equal
*/
public static boolean equals(long[] palArray1, long[] palArray2)
{
return java.util.Arrays.equals(palArray1, palArray2);
}
/**
* The <code>equals()</code> routine is based on <code>java.util.Arrays.equals()</code>.
*
* @param paoArray1 the first array of Objects to be compared for equality
* @param paoArray2 the second array of Objects to be compared for equality
* @return a boolean value <code> true </code> if the two arrays are equal
*/
public static boolean equals(Object[] paoArray1, Object[] paoArray2)
{
return java.util.Arrays.equals(paoArray1, paoArray2);
}
/**
* The <code>equals()</code> routine is based on <code>java.util.Arrays.equals()</code>.
*
* @param pasArray1 the first array of shorts to be compared for equality
* @param pasArray2 the second array of shorts to be compared for equality
* @return a boolean value <code> true </code> if the two arrays are equal
*/
public static boolean equals(short[] pasArray1, short[] pasArray2)
{
return java.util.Arrays.equals(pasArray1, pasArray2);
}
/*
* -------------
* Array filling
* -------------
*/
/**
* The <code>fill()</code> is based on <code>java.util.Arrays.fill()</code>.
*
* @param pabArray the array of booleans to be filled
* @param pbValue the value of boolean to fill into the array of booleans
*/
public static void fill(boolean[] pabArray, boolean pbValue)
{
java.util.Arrays.fill(pabArray, pbValue);
}
/**
* The <code>fill()</code> is based on <code>java.util.Arrays.fill()</code>.
*
* @param pabArray the array of booleans to be filled
* @param piFromIndex the index of the array from here the value to be filled
* @param piToIndex the index one after the last element of the array to be filled
* @param pbValue the value of boolean to fill into the array of booleans
*/
public static void fill(boolean[] pabArray, int piFromIndex, int piToIndex, boolean pbValue)
{
java.util.Arrays.fill(pabArray, piFromIndex, piToIndex, pbValue);
}
/**
* The <code>fill()</code> is based on <code>java.util.Arrays.fill()</code>.
*
* @param patArray the array of bytes to be filled
* @param ptValue the value of byte to fill into the array of bytes
*/
public static void fill(byte[] patArray, byte ptValue)
{
java.util.Arrays.fill(patArray, ptValue);
}
/**
* The <code>fill()</code> is based on <code>java.util.Arrays.fill()</code>.
*
* @param patArray the array of bytes to be filled
* @param piFromIndex the index of the array from here the value to be filled
* @param piToIndex the index one after the last element of the array to be filled
* @param ptValue the value of byte to fill into the array of bytes
*/
public static void fill(byte[] patArray, int piFromIndex, int piToIndex, byte ptValue)
{
java.util.Arrays.fill(patArray, piFromIndex, piToIndex, ptValue);
}
/**
* The <code>fill()</code> is based on <code>java.util.Arrays.fill()</code>.
*
* @param pacArray the array of characters to be filled
* @param pcValue the value of character to fill into the array of characters
*/
public static void fill(char[] pacArray, char pcValue)
{
java.util.Arrays.fill(pacArray, pcValue);
}
/**
* The <code>fill()</code> is based on <code>java.util.Arrays.fill()</code>.
*
* @param pacArray the array of characters to be filled
* @param piFromIndex the index of the array from here the value to be filled
* @param piToIndex the index one after the last element of the array to be filled
* @param pcValue the value of character to fill into the array of characters
*/
public static void fill(char[] pacArray, int piFromIndex, int piToIndex, char pcValue)
{
java.util.Arrays.fill(pacArray, piFromIndex, piToIndex, pcValue);
}
/**
* The <code>fill()</code> is based on <code>java.util.Arrays.fill()</code>.
*
* @param padArray the array of doubles to be filled
* @param pdValue the value of double to fill into the array of doubles
*/
public static void fill(double[] padArray, double pdValue)
{
java.util.Arrays.fill(padArray, pdValue);
}
/**
* The <code>fill()</code> is based on <code>java.util.Arrays.fill()</code>.
*
* @param padArray the array of doubles to be filled
* @param piFromIndex the index of the array from here the value to be filled
* @param piToIndex the index one after the last element of the array to be filled
* @param pdValue the value of double to fill into the array of doubles
*/
public static void fill(double[] padArray, int piFromIndex, int piToIndex, double pdValue)
{
java.util.Arrays.fill(padArray, piFromIndex, piToIndex, pdValue);
}
/**
* The <code>fill()</code> is based on <code>java.util.Arrays.fill()</code>.
*
* @param pafArray the array of floats to be filled
* @param pfValue the value of float to fill into the array of floats
*/
public static void fill(float[] pafArray, float pfValue)
{
java.util.Arrays.fill(pafArray, pfValue);
}
/**
* The <code>fill()</code> is based on <code>java.util.Arrays.fill()</code>.
*
* @param pafArray the array of floats to be filled
* @param piFromIndex the index of the array from here the value to be filled
* @param piToIndex the index one after the last element of the array to be filled
* @param pfValue the value of float to fill into the array of floats
*/
public static void fill(float[] pafArray, int piFromIndex, int piToIndex, float pfValue)
{
java.util.Arrays.fill(pafArray, piFromIndex, piToIndex, pfValue);
}
/**
* The <code>fill()</code> is based on <code>java.util.Arrays.fill()</code>.
*
* @param paiArray the array of integers to be filled
* @param piValue the value of integer to fill into the array of integers
*/
public static void fill(int[] paiArray, int piValue)
{
java.util.Arrays.fill(paiArray, piValue);
}
/**
* The <code>fill()</code> is based on <code>java.util.Arrays.fill()</code>.
*
* @param paiArray the array of integers to be filled
* @param piFromIndex the index of the array from here the value to be filled
* @param piToIndex the index one after the last element of the array to be filled
* @param piValue the value of integer to fill into the array of integers
*/
public static void fill(int[] paiArray, int piFromIndex, int piToIndex, int piValue)
{
java.util.Arrays.fill(paiArray, piFromIndex, piToIndex, piValue);
}
/**
* The <code>fill()</code> is based on <code>java.util.Arrays.fill()</code>.
*
* @param palArray the array of longs to be filled
* @param piFromIndex the index of the array from here the value to be filled
* @param piToIndex the index one after the last element of the array to be filled
* @param plValue the value of long to fill into the array of longs
*/
public static void fill(long[] palArray, int piFromIndex, int piToIndex, long plValue)
{
java.util.Arrays.fill(palArray, piFromIndex, piToIndex, plValue);
}
/**
* The <code>fill()</code> is based on <code>java.util.Arrays.fill()</code>.
*
* @param palArray the array of longs to be filled
* @param plValue the value of long to fill into the array of longs
*/
public static void fill(long[] palArray, long plValue)
{
java.util.Arrays.fill(palArray, plValue);
}
/**
* The <code>fill()</code> is based on <code>java.util.Arrays.fill()</code>.
*
* @param paoArray the array to be filled
* @param piFromIndex the index of the array from here the value to be filled
* @param piToIndex the index one after the last element of the array to be filled
* @param paValue the value to fill into the array
*/
public static void fill(Object[] paoArray, int piFromIndex, int piToIndex, Object paValue)
{
java.util.Arrays.fill(paoArray, piFromIndex, piToIndex, paValue);
}
/**
* The <code>fill()</code> is based on <code>java.util.Arrays.fill()</code>.
*
* @param paoArray the array to be filled
* @param poValue the value to fill into the array
*/
public static void fill(Object[] paoArray, Object poValue)
{
java.util.Arrays.fill(paoArray, poValue);
}
/**
* The <code>fill()</code> is based on <code>java.util.Arrays.fill()</code>.
*
* @param pasArray the array of shorts to be filled
* @param piFromIndex the index of the array from here the value to be filled
* @param piToIndex the index one after the last element of the array to be filled
* @param psValue the value of short to fill into the array of shorts
*/
public static void fill(short[] pasArray, int piFromIndex, int piToIndex, short psValue)
{
java.util.Arrays.fill(pasArray, piFromIndex, piToIndex, psValue);
}
/**
* The <code>fill()</code> is based on <code>java.util.Arrays.fill()</code>.
*
* @param pasArray the array of shorts to be filled
* @param psValue the value of short to fill into the array of shorts
*/
public static void fill(short[] pasArray, short psValue)
{
java.util.Arrays.fill(pasArray, psValue);
}
/**
* Sets all elements of the parameter at pseudo-random order.
* The range of the values is [- Double.MAX_VALUE / 2, Double.MAX_VALUE / 2].
* @param padArray the array to fill
* @since 0.3.0.6
*/
public static void fillRandom(double[] padArray)
{
for(int i = 0; i < padArray.length; i++)
{
padArray[i] = (Math.random() - 0.5) * Double.MAX_VALUE;
}
}
/*
* -------
* Sorting
* -------
*/
/**
* A wrapper of java.util.Arrays.sort(Object[], Comparator).
*
* @param paoArrayToSort array of objects to sort
* @param poComparator comparator object to use while sorting
*/
public static void sort(Object[] paoArrayToSort, Comparator poComparator)
{
java.util.Arrays.sort(paoArrayToSort, poComparator);
}
/**
* A wrapper of java.util.Arrays.sort(double[]).
*
* @param padArrayToSort array of doubles to sort
*/
public static void sort(double[] padArrayToSort)
{
java.util.Arrays.sort(padArrayToSort);
}
/**
* A wrapper of java.util.Arrays.sort(float[]).
*
* @param pafArrayToSort array of float to sort
*/
public static void sort(float[] pafArrayToSort)
{
java.util.Arrays.sort(pafArrayToSort);
}
/**
* A wrapper of java.util.Arrays.sort(int[]).
*
* @param paiArrayToSort array of integers to sort
*/
public static void sort(int[] paiArrayToSort)
{
java.util.Arrays.sort(paiArrayToSort);
}
/**
* A wrapper of java.util.Arrays.sort(byte[]).
*
* @param patArrayToSort array of bytes to sort
*/
public static void sort(byte[] patArrayToSort)
{
java.util.Arrays.sort(patArrayToSort);
}
/**
* A wrapper of java.util.Arrays.sort(char[]).
*
* @param pacArrayToSort array of characters to sort
*/
public static void sort(char[] pacArrayToSort)
{
java.util.Arrays.sort(pacArrayToSort);
}
/**
* A wrapper of java.util.Arrays.sort(double[]).
*
* @param palArrayToSort array of longs to sort
*/
public static void sort(long[] palArrayToSort)
{
java.util.Arrays.sort(palArrayToSort);
}
/**
* A wrapper of java.util.Arrays.sort(short[]).
*
* @param pasArrayToSort array of shorts to sort
*/
public static void sort(short[] pasArrayToSort)
{
java.util.Arrays.sort(pasArrayToSort);
}
/**
* A wrapper of java.util.Arrays.sort(object []).
*
* @param paoArrayToSort array of objects to sort
*/
public static void sort(Object[] paoArrayToSort)
{
java.util.Arrays.sort(paoArrayToSort);
}
/*
* ----------
* Conversion
* ----------
*/
/**
* Converts array of doubles to Vector.
*
* @param padData array of double data
* @return equivalent collection of Double objects
* @since 0.3.0.3
*/
public static Vector arrayToVector(final double[] padData)
{
Vector oVector = new Vector(padData.length);
for(int i = 0; i < padData.length; i++)
{
oVector.add(new Double(padData[i]));
}
return oVector;
}
/**
* Converts array of ints to Vector.
*
* @param paiData array of int data
* @return equivalent collection of Integer objects
* @since 0.3.0.3
*/
public static Vector arrayToVector(final int[] paiData)
{
Vector oVector = new Vector(paiData.length);
for(int i = 0; i < paiData.length; i++)
{
oVector.add(new Integer(paiData[i]));
}
return oVector;
}
/**
* Converts array of floats to Vector.
*
* @param pafData array of float data
* @return equivalent collection of Float objects
* @since 0.3.0.3
*/
public static Vector arrayToVector(final float[] pafData)
{
Vector oVector = new Vector(pafData.length);
for(int i = 0; i < pafData.length; i++)
{
oVector.add(new Float(pafData[i]));
}
return oVector;
}
/**
* Converts array of shorts to Vector.
*
* @param pasData array of short data
* @return equivalent collection of Short objects
* @since 0.3.0.3
*/
public static Vector arrayToVector(final short[] pasData)
{
Vector oVector = new Vector(pasData.length);
for(int i = 0; i < pasData.length; i++)
{
oVector.add(new Short(pasData[i]));
}
return oVector;
}
/**
* Converts array of longs to Vector.
*
* @param palData array of long data
* @return equivalent collection of Long objects
* @since 0.3.0.3
*/
public static Vector arrayToVector(final long[] palData)
{
Vector oVector = new Vector(palData.length);
for(int i = 0; i < palData.length; i++)
{
oVector.add(new Long(palData[i]));
}
return oVector;
}
/**
* Converts array of characters to Vector.
*
* @param pacData array of character data
* @return equivalent collection of Character objects
* @since 0.3.0.3
*/
public static Vector arrayToVector(final char[] pacData)
{
Vector oVector = new Vector(pacData.length);
for(int i = 0; i < pacData.length; i++)
{
oVector.add(new Character(pacData[i]));
}
return oVector;
}
/**
* Converts array of bytes to Vector.
*
* @param patData array of byte data
* @return equivalent collection of Byte objects
* @since 0.3.0.3
*/
public static Vector arrayToVector(final byte[] patData)
{
Vector oVector = new Vector(patData.length);
for(int i = 0; i < patData.length; i++)
{
oVector.add(new Byte(patData[i]));
}
return oVector;
}
/**
* Converts array of Strings to Vector.
*
* @param pastrData array of String data
* @return equivalent collection of String objects
* @since 0.3.0.3
*/
public static Vector arrayToVector(final String[] pastrData)
{
Vector oVector = new Vector(pastrData.length);
for(int i = 0; i < pastrData.length; i++)
{
oVector.add(new String(pastrData[i]));
}
return oVector;
}
/**
* Converts array of Objects to Vector.
*
* @param paoData array of Object data
* @return equivalent collection of objects
* @since 0.3.0.6
*/
public static Vector arrayToVector(final Object[] paoData)
{
Vector oVector = new Vector(paoData.length);
for(int i = 0; i < paoData.length; i++)
{
oVector.add(paoData[i]);
}
return oVector;
}
/**
* Converts array of Strings to a single string separated by
* the specified delimeter.
*
* @param pastrData string data to concatenate
* @param pstrDelimeter data elements separator
* @return the resulting combined string
*
* @since 0.3.0.5
*/
public static String arrayToDelimitedString(final String[] pastrData, final String pstrDelimeter)
{
String strRetVal = pastrData[0];
if(pastrData.length > 0)
{
for(int i = 1; i < pastrData.length; i++)
{
strRetVal += pstrDelimeter + pastrData[i];
}
}
return strRetVal;
}
/**
* Converts array of integers to a single string separated by
* the specified delimeter.
*
* @param paiData int data to append
* @param pstrDelimeter data elements separator
* @return the resulting combined string
*
* @since 0.3.0.5
*/
public static String arrayToDelimitedString(final int[] paiData, final String pstrDelimeter)
{
StringBuffer oRetVal = new StringBuffer();
if(paiData.length > 0)
{
oRetVal.append(paiData[0]);
for(int i = 1; i < paiData.length; i++)
{
oRetVal.append(pstrDelimeter).append(paiData[i]);
}
}
return oRetVal.toString();
}
/**
* Converts array of Objects to a single string separated by
* the specified delimeter.
*
* @param paoData Object data to append
* @param pstrDelimeter data elements separator
* @return the resulting combined string
*
* @since 0.3.0.5
*/
public static String arrayToDelimitedString(final Object[] paoData, final String pstrDelimeter)
{
StringBuffer oRetVal = new StringBuffer();
if(paoData.length > 0)
{
oRetVal.append(paoData[0]);
for(int i = 1; i < paoData.length; i++)
{
oRetVal.append(pstrDelimeter).append(paoData[i]);
}
}
return oRetVal.toString();
}
/**
* Converts array of longs to a single string separated by
* the specified delimeter.
*
* @param palData long data to append
* @param pstrDelimeter data elements separator
* @return the resulting combined string
*
* @since 0.3.0.5
*/
public static String arrayToDelimitedString(final long[] palData, final String pstrDelimeter)
{
StringBuffer oRetVal = new StringBuffer();
if(palData.length > 0)
{
oRetVal.append(palData[0]);
for(int i = 1; i < palData.length; i++)
{
oRetVal.append(pstrDelimeter).append(palData[i]);
}
}
return oRetVal.toString();
}
/**
* Converts array of floats to a single string separated by
* the specified delimeter.
*
* @param pafData float data to append
* @param pstrDelimeter data elements separator
* @return the resulting combined string
*
* @since 0.3.0.5
*/
public static String arrayToDelimitedString(final float[] pafData, final String pstrDelimeter)
{
StringBuffer oRetVal = new StringBuffer();
if(pafData.length > 0)
{
oRetVal.append(pafData[0]);
for(int i = 1; i < pafData.length; i++)
{
oRetVal.append(pstrDelimeter).append(pafData[i]);
}
}
return oRetVal.toString();
}
/**
* Converts array of doubles to a single string separated by
* the specified delimeter.
*
* @param padData double data to append
* @param pstrDelimeter data elements separator
* @return the resulting combined string
*
* @since 0.3.0.5
*/
public static String arrayToDelimitedString(final double[] padData, final String pstrDelimeter)
{
StringBuffer oRetVal = new StringBuffer();
if(padData.length > 0)
{
oRetVal.append(padData[0]);
for(int i = 1; i < padData.length; i++)
{
oRetVal.append(pstrDelimeter).append(padData[i]);
}
}
return oRetVal.toString();
}
/**
* Converts array of bytes to a single string separated by
* the specified delimeter.
*
* @param patData byte data to append
* @param pstrDelimeter data elements separator
* @return the resulting combined string
*
* @since 0.3.0.5
*/
public static String arrayToDelimitedString(final byte[] patData, final String pstrDelimeter)
{
StringBuffer oRetVal = new StringBuffer();
if(patData.length > 0)
{
oRetVal.append(patData[0]);
for(int i = 1; i < patData.length; i++)
{
oRetVal.append(pstrDelimeter).append(patData[i]);
}
}
return oRetVal.toString();
}
/**
* Converts array of booleans to a single string separated by
* the specified delimeter.
*
* @param pabData boolean data to append
* @param pstrDelimeter data elements separator
* @return the resulting combined string
*
* @since 0.3.0.5
*/
public static String arrayToDelimitedString(final boolean[] pabData, final String pstrDelimeter)
{
StringBuffer oRetVal = new StringBuffer();
if(pabData.length > 0)
{
oRetVal.append(pabData[0]);
for(int i = 1; i < pabData.length; i++)
{
oRetVal.append(pstrDelimeter).append(pabData[i]);
}
}
return oRetVal.toString();
}
/**
* Converts array of characters to a single string separated by
* the specified delimeter.
*
* @param pacData charater data to append
* @param pstrDelimeter data elements separator
* @return the resulting combined string
*
* @since 0.3.0.5
*/
public static String arrayToDelimitedString(final char[] pacData, final String pstrDelimeter)
{
StringBuffer oRetVal = new StringBuffer();
if(pacData.length > 0)
{
oRetVal.append(pacData[0]);
for(int i = 1; i < pacData.length; i++)
{
oRetVal.append(pstrDelimeter).append(pacData[i]);
}
}
return oRetVal.toString();
}
/**
* Converts array of Strings to a single space-separated String.
*
* @param pastrData array of String data
* @return equivalent combined string
*
* @since 0.3.0.5
*/
public static String arrayToString(final String[] pastrData)
{
return arrayToDelimitedString(pastrData, " ");
}
/**
* Converts array of Objects to a single space-separated String.
*
* @param paoData array of Object data
* @return equivalent combined string
*
* @since 0.3.0.5
*/
public static String arrayToString(final Object[] paoData)
{
return arrayToDelimitedString(paoData, " ");
}
/**
* Converts array of integers to a single space-separated String.
*
* @param paiData array of integer data
* @return equivalent combined string
*
* @since 0.3.0.5
*/
public static String arrayToString(final int[] paiData)
{
return arrayToDelimitedString(paiData, " ");
}
/**
* Converts array of longs to a single space-separated String.
*
* @param palData array of long data
* @return equivalent combined string
*
* @since 0.3.0.5
*/
public static String arrayToString(final long[] palData)
{
return arrayToDelimitedString(palData, " ");
}
/**
* Converts array of floats to a single space-separated String.
*
* @param pafData array of float data
* @return equivalent combined string
*
* @since 0.3.0.5
*/
public static String arrayToString(final float[] pafData)
{
return arrayToDelimitedString(pafData, " ");
}
/**
* Converts array of doubles to a single space-separated String.
*
* @param padData array of double data
* @return equivalent combined string
*
* @since 0.3.0.5
*/
public static String arrayToString(final double[] padData)
{
return arrayToDelimitedString(padData, " ");
}
/**
* Converts array of bytes to a single space-separated String.
*
* @param patData array of byte data
* @return equivalent combined string
*
* @since 0.3.0.5
*/
public static String arrayToString(final byte[] patData)
{
return arrayToDelimitedString(patData, " ");
}
/**
* Converts array of booleans to a single space-separated String.
*
* @param pabData array of boolean data
* @return equivalent combined string
*
* @since 0.3.0.5
*/
public static String arrayToString(final boolean[] pabData)
{
return arrayToDelimitedString(pabData, " ");
}
/**
* Converts array of characters to a single space-separated String.
*
* @param pacData array of charater data
* @return equivalent combined string
*
* @since 0.3.0.5
*/
public static String arrayToString(final char[] pacData)
{
return arrayToDelimitedString(pacData, " ");
}
/**
* Converts array of Strings to a single comma-separated String.
*
* @param pastrData array of String data
* @return equivalent combined string
*
* @since 0.3.0.5
*/
public static String arrayToCSV(final String[] pastrData)
{
return arrayToDelimitedString(pastrData, ",");
}
/**
* Converts array of Objects to a single comma-separated String.
*
* @param paoData array of Object data
* @return equivalent combined string
*
* @since 0.3.0.5
*/
public static String arrayToCSV(final Object[] paoData)
{
return arrayToDelimitedString(paoData, ",");
}
/**
* Converts array of integers to a single comma-separated String.
*
* @param paiData array of integer data
* @return equivalent combined string
*
* @since 0.3.0.5
*/
public static String arrayToCSV(final int[] paiData)
{
return arrayToDelimitedString(paiData, ",");
}
/**
* Converts array of longs to a single comma-separated String.
*
* @param palData array of long data
* @return equivalent combined string
*
* @since 0.3.0.5
*/
public static String arrayToCSV(final long[] palData)
{
return arrayToDelimitedString(palData, ",");
}
/**
* Converts array of floats to a single comma-separated String.
*
* @param pafData array of float data
* @return equivalent combined string
*
* @since 0.3.0.5
*/
public static String arrayToCSV(final float[] pafData)
{
return arrayToDelimitedString(pafData, ",");
}
/**
* Converts array of doubles to a single comma-separated String.
*
* @param padData array of double data
* @return equivalent combined string
*
* @since 0.3.0.5
*/
public static String arrayToCSV(final double[] padData)
{
return arrayToDelimitedString(padData, ",");
}
/**
* Converts array of bytes to a single comma-separated String.
*
* @param patData array of byte data
* @return equivalent combined string
*
* @since 0.3.0.5
*/
public static String arrayToCSV(final byte[] patData)
{
return arrayToDelimitedString(patData, ",");
}
/**
* Converts array of booleans to a single comma-separated String.
*
* @param pabData array of boolean data
* @return equivalent combined string
*
* @since 0.3.0.5
*/
public static String arrayToCSV(final boolean[] pabData)
{
return arrayToDelimitedString(pabData, ",");
}
/**
* Converts array of charaters to a single comma-separated String.
*
* @param pacData array of charater data
* @return equivalent combined string
*
* @since 0.3.0.5
*/
public static String arrayToCSV(final char[] pacData)
{
return arrayToDelimitedString(pacData, ",");
}
/**
* Provides an array-of-objects-to-List bridge.
* Wraps <code>java.util.Arrays.asList()</code>.
*
* @param paoObjects array of objects
* @return corresponding List collection
* @since 0.3.0.3
*/
public static java.util.List asList(Object[] paoObjects)
{
return java.util.Arrays.asList(paoObjects);
}
/**
* General copy-conversion method that copies N int elements
* from an array of ints into array of doubles.
*
* @param padDestination destination array of doubles
* @param piDestinationFrom index in the destination to start place elements at
* @param paiSource sourc earray of ints
* @param piSourceFrom index in the source to start take elements from
* @param piHowMany N; how many elements to copy
* @since 0.3.0.3
*/
public static void copy(double[] padDestination, int piDestinationFrom, int[] paiSource, int piSourceFrom, int piHowMany)
{
for(int i = 0; i < piHowMany; i++)
padDestination[piDestinationFrom + i] = paiSource[piSourceFrom + i];
}
/**
* Copy-conversion method that copies N int elements
* from an array of ints into array of doubles.
*
* @param padDestination destination array of doubles
* @param paiSource sourc earray of ints
* @param piHowMany N; how many elements to copy
* @since 0.3.0.3
*/
public static void copy(double[] padDestination, int[] paiSource, int piHowMany)
{
copy(padDestination, 0, paiSource, 0, piHowMany);
}
/**
* Copy-conversion method that copies all int elements
* from an array of ints into array of doubles.
*
* @param padDestination destination array of doubles
* @param paiSource source array of ints
* @since 0.3.0.3
*/
public static void copy(double[] padDestination, int[] paiSource)
{
copy(padDestination, 0, paiSource, 0, paiSource.length);
}
/**
* General copy-conversion method that copies N int elements
* from an array of ints into array of floats.
*
* @param pafDestination destination array of floats
* @param piDestinationFrom index in the destination to start place elements at
* @param paiSource source array of ints
* @param piSourceFrom index in the source to start take elements from
* @param piHowMany N; how many elements to copy
* @since 0.3.0.3
*/
public static void copy(float[] pafDestination, int piDestinationFrom, int[] paiSource, int piSourceFrom, int piHowMany)
{
for(int i = 0; i < piHowMany; i++)
pafDestination[piDestinationFrom + i] = paiSource[piSourceFrom + i];
}
/**
* Copy-conversion method that copies N int elements
* from an array of ints into array of floats.
*
* @param pafDestination destination array of floats
* @param paiSource source array of ints
* @param piHowMany N; how many elements to copy
* @since 0.3.0.3
*/
public static void copy(float[] pafDestination, int[] paiSource, int piHowMany)
{
copy(pafDestination, 0, paiSource, 0, piHowMany);
}
/**
* Copy-conversion method that copies all int elements
* from an array of ints into array of floats.
*
* @param pafDestination destination array of floats
* @param paiSource source array of ints
* @since 0.3.0.3
*/
public static void copy(float[] pafDestination, int[] paiSource)
{
copy(pafDestination, 0, paiSource, 0, paiSource.length);
}
/**
* General copy-conversion method that copies N int elements
* from an array of ints into array of longs.
*
* @param palDestination destination array of longs
* @param piDestinationFrom index in the destination to start place elements at
* @param paiSource source array of ints
* @param piSourceFrom index in the source to start take elements from
* @param piHowMany N; how many elements to copy
* @since 0.3.0.3
*/
public static void copy(long[] palDestination, int piDestinationFrom, int[] paiSource, int piSourceFrom, int piHowMany)
{
for(int i = 0; i < piHowMany; i++)
palDestination[piDestinationFrom + i] = paiSource[piSourceFrom + i];
}
/**
* Copy-conversion method that copies N int elements
* from an array of ints into array of longs.
*
* @param palDestination destination array of longs
* @param paiSource source array of ints
* @param piHowMany N; how many elements to copy
* @since 0.3.0.3
*/
public static void copy(long[] palDestination, int[] paiSource, int piHowMany)
{
copy(palDestination, 0, paiSource, 0, piHowMany);
}
/**
* Copy-conversion method that copies all int elements
* from an array of ints into array of longs.
*
* @param palDestination destination array of longs
* @param paiSource source array of ints
* @since 0.3.0.3
*/
public static void copy(long[] palDestination, int[] paiSource)
{
copy(palDestination, 0, paiSource, 0, paiSource.length);
}
/**
* General copy-conversion method that copies N int elements
* from an array of ints into array of shorts.
*
* @param pasDestination destination array of shorts
* @param piDestinationFrom index in the destination to start place elements at
* @param paiSource source array of ints
* @param piSourceFrom index in the source to start take elements from
* @param piHowMany N; how many elements to copy
* @since 0.3.0.3
*/
public static void copy(short[] pasDestination, int piDestinationFrom, int[] paiSource, int piSourceFrom, int piHowMany)
{
for(int i = 0; i < piHowMany; i++)
pasDestination[piDestinationFrom + i] = (short)paiSource[piSourceFrom + i];
}
/**
* Copy-conversion method that copies N int elements
* from an array of ints into array of shorts.
*
* @param pasDestination destination array of shorts
* @param paiSource source array of ints
* @param piHowMany N; how many elements to copy
* @since 0.3.0.3
*/
public static void copy(short[] pasDestination, int[] paiSource, int piHowMany)
{
copy(pasDestination, 0, paiSource, 0, piHowMany);
}
/**
* Copy-conversion method that copies all int elements
* from an array of ints into array of shorts.
*
* @param pasDestination destination array of shorts
* @param paiSource source array of ints
* @since 0.3.0.3
*/
public static void copy(short[] pasDestination, int[] paiSource)
{
copy(pasDestination, 0, paiSource, 0, paiSource.length);
}
/**
* General copy-conversion method that copies N int elements
* from an array of ints into array of bytes.
*
* @param patDestination destination array of bytes
* @param piDestinationFrom index in the destination to start place elements at
* @param paiSource source array of ints
* @param piSourceFrom index in the source to start take elements from
* @param piHowMany N; how many elements to copy
* @since 0.3.0.3
*/
public static void copy(byte[] patDestination, int piDestinationFrom, int[] paiSource, int piSourceFrom, int piHowMany)
{
for(int i = 0; i < piHowMany; i++)
patDestination[piDestinationFrom + i] = (byte)(paiSource[piSourceFrom + i]);
}
/**
* Copy-conversion method that copies N int elements
* from an array of ints into array of bytes.
*
* @param patDestination destination array of bytes
* @param paiSource source array of ints
* @param piHowMany N; how many elements to copy
* @since 0.3.0.3
*/
public static void copy(byte[] patDestination, int[] paiSource, int piHowMany)
{
copy(patDestination, 0, paiSource, 0, piHowMany);
}
/**
* Copy-conversion method that copies all int elements
* from an array of ints into array of bytes.
*
* @param patDestination destination array of bytes
* @param paiSource sourc earray of ints
* @since 0.3.0.3
*/
public static void copy(byte[] patDestination, int[] paiSource)
{
copy(patDestination, 0, paiSource, 0, paiSource.length);
}
/**
* General copy-conversion method that copies N int elements
* from an array of ints into array of characters.
*
* @param pacDestination destination array of characters
* @param piDestinationFrom index in the destination to start place elements at
* @param paiSource source array of ints
* @param piSourceFrom index in the source to start take elements from
* @param piHowMany N; how many elements to copy
* @since 0.3.0.3
*/
public static void copy(char[] pacDestination, int piDestinationFrom, int[] paiSource, int piSourceFrom, int piHowMany)
{
for(int i = 0; i < piHowMany; i++)
pacDestination[piDestinationFrom + i] = (char)paiSource[piSourceFrom + i];
}
/**
* Copy-conversion method that copies N int elements
* from an array of ints into array of characters.
*
* @param pacDestination destination array of characters
* @param paiSource sourc earray of ints
* @param piHowMany N; how many elements to copy
* @since 0.3.0.3
*/
public static void copy(char[] pacDestination, int[] paiSource, int piHowMany)
{
copy(pacDestination, 0, paiSource, 0, piHowMany);
}
/**
* Copy-conversion method that copies all int elements
* from an array of ints into array of characters.
*
* @param pacDestination destination array of characters
* @param paiSource sourc earray of ints
* @since 0.3.0.3
*/
public static void copy(char[] pacDestination, int[] paiSource)
{
copy(pacDestination, 0, paiSource, 0, paiSource.length);
}
/**
* General copy-conversion method that copies N double elements
* from an array of doubles into array of integers.
*
* @param paiDestination destination array of integers
* @param piDestinationFrom index in the destination to start place elements at
* @param padSource source array of doubles
* @param piSourceFrom index in the source to start take elements from
* @param piHowMany N; how many elements to copy
* @since 0.3.0.3
*/
public static void copy(int[] paiDestination, int piDestinationFrom, double[] padSource, int piSourceFrom, int piHowMany)
{
for(int i = 0; i < piHowMany; i++)
paiDestination[piDestinationFrom + i] =(int)padSource[piSourceFrom + i];
}
/**
* Copy-conversion method that copies N double elements
* from an array of doubles into array of integers.
*
* @param paiDestination destination array of integers
* @param padSource source array of doubles
* @param piHowMany N; how many elements to copy
* @since 0.3.0.3
*/
public static void copy(int[] paiDestination, double[] padSource, int piHowMany)
{
copy(paiDestination, 0, padSource, 0, piHowMany);
}
/**
* Copy-conversion method that copies all double elements
* from an array of doubles into array of ints.
*
* @param paiDestination destination array of ints
* @param padSource source array of doubles
* @since 0.3.0.3
*/
public static void copy(int[] paiDestination, double[] padSource)
{
copy(paiDestination, 0, padSource, 0, padSource.length);
}
/**
* General copy-conversion method that copies N double elements
* from an array of doubles into array of characters.
*
* @param pacDestination destination array of characters
* @param piDestinationFrom index in the destination to start place elements at
* @param padSource source array of doubles
* @param piSourceFrom index in the source to start take elements from
* @param piHowMany N; how many elements to copy
* @since 0.3.0.3
*/
public static void copy(char[] pacDestination, int piDestinationFrom, double[] padSource, int piSourceFrom, int piHowMany)
{
for(int i = 0; i < piHowMany; i++)
pacDestination[piDestinationFrom + i] =(char)padSource[piSourceFrom + i];
}
/**
* Copy-conversion method that copies N double elements
* from an array of doubles into array of characters.
*
* @param pacDestination destination array of characters
* @param padSource source array of doubles
* @param piHowMany N; how many elements to copy
* @since 0.3.0.3
*/
public static void copy(char[] pacDestination, double[] padSource, int piHowMany)
{
copy(pacDestination, 0, padSource, 0, piHowMany);
}
/**
* Copy-conversion method that copies all double elements
* from an array of doubles into array of characters.
*
* @param pacDestination destination array of characters
* @param padSource source array of doubles
* @since 0.3.0.3
*/
public static void copy(char[] pacDestination, double[] padSource)
{
copy(pacDestination, 0, padSource, 0, padSource.length);
}
/**
* General copy-conversion method that copies N double elements
* from an array of doubles into array of bytes.
*
* @param patDestination destination array of bytes
* @param piDestinationFrom index in the destination to start place elements at
* @param padSource source array of doubles
* @param piSourceFrom index in the source to start take elements from
* @param piHowMany N; how many elements to copy
* @since 0.3.0.3
*/
public static void copy(byte[] patDestination, int piDestinationFrom, double[] padSource, int piSourceFrom, int piHowMany)
{
for(int i = 0; i < piHowMany; i++)
patDestination[piDestinationFrom + i] =(byte)padSource[piSourceFrom + i];
}
/**
* Copy-conversion method that copies N double elements
* from an array of doubles into array of bytes.
*
* @param patDestination destination array of bytes
* @param padSource source array of doubles
* @param piHowMany N; how many elements to copy
* @since 0.3.0.3
*/
public static void copy(byte[] patDestination, double[] padSource, int piHowMany)
{
copy(patDestination, 0, padSource, 0, piHowMany);
}
/**
* Copy-conversion method that copies all double elements
* from an array of doubles into array of bytes.
*
* @param patDestination destination array of bytes
* @param padSource source array of doubles
* @since 0.3.0.3
*/
public static void copy(byte[] patDestination, double[] padSource)
{
copy(patDestination, 0, padSource, 0, padSource.length);
}
/**
* General copy-conversion method that copies N double elements
* from an array of doubles into array of floats.
*
* @param pafDestination destination array of floats
* @param piDestinationFrom index in the destination to start place elements at
* @param padSource source array of doubles
* @param piSourceFrom index in the source to start take elements from
* @param piHowMany N; how many elements to copy
* @since 0.3.0.3
*/
public static void copy(float[] pafDestination, int piDestinationFrom, double[] padSource, int piSourceFrom, int piHowMany)
{
for(int i = 0; i < piHowMany; i++)
pafDestination[piDestinationFrom + i] = (float)padSource[piSourceFrom + i];
}
/**
* Copy-conversion method that copies N double elements
* from an array of doubles into array of floats.
*
* @param pafDestination destination array of floats
* @param padSource source array of doubles
* @param piHowMany N; how many elements to copy
* @since 0.3.0.3
*/
public static void copy(float[] pafDestination, double[] padSource, int piHowMany)
{
copy(pafDestination, 0, padSource, 0, piHowMany);
}
/**
* Copy-conversion method that copies all double elements
* from an array of doubles into array of floats.
*
* @param pafDestination destination array of floats
* @param padSource source array of doubles
* @since 0.3.0.3
*/
public static void copy(float[] pafDestination, double[] padSource)
{
copy(pafDestination, 0, padSource, 0, padSource.length);
}
/**
* General copy-conversion method that copies N double elements
* from an array of doubles into array of shorts.
*
* @param pasDestination destination array of shorts
* @param piDestinationFrom index in the destination to start place elements at
* @param padSource source array of doubles
* @param piSourceFrom index in the source to start take elements from
* @param piHowMany N; how many elements to copy
* @since 0.3.0.3
*/
public static void copy(short[] pasDestination, int piDestinationFrom, double[] padSource, int piSourceFrom, int piHowMany)
{
for(int i = 0; i < piHowMany; i++)
pasDestination[piDestinationFrom + i] =(short)padSource[piSourceFrom + i];
}
/**
* Copy-conversion method that copies N double elements
* from an array of doubles into array of shorts.
*
* @param pasDestination destination array of shorts
* @param padSource source array of doubles
* @param piHowMany N; how many elements to copy
* @since 0.3.0.3
*/
public static void copy(short[] pasDestination, double[] padSource, int piHowMany)
{
copy(pasDestination, 0, padSource, 0, piHowMany);
}
/**
* Copy-conversion method that copies all double elements
* from an array of doubles into array of shorts.
*
* @param pasDestination destination array of shorts
* @param padSource source array of doubles
* @since 0.3.0.3
*/
public static void copy(short[] pasDestination, double[] padSource)
{
copy(pasDestination, 0, padSource, 0, padSource.length);
}
/**
* General copy-conversion method that copies N double elements
* from an array of doubles into array of longs.
*
* @param palDestination destination array of longs
* @param piDestinationFrom index in the destination to start place elements at
* @param padSource source array of doubles
* @param piSourceFrom index in the source to start take elements from
* @param piHowMany N; how many elements to copy
* @since 0.3.0.3
*/
public static void copy(long[] palDestination, int piDestinationFrom, double[] padSource, int piSourceFrom, int piHowMany)
{
for(int i = 0; i < piHowMany; i++)
palDestination[piDestinationFrom + i] =(long)padSource[piSourceFrom + i];
}
/**
* Copy-conversion method that copies N double elements
* from an array of doubles into array of longs.
*
* @param palDestination destination array of longs
* @param padSource source array of doubles
* @param piHowMany N; how many elements to copy
* @since 0.3.0.3
*/
public static void copy(long[] palDestination, double[] padSource, int piHowMany)
{
copy(palDestination, 0, padSource, 0, piHowMany);
}
/**
* Copy-conversion method that copies all double elements
* from an array of doubles into array of longs.
*
* @param palDestination destination array of longs
* @param padSource source array of doubles
* @since 0.3.0.3
*/
public static void copy(long[] palDestination, double[] padSource)
{
copy(palDestination, 0, padSource, 0, padSource.length);
}
/**
* General copy-conversion method that copies N float elements
* from an array of floats into array of characters.
*
* @param pacDestination destination array of characters
* @param piDestinationFrom index in the destination to start place elements at
* @param pafSource source array of floats
* @param piSourceFrom index in the source to start take elements from
* @param piHowMany N; how many elements to copy
* @since 0.3.0.3
*/
public static void copy(char[] pacDestination, int piDestinationFrom, float[] pafSource, int piSourceFrom, int piHowMany)
{
for(int i = 0; i < piHowMany; i++)
pacDestination[piDestinationFrom + i] = (char)pafSource[piSourceFrom + i];
}
/**
* Copy-conversion method that copies N float elements
* from an array of floats into array of characters.
*
* @param pacDestination destination array of characters
* @param pafSource source array of floats
* @param piHowMany N; how many elements to copy
* @since 0.3.0.3
*/
public static void copy(char[] pacDestination, float[] pafSource, int piHowMany)
{
copy(pacDestination, 0, pafSource, 0, piHowMany);
}
/**
* Copy-conversion method that copies all float elements
* from an array of floats into array of characters.
*
* @param pacDestination destination array of characters
* @param pafSource source array of floats
* @since 0.3.0.3
*/
public static void copy(char[] pacDestination, float[] pafSource)
{
copy(pacDestination, 0, pafSource, 0, pafSource.length);
}
/**
* General copy-conversion method that copies N float elements
* from an array of floats into array of bytes.
*
* @param patDestination destination array of bytes
* @param piDestinationFrom index in the destination to start place elements at
* @param pafSource source array of floats
* @param piSourceFrom index in the source to start take elements from
* @param piHowMany N; how many elements to copy
* @since 0.3.0.3
*/
public static void copy(byte[] patDestination, int piDestinationFrom, float[] pafSource, int piSourceFrom, int piHowMany)
{
for(int i = 0; i < piHowMany; i++)
patDestination[piDestinationFrom + i] = (byte)pafSource[piSourceFrom + i];
}
/**
* Copy-conversion method that copies N float elements
* from an array of floats into array of bytes.
*
* @param patDestination destination array of characters
* @param pafSource source array of bytes
* @param piHowMany N; how many elements to copy
* @since 0.3.0.3
*/
public static void copy(byte[] patDestination, float[] pafSource, int piHowMany)
{
copy(patDestination, 0, pafSource, 0, piHowMany);
}
/**
* Copy-conversion method that copies all float elements
* from an array of floats into array of characters.
*
* @param patDestination destination array of bytes
* @param pafSource source array of floats
* @since 0.3.0.3
*/
public static void copy(byte[] patDestination, float[] pafSource)
{
copy(patDestination, 0, pafSource, 0, pafSource.length);
}
/**
* General copy-conversion method that copies N float elements
* from an array of floats into array of integers.
*
* @param paiDestination destination array of integers
* @param piDestinationFrom index in the destination to start place elements at
* @param pafSource source array of floats
* @param piSourceFrom index in the source to start take elements from
* @param piHowMany N; how many elements to copy
* @since 0.3.0.3
*/
public static void copy(int[] paiDestination, int piDestinationFrom, float[] pafSource, int piSourceFrom, int piHowMany)
{
for(int i = 0; i < piHowMany; i++)
paiDestination[piDestinationFrom + i] =(int)pafSource[piSourceFrom + i];
}
/**
* Copy-conversion method that copies N float elements
* from an array of floats into array of integers.
*
* @param paiDestination destination array of integers
* @param pafSource source array of floats
* @param piHowMany N; how many elements to copy
* @since 0.3.0.3
*/
public static void copy(int[] paiDestination, float[] pafSource, int piHowMany)
{
copy(paiDestination, 0, pafSource, 0, piHowMany);
}
/**
* Copy-conversion method that copies all float elements
* from an array of floats into array of integers.
*
* @param paiDestination destination array of integers
* @param pafSource source array of floats
* @since 0.3.0.3
*/
public static void copy(int[] paiDestination, float[] pafSource)
{
copy(paiDestination, 0, pafSource, 0, pafSource.length);
}
/**
* General copy-conversion method that copies N float elements
* from an array of floats into array of shorts.
*
* @param pasDestination destination array of shorts
* @param piDestinationFrom index in the destination to start place elements at
* @param pafSource source array of floats
* @param piSourceFrom index in the source to start take elements from
* @param piHowMany N; how many elements to copy
* @since 0.3.0.3
*/
public static void copy(short[] pasDestination, int piDestinationFrom, float[] pafSource, int piSourceFrom, int piHowMany)
{
for(int i = 0; i < piHowMany; i++)
pasDestination[piDestinationFrom + i] = (short)pafSource[piSourceFrom + i];
}
/**
* Copy-conversion method that copies N float elements
* from an array of floats into array of shorts.
*
* @param pasDestination destination array of shorts
* @param pafSource source array of floats
* @param piHowMany N; how many elements to copy
* @since 0.3.0.3
*/
public static void copy(short[] pasDestination, float[] pafSource, int piHowMany)
{
copy(pasDestination, 0, pafSource, 0, piHowMany);
}
/**
* Copy-conversion method that copies all float elements
* from an array of floats into array of shorts.
*
* @param pasDestination destination array of shorts
* @param pafSource source array of floats
* @since 0.3.0.3
*/
public static void copy(short[] pasDestination, float[] pafSource)
{
copy(pasDestination, 0, pafSource, 0, pafSource.length);
}
/**
* General copy-conversion method that copies N float elements
* from an array of floats into array of longs.
*
* @param palDestination destination array of longs
* @param piDestinationFrom index in the destination to start place elements at
* @param pafSource source array of floats
* @param piSourceFrom index in the source to start take elements from
* @param piHowMany N; how many elements to copy
* @since 0.3.0.3
*/
public static void copy(long[] palDestination, int piDestinationFrom, float[] pafSource, int piSourceFrom, int piHowMany)
{
for(int i = 0; i < piHowMany; i++)
palDestination[piDestinationFrom + i] =(long)pafSource[piSourceFrom + i];
}
/**
* Copy-conversion method that copies N float elements
* from an array of floats into array of longs.
*
* @param palDestination destination array of longs
* @param pafSource source array of floats
* @param piHowMany N; how many elements to copy
* @since 0.3.0.3
*/
public static void copy(long[] palDestination, float[] pafSource, int piHowMany)
{
copy(palDestination, 0, pafSource, 0, piHowMany);
}
/**
* Copy-conversion method that copies all float elements
* from an array of floats into array of longs.
*
* @param palDestination destination array of longs
* @param pafSource source array of floats
* @since 0.3.0.3
*/
public static void copy(long[] palDestination, float[] pafSource)
{
copy(palDestination, 0, pafSource, 0, pafSource.length);
}
/**
* General copy-conversion method that copies N float elements
* from an array of floats into array of doubles.
*
* @param padDestination destination array of doubles
* @param piDestinationFrom index in the destination to start place elements at
* @param pafSource source array of floats
* @param piSourceFrom index in the source to start take elements from
* @param piHowMany N; how many elements to copy
* @since 0.3.0.3
*/
public static void copy(double[] padDestination, int piDestinationFrom, float[] pafSource, int piSourceFrom, int piHowMany)
{
for(int i = 0; i < piHowMany; i++)
padDestination[piDestinationFrom + i] = pafSource[piSourceFrom + i];
}
/**
* Copy-conversion method that copies N float elements
* from an array of floats into array of doubles.
*
* @param padDestination destination array of doubles
* @param pafSource source array of floats
* @param piHowMany N; how many elements to copy
* @since 0.3.0.3
*/
public static void copy(double[] padDestination, float[] pafSource, int piHowMany)
{
copy(padDestination, 0, pafSource, 0, piHowMany);
}
/**
* Copy-conversion method that copies all float elements
* from an array of floats into array of doubles.
*
* @param padDestination destination array of doubles
* @param pafSource source array of floats
* @since 0.3.0.3
*/
public static void copy(double[] padDestination, float[] pafSource)
{
copy(padDestination, 0, pafSource, 0, pafSource.length);
}
/**
* General copy-conversion method that copies N short elements
* from an array of shorts into array of doubles.
*
* @param padDestination destination array of doubles
* @param piDestinationFrom index in the destination to start place elements at
* @param pasSource source array of shorts
* @param piSourceFrom index in the source to start take elements from
* @param piHowMany N; how many elements to copy
* @since 0.3.0.3
*/
public static void copy(double[] padDestination, int piDestinationFrom, short[] pasSource, int piSourceFrom, int piHowMany)
{
for(int i = 0; i < piHowMany; i++)
padDestination[piDestinationFrom + i] = pasSource[piSourceFrom + i];
}
/**
* Copy-conversion method that copies N short elements
* from an array of shorts into array of doubles.
*
* @param padDestination destination array of doubles
* @param pasSource source array of shorts
* @param piHowMany N; how many elements to copy
* @since 0.3.0.3
*/
public static void copy(double[] padDestination, short[] pasSource, int piHowMany)
{
copy(padDestination, 0, pasSource, 0, piHowMany);
}
/**
* Copy-conversion method that copies all short elements
* from an array of shorts into array of doubles.
*
* @param padDestination destination array of doubles
* @param pasSource source array of shorts
* @since 0.3.0.3
*/
public static void copy(double[] padDestination, short[] pasSource)
{
copy(padDestination, 0, pasSource, 0, pasSource.length);
}
/**
* General copy-conversion method that copies N short elements
* from an array of shorts into array of characters.
*
* @param pacDestination destination array of characters
* @param piDestinationFrom index in the destination to start place elements at
* @param pasSource source array of shorts
* @param piSourceFrom index in the source to start take elements from
* @param piHowMany N; how many elements to copy
* @since 0.3.0.3
*/
public static void copy(char[] pacDestination, int piDestinationFrom, short[] pasSource, int piSourceFrom, int piHowMany)
{
for(int i = 0; i < piHowMany; i++)
pacDestination[piDestinationFrom + i] = (char)pasSource[piSourceFrom + i];
}
/**
* Copy-conversion method that copies N short elements
* from an array of shorts into array of characters.
*
* @param pacDestination destination array of characters
* @param pasSource source array of shorts
* @param piHowMany N; how many elements to copy
* @since 0.3.0.3
*/
public static void copy(char[] pacDestination, short[] pasSource, int piHowMany)
{
copy(pacDestination, 0, pasSource, 0, piHowMany);
}
/**
* Copy-conversion method that copies all short elements
* from an array of shorts into array of characters.
*
* @param pacDestination destination array of characters
* @param pasSource source array of shorts
* @since 0.3.0.3
*/
public static void copy(char[] pacDestination, short[] pasSource)
{
copy(pacDestination, 0, pasSource, 0, pasSource.length);
}
/**
* General copy-conversion method that copies N short elements
* from an array of shorts into array of bytes.
*
* @param patDestination destination array of bytes
* @param piDestinationFrom index in the destination to start place elements at
* @param pasSource source array of shorts
* @param piSourceFrom index in the source to start take elements from
* @param piHowMany N; how many elements to copy
* @since 0.3.0.3
*/
public static void copy(byte[] patDestination, int piDestinationFrom, short[] pasSource, int piSourceFrom, int piHowMany)
{
for(int i = 0; i < piHowMany; i++)
patDestination[piDestinationFrom + i] =(byte)pasSource[piSourceFrom + i];
}
/**
* Copy-conversion method that copies N short elements
* from an array of shorts into array of bytes.
*
* @param patDestination destination array of bytes
* @param pasSource source array of shorts
* @param piHowMany N; how many elements to copy
* @since 0.3.0.3
*/
public static void copy(byte[] patDestination, short[] pasSource, int piHowMany)
{
copy(patDestination, 0, pasSource, 0, piHowMany);
}
/**
* Copy-conversion method that copies all short elements
* from an array of shorts into array of bytes.
*
* @param patDestination destination array of bytes
* @param pasSource source array of shorts
* @since 0.3.0.3
*/
public static void copy(byte[] patDestination, short[] pasSource)
{
copy(patDestination, 0, pasSource, 0, pasSource.length);
}
/**
* General copy-conversion method that copies N short elements
* from an array of shorts into array of integers.
*
* @param paiDestination destination array of integers
* @param piDestinationFrom index in the destination to start place elements at
* @param pasSource source array of shorts
* @param piSourceFrom index in the source to start take elements from
* @param piHowMany N; how many elements to copy
* @since 0.3.0.3
*/
public static void copy(int[] paiDestination, int piDestinationFrom, short[] pasSource, int piSourceFrom, int piHowMany)
{
for(int i = 0; i < piHowMany; i++)
paiDestination[piDestinationFrom + i] = pasSource[piSourceFrom + i];
}
/**
* Copy-conversion method that copies N short elements
* from an array of shorts into array of integers.
*
* @param paiDestination destination array of integers
* @param pasSource source array of shorts
* @param piHowMany N; how many elements to copy
* @since 0.3.0.3
*/
public static void copy(int[] paiDestination, short[] pasSource, int piHowMany)
{
copy(paiDestination, 0, pasSource, 0, piHowMany);
}
/**
* Copy-conversion method that copies all short elements
* from an array of shorts into array of integers.
*
* @param paiDestination destination array of integers
* @param pasSource source array of shorts
* @since 0.3.0.3
*/
public static void copy(int[] paiDestination, short[] pasSource)
{
copy(paiDestination, 0, pasSource, 0, pasSource.length);
}
/**
* General copy-conversion method that copies N short elements
* from an array of shorts into array of floats.
*
* @param pafDestination destination array of floats
* @param piDestinationFrom index in the destination to start place elements at
* @param pasSource source array of shorts
* @param piSourceFrom index in the source to start take elements from
* @param piHowMany N; how many elements to copy
* @since 0.3.0.3
*/
public static void copy(float[] pafDestination, int piDestinationFrom, short[] pasSource, int piSourceFrom, int piHowMany)
{
for(int i = 0; i < piHowMany; i++)
pafDestination[piDestinationFrom + i] = pasSource[piSourceFrom + i];
}
/**
* Copy-conversion method that copies N short elements
* from an array of shorts into array of floats.
*
* @param pafDestination destination array of floats
* @param pasSource source array of shorts
* @param piHowMany N; how many elements to copy
* @since 0.3.0.3
*/
public static void copy(float[] pafDestination, short[] pasSource, int piHowMany)
{
copy(pafDestination, 0, pasSource, 0, piHowMany);
}
/**
* Copy-conversion method that copies all short elements
* from an array of shorts into array of floats.
*
* @param pafDestination destination array of floats
* @param pasSource source array of shorts
* @since 0.3.0.3
*/
public static void copy(float[] pafDestination, short[] pasSource)
{
copy(pafDestination, 0, pasSource, 0, pasSource.length);
}
/**
* General copy-conversion method that copies N short elements
* from an array of shorts into array of longs.
*
* @param palDestination destination array of longs
* @param piDestinationFrom index in the destination to start place elements at
* @param pasSource source array of shorts
* @param piSourceFrom index in the source to start take elements from
* @param piHowMany N; how many elements to copy
* @since 0.3.0.3
*/
public static void copy(long[] palDestination, int piDestinationFrom, short[] pasSource, int piSourceFrom, int piHowMany)
{
for(int i = 0; i < piHowMany; i++)
palDestination[piDestinationFrom + i] = pasSource[piSourceFrom + i];
}
/**
* Copy-conversion method that copies N short elements
* from an array of shorts into array of longs.
*
* @param palDestination destination array of longs
* @param pasSource source array of shorts
* @param piHowMany N; how many elements to copy
* @since 0.3.0.3
*/
public static void copy(long[] palDestination, short[] pasSource, int piHowMany)
{
copy(palDestination, 0, pasSource, 0, piHowMany);
}
/**
* Copy-conversion method that copies all short elements
* from an array of shorts into array of longs.
*
* @param palDestination destination array of longs
* @param pasSource source array of shorts
* @since 0.3.0.3
*/
public static void copy(long[] palDestination, short[] pasSource)
{
copy(palDestination, 0, pasSource, 0, pasSource.length);
}
/**
* General copy-conversion method that copies N byte elements
* from an array of bytes into array of longs.
*
* @param palDestination destination array of longs
* @param piDestinationFrom index in the destination to start place elements at
* @param patSource source array of bytes
* @param piSourceFrom index in the source to start take elements from
* @param piHowMany N; how many elements to copy
* @since 0.3.0.3
*/
public static void copy(long[] palDestination, int piDestinationFrom, byte[] patSource, int piSourceFrom, int piHowMany)
{
for(int i = 0; i < piHowMany; i++)
palDestination[piDestinationFrom + i] = patSource[piSourceFrom + i];
}
/**
* Copy-conversion method that copies N byte elements
* from an array of bytes into array of longs.
*
* @param palDestination destination array of longs
* @param patSource source array of bytes
* @param piHowMany N; how many elements to copy
* @since 0.3.0.3
*/
public static void copy(long[] palDestination, byte[] patSource, int piHowMany)
{
copy(palDestination, 0, patSource, 0, piHowMany);
}
/**
* Copy-conversion method that copies all byte elements
* from an array of bytes into array of longs.
*
* @param palDestination destination array of longs
* @param patSource source array of bytes
* @since 0.3.0.3
*/
public static void copy(long[] palDestination, byte[] patSource)
{
copy(palDestination, 0, patSource, 0, patSource.length);
}
/**
* General copy-conversion method that copies N byte elements
* from an array of bytes into array of doubles.
*
* @param padDestination destination array of doubles
* @param piDestinationFrom index in the destination to start place elements at
* @param patSource source array of bytes
* @param piSourceFrom index in the source to start take elements from
* @param piHowMany N; how many elements to copy
* @since 0.3.0.3
*/
public static void copy(double[] padDestination, int piDestinationFrom, byte[] patSource, int piSourceFrom, int piHowMany)
{
for(int i = 0; i < piHowMany; i++)
padDestination[piDestinationFrom + i] = patSource[piSourceFrom + i];
}
/**
* Copy-conversion method that copies N byte elements
* from an array of bytes into array of doubles.
*
* @param padDestination destination array of doubles
* @param patSource source array of bytes
* @param piHowMany N; how many elements to copy
* @since 0.3.0.3
*/
public static void copy(double[] padDestination, byte[] patSource, int piHowMany)
{
copy(padDestination, 0, patSource, 0, piHowMany);
}
/**
* Copy-conversion method that copies all byte elements
* from an array of bytes into array of doubles.
*
* @param padDestination destination array of doubles
* @param patSource source array of bytes
* @since 0.3.0.3
*/
public static void copy(double[] padDestination, byte[] patSource)
{
copy(padDestination, 0, patSource, 0, patSource.length);
}
/**
* General copy-conversion method that copies N byte elements
* from an array of bytes into array of shorts.
*
* @param pasDestination destination array of shorts
* @param piDestinationFrom index in the destination to start place elements at
* @param patSource source array of bytes
* @param piSourceFrom index in the source to start take elements from
* @param piHowMany N; how many elements to copy
* @since 0.3.0.3
*/
public static void copy(short[] pasDestination, int piDestinationFrom, byte[] patSource, int piSourceFrom, int piHowMany)
{
for(int i = 0; i < piHowMany; i++)
pasDestination[piDestinationFrom + i] = patSource[piSourceFrom + i];
}
/**
* Copy-conversion method that copies N byte elements
* from an array of bytes into array of shorts.
*
* @param pasDestination destination array of shorts
* @param patSource source array of bytes
* @param piHowMany N; how many elements to copy
* @since 0.3.0.3
*/
public static void copy(short[] pasDestination, byte[] patSource, int piHowMany)
{
copy(pasDestination, 0, patSource, 0, piHowMany);
}
/**
* Copy-conversion method that copies all byte elements
* from an array of bytes into array of shorts.
*
* @param pasDestination destination array of shorts
* @param patSource source array of bytes
* @since 0.3.0.3
*/
public static void copy(short[] pasDestination, byte[] patSource)
{
copy(pasDestination, 0, patSource, 0, patSource.length);
}
/**
* General copy-conversion method that copies N byte elements
* from an array of bytes into array of floats.
*
* @param pafDestination destination array of floats
* @param piDestinationFrom index in the destination to start place elements at
* @param patSource source array of bytes
* @param piSourceFrom index in the source to start take elements from
* @param piHowMany N; how many elements to copy
* @since 0.3.0.3
*/
public static void copy(float[] pafDestination, int piDestinationFrom, byte[] patSource, int piSourceFrom, int piHowMany)
{
for(int i = 0; i < piHowMany; i++)
pafDestination[piDestinationFrom + i] = patSource[piSourceFrom + i];
}
/**
* Copy-conversion method that copies N byte elements
* from an array of bytes into array of floats.
*
* @param pafDestination destination array of floats
* @param patSource source array of bytes
* @param piHowMany N; how many elements to copy
* @since 0.3.0.3
*/
public static void copy(float[] pafDestination, byte[] patSource, int piHowMany)
{
copy(pafDestination, 0, patSource, 0, piHowMany);
}
/**
* Copy-conversion method that copies all byte elements
* from an array of bytes into array of floats.
*
* @param pafDestination destination array of floats
* @param patSource source array of bytes
* @since 0.3.0.3
*/
public static void copy(float[] pafDestination, byte[] patSource)
{
copy(pafDestination, 0, patSource, 0, patSource.length);
}
/**
* General copy-conversion method that copies N byte elements
* from an array of bytes into array of characters.
*
* @param pacDestination destination array of characters
* @param piDestinationFrom index in the destination to start place elements at
* @param patSource source array of bytes
* @param piSourceFrom index in the source to start take elements from
* @param piHowMany N; how many elements to copy
* @since 0.3.0.3
*/
public static void copy(char[] pacDestination, int piDestinationFrom, byte[] patSource, int piSourceFrom, int piHowMany)
{
for(int i = 0; i < piHowMany; i++)
pacDestination[piDestinationFrom + i] = (char)patSource[piSourceFrom + i];
}
/**
* Copy-conversion method that copies N byte elements
* from an array of bytes into array of characters.
*
* @param pacDestination destination array of characters
* @param patSource source array of bytes
* @param piHowMany N; how many elements to copy
* @since 0.3.0.3
*/
public static void copy(char[] pacDestination, byte[] patSource, int piHowMany)
{
copy(pacDestination, 0, patSource, 0, piHowMany);
}
/**
* Copy-conversion method that copies all byte elements
* from an array of bytes into array of bytes.
*
* @param pacDestination destination array of characters
* @param patSource source array of bytes
* @since 0.3.0.3
*/
public static void copy(char[] pacDestination, byte[] patSource)
{
copy(pacDestination, 0, patSource, 0, patSource.length);
}
/**
* General copy-conversion method that copies N byte elements
* from an array of bytes into array of integers.
*
* @param paiDestination destination array of integers
* @param piDestinationFrom index in the destination to start place elements at
* @param patSource source array of bytes
* @param piSourceFrom index in the source to start take elements from
* @param piHowMany N; how many elements to copy
* @since 0.3.0.3
*/
public static void copy(int[] paiDestination, int piDestinationFrom, byte[] patSource, int piSourceFrom, int piHowMany)
{
for(int i = 0; i < piHowMany; i++)
paiDestination[piDestinationFrom + i] = patSource[piSourceFrom + i];
}
/**
* Copy-conversion method that copies N byte elements
* from an array of bytes into array of integers.
*
* @param paiDestination destination array of integers
* @param patSource source array of bytes
* @param piHowMany N; how many elements to copy
* @since 0.3.0.3
*/
public static void copy(int[] paiDestination, byte[] patSource, int piHowMany)
{
copy(paiDestination, 0, patSource, 0, piHowMany);
}
/**
* Copy-conversion method that copies all byte elements
* from an array of bytes into array of integers.
*
* @param paiDestination destination array of integers
* @param patSource source array of bytes
* @since 0.3.0.3
*/
public static void copy(int[] paiDestination, byte[] patSource)
{
copy(paiDestination, 0, patSource, 0, patSource.length);
}
/**
* General copy-conversion method that copies N character elements
* from an array of characters into array of integers.
*
* @param paiDestination destination array of integers
* @param piDestinationFrom index in the destination to start place elements at
* @param pacSource source array of characters
* @param piSourceFrom index in the source to start take elements from
* @param piHowMany N; how many elements to copy
* @since 0.3.0.3
*/
public static void copy(int[] paiDestination, int piDestinationFrom, char[] pacSource, int piSourceFrom, int piHowMany)
{
for(int i = 0; i < piHowMany; i++)
paiDestination[piDestinationFrom + i] = pacSource[piSourceFrom + i];
}
/**
* Copy-conversion method that copies N character elements
* from an array of characters into array of integers.
*
* @param paiDestination destination array of integers
* @param pacSource source array of characters
* @param piHowMany N; how many elements to copy
* @since 0.3.0.3
*/
public static void copy(int[] paiDestination, char[] pacSource, int piHowMany)
{
copy(paiDestination, 0, pacSource, 0, piHowMany);
}
/**
* Copy-conversion method that copies all character elements
* from an array of characters into array of integers.
*
* @param paiDestination destination array of integers
* @param pacSource source array of characters
* @since 0.3.0.3
*/
public static void copy(int[] paiDestination, char[] pacSource)
{
copy(paiDestination, 0, pacSource, 0, pacSource.length);
}
/**
* General copy-conversion method that copies N character elements
* from an array of characters into array of bytes.
*
* @param patDestination destination array of bytes
* @param piDestinationFrom index in the destination to start place elements at
* @param pacSource source array of characters
* @param piSourceFrom index in the source to start take elements from
* @param piHowMany N; how many elements to copy
* @since 0.3.0.3
*/
public static void copy(byte[] patDestination, int piDestinationFrom, char[] pacSource, int piSourceFrom, int piHowMany)
{
for(int i = 0; i < piHowMany; i++)
patDestination[piDestinationFrom + i] = (byte)pacSource[piSourceFrom + i];
}
/**
* Copy-conversion method that copies N character elements
* from an array of characters into array of bytes.
*
* @param patDestination destination array of bytes
* @param pacSource source array of characters
* @param piHowMany N; how many elements to copy
* @since 0.3.0.3
*/
public static void copy(byte[] patDestination, char[] pacSource, int piHowMany)
{
copy(patDestination, 0, pacSource, 0, piHowMany);
}
/**
* Copy-conversion method that copies all character elements
* from an array of characters into array of bytes.
*
* @param patDestination destination array of bytes
* @param pacSource source array of characters
* @since 0.3.0.3
*/
public static void copy(byte[] patDestination, char[] pacSource)
{
copy(patDestination, 0, pacSource, 0, pacSource.length);
}
/**
* General copy-conversion method that copies N character elements
* from an array of characters into array of shorts.
*
* @param pasDestination destination array of shorts
* @param piDestinationFrom index in the destination to start place elements at
* @param pacSource source array of characters
* @param piSourceFrom index in the source to start take elements from
* @param piHowMany N; how many elements to copy
* @since 0.3.0.3
*/
public static void copy(short[] pasDestination, int piDestinationFrom, char[] pacSource, int piSourceFrom, int piHowMany)
{
for(int i = 0; i < piHowMany; i++)
pasDestination[piDestinationFrom + i] = (short)pacSource[piSourceFrom + i];
}
/**
* Copy-conversion method that copies N character elements
* from an array of characters into array of shorts.
*
* @param pasDestination destination array of shorts
* @param pacSource source array of characters
* @param piHowMany N; how many elements to copy
* @since 0.3.0.3
*/
public static void copy(short[] pasDestination, char[] pacSource, int piHowMany)
{
copy(pasDestination, 0, pacSource, 0, piHowMany);
}
/**
* Copy-conversion method that copies all character elements
* from an array of characters into array of shorts.
*
* @param pasDestination destination array of shorts
* @param pacSource source array of characters
* @since 0.3.0.3
*/
public static void copy(short[] pasDestination, char[] pacSource)
{
copy(pasDestination, 0, pacSource, 0, pacSource.length);
}
/**
* General copy-conversion method that copies N character elements
* from an array of characters into array of longs.
*
* @param palDestination destination array of longs
* @param piDestinationFrom index in the destination to start place elements at
* @param pacSource source array of characters
* @param piSourceFrom index in the source to start take elements from
* @param piHowMany N; how many elements to copy
* @since 0.3.0.3
*/
public static void copy(long[] palDestination, int piDestinationFrom, char[] pacSource, int piSourceFrom, int piHowMany)
{
for(int i = 0; i < piHowMany; i++)
palDestination[piDestinationFrom + i] = pacSource[piSourceFrom + i];
}
/**
* Copy-conversion method that copies N character elements
* from an array of characters into array of longs.
*
* @param palDestination destination array of longs
* @param pacSource source array of characters
* @param piHowMany N; how many elements to copy
* @since 0.3.0.3
*/
public static void copy(long[] palDestination, char[] pacSource, int piHowMany)
{
copy(palDestination, 0, pacSource, 0, piHowMany);
}
/**
* Copy-conversion method that copies all character elements
* from an array of characters into array of longs.
*
* @param palDestination destination array of longs
* @param pacSource source array of characters
* @since 0.3.0.3
*/
public static void copy(long[] palDestination, char[] pacSource)
{
copy(palDestination, 0, pacSource, 0, pacSource.length);
}
/**
* General copy-conversion method that copies N character elements
* from an array of characters into array of floats.
*
* @param pafDestination destination array of floats
* @param piDestinationFrom index in the destination to start place elements at
* @param pacSource source array of characters
* @param piSourceFrom index in the source to start take elements from
* @param piHowMany N; how many elements to copy
* @since 0.3.0.3
*/
public static void copy(float[] pafDestination, int piDestinationFrom, char[] pacSource, int piSourceFrom, int piHowMany)
{
for(int i = 0; i < piHowMany; i++)
pafDestination[piDestinationFrom + i] = pacSource[piSourceFrom + i];
}
/**
* Copy-conversion method that copies N character elements
* from an array of characters into array of floats.
*
* @param pafDestination destination array of floats
* @param pacSource source array of characters
* @param piHowMany N; how many elements to copy
* @since 0.3.0.3
*/
public static void copy(float[] pafDestination, char[] pacSource, int piHowMany)
{
copy(pafDestination, 0, pacSource, 0, piHowMany);
}
/**
* Copy-conversion method that copies all character elements
* from an array of characters into array of floats.
*
* @param pafDestination destination array of floats
* @param pacSource source array of characters
* @since 0.3.0.3
*/
public static void copy(float[] pafDestination, char[] pacSource)
{
copy(pafDestination, 0, pacSource, 0, pacSource.length);
}
/**
* General copy-conversion method that copies N character elements
* from an array of characters into array of doubles.
*
* @param padDestination destination array of doubles
* @param piDestinationFrom index in the destination to start place elements at
* @param pacSource source array of characters
* @param piSourceFrom index in the source to start take elements from
* @param piHowMany N; how many elements to copy
* @since 0.3.0.3
*/
public static void copy(double[] padDestination, int piDestinationFrom, char[] pacSource, int piSourceFrom, int piHowMany)
{
for(int i = 0; i < piHowMany; i++)
padDestination[piDestinationFrom + i] = pacSource[piSourceFrom + i];
}
/**
* Copy-conversion method that copies N character elements
* from an array of characters into array of doubles.
*
* @param padDestination destination array of doubles
* @param pacSource source array of characters
* @param piHowMany N; how many elements to copy
* @since 0.3.0.3
*/
public static void copy(double[] padDestination, char[] pacSource, int piHowMany)
{
copy(padDestination, 0, pacSource, 0, piHowMany);
}
/**
* Copy-conversion method that copies all character elements
* from an array of characters into array of doubles.
*
* @param padDestination destination array of doubles
* @param pacSource source array of characters
* @since 0.3.0.3
*/
public static void copy(double[] padDestination, char[] pacSource)
{
copy(padDestination, 0, pacSource, 0, pacSource.length);
}
/**
* General copy-conversion method that copies N int elements
* from an array of ints into array of Strings.
*
* @param pstrDestination destination array of Strings
* @param piDestinationFrom index in the destination to start place elements at
* @param paiSource source array of ints
* @param piSourceFrom index in the source to start take elements from
* @param piHowMany N; how many elements to copy
* @since 0.3.0.3
*/
public static void copy(String[] pstrDestination, int piDestinationFrom, int[] paiSource, int piSourceFrom, int piHowMany)
{
for(int i = 0; i < piHowMany; i++)
pstrDestination[piDestinationFrom + i] = paiSource[piSourceFrom + i] + "";
}
/**
* Copy-conversion method that copies N int elements
* from an array of ints into array of Strings.
*
* @param pstrDestination destination array of Strings
* @param paiSource source array of ints
* @param piHowMany N; how many elements to copy
* @since 0.3.0.3
*/
public static void copy(String[] pstrDestination, int[] paiSource, int piHowMany)
{
copy(pstrDestination, 0, paiSource, 0, piHowMany);
}
/**
* Copy-conversion method that copies all int elements
* from an array of ints into array of Strings.
*
* @param pstrDestination destination array of Strings
* @param paiSource source array of ints
* @since 0.3.0.3
*/
public static void copy(String[] pstrDestination, int[] paiSource)
{
copy(pstrDestination, 0, paiSource, 0, paiSource.length);
}
/**
* General copy-conversion method that copies N char elements
* from an array of chars into array of Strings.
*
* @param pstrDestination destination array of Strings
* @param piDestinationFrom index in the destination to start place elements at
* @param pacSource source array of chars
* @param piSourceFrom index in the source to start take elements from
* @param piHowMany N; how many elements to copy
* @since 0.3.0.3
*/
public static void copy(String[] pstrDestination, int piDestinationFrom, char[] pacSource, int piSourceFrom, int piHowMany)
{
for(int i = 0; i < piHowMany; i++)
pstrDestination[piDestinationFrom + i] = pacSource[piSourceFrom + i] + "";
}
/**
* Copy-conversion method that copies N char elements
* from an array of chars into array of Strings.
*
* @param pstrDestination destination array of Strings
* @param pacSource source array of chars
* @param piHowMany N; how many elements to copy
* @since 0.3.0.3
*/
public static void copy(String[] pstrDestination, char[] pacSource, int piHowMany)
{
copy(pstrDestination, 0, pacSource, 0, piHowMany);
}
/**
* Copy-conversion method that copies all char elements
* from an array of chars into array of Strings.
*
* @param pstrDestination destination array of Strings
* @param pacSource source array of chars
* @since 0.3.0.3
*/
public static void copy(String[] pstrDestination, char[] pacSource)
{
copy(pstrDestination, 0, pacSource, 0, pacSource.length);
}
/**
* General copy-conversion method that copies N byte elements
* from an array of bytes into array of Strings.
*
* @param pstrDestination destination array of Strings
* @param piDestinationFrom index in the destination to start place elements at
* @param patSource source array of bytes
* @param piSourceFrom index in the source to start take elements from
* @param piHowMany N; how many elements to copy
* @since 0.3.0.3
*/
public static void copy(String[] pstrDestination, int piDestinationFrom, byte[] patSource, int piSourceFrom, int piHowMany)
{
for(int i = 0; i < piHowMany; i++)
pstrDestination[piDestinationFrom + i] = patSource[piSourceFrom + i] + "";
}
/**
* Copy-conversion method that copies N byte elements
* from an array of bytes into array of Strings.
*
* @param pstrDestination destination array of Strings
* @param patSource source array of bytes
* @param piHowMany N; how many elements to copy
* @since 0.3.0.3
*/
public static void copy(String[] pstrDestination, byte[] patSource, int piHowMany)
{
copy(pstrDestination, 0, patSource, 0, piHowMany);
}
/**
* Copy-conversion method that copies all byte elements
* from an array of ints into array of Strings.
*
* @param pstrDestination destination array of Strings
* @param patSource source array of bytes
* @since 0.3.0.3
*/
public static void copy(String[] pstrDestination, byte[] patSource)
{
copy(pstrDestination, 0, patSource, 0, patSource.length);
}
/**
* General copy-conversion method that copies N short elements
* from an array of shorts into array of Strings.
*
* @param pstrDestination destination array of Strings
* @param piDestinationFrom index in the destination to start place elements at
* @param pasSource source array of shorts
* @param piSourceFrom index in the source to start take elements from
* @param piHowMany N; how many elements to copy
* @since 0.3.0.3
*/
public static void copy(String[] pstrDestination, int piDestinationFrom, short[] pasSource, int piSourceFrom, int piHowMany)
{
for(int i = 0; i < piHowMany; i++)
pstrDestination[piDestinationFrom + i] = pasSource[piSourceFrom + i] + "";
}
/**
* Copy-conversion method that copies N short elements
* from an array of shorts into array of Strings.
*
* @param pstrDestination destination array of Strings
* @param patSource source array of shorts
* @param piHowMany N; how many elements to copy
* @since 0.3.0.3
*/
public static void copy(String[] pstrDestination, short[] patSource, int piHowMany)
{
copy(pstrDestination, 0, patSource, 0, piHowMany);
}
/**
* Copy-conversion method that copies all short elements
* from an array of shorts into array of Strings.
*
* @param pstrDestination destination array of Strings
* @param pasSource source array of shorts
* @since 0.3.0.3
*/
public static void copy(String[] pstrDestination, short[] pasSource)
{
copy(pstrDestination, 0, pasSource, 0, pasSource.length);
}
/**
* General copy-conversion method that copies N long elements
* from an array of longs into array of Strings.
*
* @param pstrDestination destination array of Strings
* @param piDestinationFrom index in the destination to start place elements at
* @param palSource source array of longs
* @param piSourceFrom index in the source to start take elements from
* @param piHowMany N; how many elements to copy
* @since 0.3.0.3
*/
public static void copy(String[] pstrDestination, int piDestinationFrom, long[] palSource, int piSourceFrom, int piHowMany)
{
for(int i = 0; i < piHowMany; i++)
pstrDestination[piDestinationFrom + i] = palSource[piSourceFrom + i] + "";
}
/**
* Copy-conversion method that copies N long elements
* from an array of longs into array of Strings.
*
* @param pstrDestination destination array of Strings
* @param palSource source array of longs
* @param piHowMany N; how many elements to copy
* @since 0.3.0.3
*/
public static void copy(String[] pstrDestination, long[] palSource, int piHowMany)
{
copy(pstrDestination, 0, palSource, 0, piHowMany);
}
/**
* Copy-conversion method that copies all long elements
* from an array of longs into array of Strings.
*
* @param pstrDestination destination array of Strings
* @param palSource source array of longs
* @since 0.3.0.3
*/
public static void copy(String[] pstrDestination, long[] palSource)
{
copy(pstrDestination, 0, palSource, 0, palSource.length);
}
/**
* General copy-conversion method that copies N float elements
* from an array of floats into array of Strings.
*
* @param pstrDestination destination array of Strings
* @param piDestinationFrom index in the destination to start place elements at
* @param pafSource source array of floats
* @param piSourceFrom index in the source to start take elements from
* @param piHowMany N; how many elements to copy
* @since 0.3.0.3
*/
public static void copy(String[] pstrDestination, int piDestinationFrom, float[] pafSource, int piSourceFrom, int piHowMany)
{
for(int i = 0; i < piHowMany; i++)
pstrDestination[piDestinationFrom + i] = pafSource[piSourceFrom + i] + "";
}
/**
* Copy-conversion method that copies N float elements
* from an array of floats into array of Strings.
*
* @param pstrDestination destination array of Strings
* @param pafSource source array of floats
* @param piHowMany N; how many elements to copy
* @since 0.3.0.3
*/
public static void copy(String[] pstrDestination, float[] pafSource, int piHowMany)
{
copy(pstrDestination, 0, pafSource, 0, piHowMany);
}
/**
* Copy-conversion method that copies all float elements
* from an array of floats into array of Strings.
*
* @param pstrDestination destination array of Strings
* @param pafSource source array of floats
* @since 0.3.0.3
*/
public static void copy(String[] pstrDestination, float[] pafSource)
{
copy(pstrDestination, 0, pafSource, 0, pafSource.length);
}
/**
* General copy-conversion method that copies N double elements
* from an array of doubles into array of Strings.
*
* @param pstrDestination destination array of Strings
* @param piDestinationFrom index in the destination to start place elements at
* @param padSource source array of doubles
* @param piSourceFrom index in the source to start take elements from
* @param piHowMany N; how many elements to copy
* @since 0.3.0.3
*/
public static void copy(String[] pstrDestination, int piDestinationFrom, double[] padSource, int piSourceFrom, int piHowMany)
{
for(int i = 0; i < piHowMany; i++)
pstrDestination[piDestinationFrom + i] = padSource[piSourceFrom + i] + "";
}
/**
* Copy-conversion method that copies N double elements
* from an array of doubles into array of Strings.
*
* @param pstrDestination destination array of Strings
* @param padSource source array of doubles
* @param piHowMany N; how many elements to copy
* @since 0.3.0.3
*/
public static void copy(String[] pstrDestination, double[] padSource, int piHowMany)
{
copy(pstrDestination, 0, padSource, 0, piHowMany);
}
/**
* Copy-conversion method that copies all double elements
* from an array of doubles into array of Strings.
*
* @param pstrDestination destination array of Strings
* @param padSource source array of doubles
* @since 0.3.0.3
*/
public static void copy(String[] pstrDestination, double[] padSource)
{
copy(pstrDestination, 0, padSource, 0, padSource.length);
}
/**
* General copy-conversion method that copies N String elements
* from an array of Strings into array of doubles.
*
* @param padDestination destination array of doubles
* @param piDestinationFrom index in the destination to start place elements at
* @param pastrSource source array of Strings
* @param piSourceFrom index in the source to start take elements from
* @param piHowMany N; how many elements to copy
*
* @throws NumberFormatException if one of the Strings doesn"t have a properly formatted number
* @since 0.3.0.3
*/
public static void copy(double[] padDestination, int piDestinationFrom, String[] pastrSource, int piSourceFrom, int piHowMany)
{
for(int i = 0; i < piHowMany; i++)
padDestination[piDestinationFrom + i] = Double.parseDouble(pastrSource[piSourceFrom + i]);
}
/**
* Copy-conversion method that copies N String elements
* from an array of Strings into array of doubles.
*
* @param padDestination destination array of doubles
* @param pastrSource source array of Strings
* @param piHowMany N; how many elements to copy
* @since 0.3.0.3
*/
public static void copy(double[] padDestination, String[] pastrSource, int piHowMany)
{
copy(padDestination, 0, pastrSource, 0, piHowMany);
}
/**
* Copy-conversion method that copies all String elements
* from an array of Strings into array of doubles.
*
* @param padDestination destination array of doubles
* @param pastrSource source array of Strings
* @since 0.3.0.3
*/
public static void copy(double[] padDestination, String[] pastrSource)
{
copy(padDestination, 0, pastrSource, 0, pastrSource.length);
}
/**
* General copy-conversion method that copies N String elements
* from an array of Strings into array of floats.
*
* @param pafDestination destination array of floats
* @param piDestinationFrom index in the destination to start place elements at
* @param pastrSource source array of Strings
* @param piSourceFrom index in the source to start take elements from
* @param piHowMany N; how many elements to copy
*
* @throws NumberFormatException if one of the Strings doesn"t have a properly formatted number
* @since 0.3.0.3
*/
public static void copy(float[] pafDestination, int piDestinationFrom, String[] pastrSource, int piSourceFrom, int piHowMany)
{
for(int i = 0; i < piHowMany; i++)
pafDestination[piDestinationFrom + i] = Float.parseFloat(pastrSource[piSourceFrom + i]);
}
/**
* Copy-conversion method that copies N String elements
* from an array of Strings into array of floats.
*
* @param pafDestination destination array of floats
* @param pastrSource source array of Strings
* @param piHowMany N; how many elements to copy
* @since 0.3.0.3
*/
public static void copy(float[] pafDestination, String[] pastrSource, int piHowMany)
{
copy(pafDestination, 0, pastrSource, 0, piHowMany);
}
/**
* Copy-conversion method that copies all String elements
* from an array of Strings into array of floats.
*
* @param pafDestination destination array of floats
* @param pastrSource source array of Strings
*/
public static void copy(float[] pafDestination, String[] pastrSource)
{
copy(pafDestination, 0, pastrSource, 0, pastrSource.length);
}
/**
* General copy-conversion method that copies N String elements
* from an array of Strings into array of longs.
*
* @param palDestination destination array of longs
* @param piDestinationFrom index in the destination to start place elements at
* @param pastrSource source array of Strings
* @param piSourceFrom index in the source to start take elements from
* @param piHowMany N; how many elements to copy
*
* @throws NumberFormatException if one of the Strings doesn"t have a properly formatted number
* @since 0.3.0.3
*/
public static void copy(long[] palDestination, int piDestinationFrom, String[] pastrSource, int piSourceFrom, int piHowMany)
{
for(int i = 0; i < piHowMany; i++)
palDestination[piDestinationFrom + i] = Long.parseLong(pastrSource[piSourceFrom + i]);
}
/**
* Copy-conversion method that copies N String elements
* from an array of Strings into array of longs.
*
* @param palDestination destination array of longs
* @param pastrSource source array of Strings
* @param piHowMany N; how many elements to copy
* @since 0.3.0.3
*/
public static void copy(long[] palDestination, String[] pastrSource, int piHowMany)
{
copy(palDestination, 0, pastrSource, 0, piHowMany);
}
/**
* Copy-conversion method that copies all String elements
* from an array of Strings into array of longs.
*
* @param palDestination destination array of longs
* @param pastrSource source array of Strings
* @since 0.3.0.3
*/
public static void copy(long[] palDestination, String[] pastrSource)
{
copy(palDestination, 0, pastrSource, 0, pastrSource.length);
}
/**
* General copy-conversion method that copies N String elements
* from an array of Strings into array of integers.
*
* @param paiDestination destination array of integers
* @param piDestinationFrom index in the destination to start place elements at
* @param pastrSource source array of Strings
* @param piSourceFrom index in the source to start take elements from
* @param piHowMany N; how many elements to copy
*
* @throws NumberFormatException if one of the Strings doesn"t have a properly formatted number
* @since 0.3.0.3
*/
public static void copy(int[] paiDestination, int piDestinationFrom, String[] pastrSource, int piSourceFrom, int piHowMany)
{
for(int i = 0; i < piHowMany; i++)
paiDestination[piDestinationFrom + i] = Integer.parseInt(pastrSource[piSourceFrom + i]);
}
/**
* Copy-conversion method that copies N String elements
* from an array of Strings into array of integers.
*
* @param paiDestination destination array of integers
* @param pastrSource source array of Strings
* @param piHowMany N; how many elements to copy
* @since 0.3.0.3
*/
public static void copy(int[] paiDestination, String[] pastrSource, int piHowMany)
{
copy(paiDestination, 0, pastrSource, 0, piHowMany);
}
/**
* Copy-conversion method that copies all String elements
* from an array of Strings into array of integers.
*
* @param paiDestination destination array of integers
* @param pastrSource source array of Strings
* @since 0.3.0.3
*/
public static void copy(int[] paiDestination, String[] pastrSource)
{
copy(paiDestination, 0, pastrSource, 0, pastrSource.length);
}
/**
* General copy-conversion method that copies N String elements
* from an array of Strings into array of shorts.
*
* @param pasDestination destination array of shorts
* @param piDestinationFrom index in the destination to start place elements at
* @param pastrSource source array of Strings
* @param piSourceFrom index in the source to start take elements from
* @param piHowMany N; how many elements to copy
*
* @throws NumberFormatException if one of the Strings doesn"t have a properly formatted number
* @since 0.3.0.3
*/
public static void copy(short[] pasDestination, int piDestinationFrom, String[] pastrSource, int piSourceFrom, int piHowMany)
{
for(int i = 0; i < piHowMany; i++)
pasDestination[piDestinationFrom + i] = Short.parseShort(pastrSource[piSourceFrom + i]);
}
/**
* Copy-conversion method that copies N String elements
* from an array of Strings into array of shorts.
*
* @param pasDestination destination array of shorts
* @param pastrSource source array of Strings
* @param piHowMany N; how many elements to copy
* @since 0.3.0.3
*/
public static void copy(short[] pasDestination, String[] pastrSource, int piHowMany)
{
copy(pasDestination, 0, pastrSource, 0, piHowMany);
}
/**
* Copy-conversion method that copies all String elements
* from an array of Strings into array of shorts.
*
* @param pasDestination destination array of shorts
* @param pastrSource source array of Strings
* @since 0.3.0.3
*/
public static void copy(short[] pasDestination, String[] pastrSource)
{
copy(pasDestination, 0, pastrSource, 0, pastrSource.length);
}
/**
* General copy-conversion method that copies N String elements
* from an array of Strings into array of bytes.
*
* @param patDestination destination array of bytes
* @param piDestinationFrom index in the destination to start place elements at
* @param pastrSource source array of Strings
* @param piSourceFrom index in the source to start take elements from
* @param piHowMany N; how many elements to copy
*
* @throws NumberFormatException if one of the Strings doesn"t have a properly formatted number
* @since 0.3.0.3
*/
public static void copy(byte[] patDestination, int piDestinationFrom, String[] pastrSource, int piSourceFrom, int piHowMany)
{
for(int i = 0; i < piHowMany; i++)
patDestination[piDestinationFrom + i] = Byte.parseByte(pastrSource[piSourceFrom + i]);
}
/**
* Copy-conversion method that copies N String elements
* from an array of Strings into array of bytes.
*
* @param patDestination destination array of bytes
* @param pastrSource source array of Strings
* @param piHowMany N; how many elements to copy
* @since 0.3.0.3
*/
public static void copy(byte[] patDestination, String[] pastrSource, int piHowMany)
{
copy(patDestination, 0, pastrSource, 0, piHowMany);
}
/**
* Copy-conversion method that copies all String elements
* from an array of Strings into array of bytes.
*
* @param patDestination destination array of bytes
* @param pastrSource source array of Strings
* @since 0.3.0.3
*/
public static void copy(byte[] patDestination, String[] pastrSource)
{
copy(patDestination, 0, pastrSource, 0, pastrSource.length);
}
/*
* -------------
* Binary Search
* -------------
*/
/**
* The <code>binarySearch()</code> routine is based on <code>java.util.Arrays.binarySearch()</code>.
*
* @param pafArray the array of floats to be searched
* @param pfValue the value of float to be searched in the array of floats
* @return index of the searched value if it is in the array of floats
* @since 0.3.0.3
*/
public static int binarySearch(float[] pafArray, float pfValue)
{
return java.util.Arrays.binarySearch(pafArray, pfValue);
}
/**
* The <code>binarySearch()</code> routine is based on <code>java.util.Arrays.binarySearch()</code>.
*
* @param padArray the array of doubles to be searched
* @param pdValue the value of double to be searched in the array of doubles
* @return index of the searched value if it is in the array of doubles
* @since 0.3.0.3
*/
public static int binarySearch(double[] padArray, double pdValue)
{
return java.util.Arrays.binarySearch(padArray, pdValue);
}
/**
* The <code>binarySearch()</code> routine is based on <code>java.util.Arrays.binarySearch()</code>.
*
* @param pasArray the array of shorts to be searched
* @param psValue the value of shorts to be searched in the array of shorts
* @return index of the searched value if it is in the array of shorts
* @since 0.3.0.3
*/
public static int binarySearch(short[] pasArray, short psValue)
{
return java.util.Arrays.binarySearch(pasArray, psValue);
}
/**
* The <code>binarySearch()</code> routine is based on <code>java.util.Arrays.binarySearch()</code>.
*
* @param paiArray the array of integers to be searched
* @param piValue the value of integer to be searched in the array of integers
* @return index of the searched value if it is in the array of integers
* @since 0.3.0.3
*/
public static int binarySearch(int[] paiArray, int piValue)
{
return java.util.Arrays.binarySearch(paiArray, piValue);
}
/**
* The <code>binarySearch()</code> routine is based on <code>java.util.Arrays.binarySearch()</code>.
*
* @param patArray the array of bytes to be searched
* @param ptValue the value of byte to be searched in the array of bytes
* @return index of the searched value if it is in the array of bytes
* @since 0.3.0.3
*/
public static int binarySearch(byte[] patArray, byte ptValue)
{
return java.util.Arrays.binarySearch(patArray, ptValue);
}
/**
* The <code>binarySearch()</code> routine is based on <code>java.util.Arrays.binarySearch()</code>.
*
* @param pacArray the array of characters to be searched
* @param pcValue the value of character to be searched in the array of characters
* @return index of the searched value if it is in the array of characters
* @since 0.3.0.3
*/
public static int binarySearch(char[] pacArray, char pcValue)
{
return java.util.Arrays.binarySearch(pacArray, pcValue);
}
/**
* The <code>binarySearch()</code> routine is based on <code>java.util.Arrays.binarySearch()</code>.
*
* @param paoArray the array of objects to be searched
* @param poValue the value of object to be searched in the array of objects
* @return index of the searched value if it is in the array of objects
* @throws ClassCastException if the type of the searched value is not match the type of the array
* @since 0.3.0.3
*/
public static int binarySearch(Object[] paoArray, Object poValue)
{
return java.util.Arrays.binarySearch(paoArray, poValue);
}
/**
* The <code>binarySearch()</code> routine is based on <code>java.util.Arrays.binarySearch()</code>.
*
* @param paoArray the array of objects to be searched
* @param poValue the value of object to be searched in the array of objects
* @param poComparator the comparator to decide the order of the array
* @return index of the searched value if it is in the array of objects
* @throws ClassCastException if the type of the searched value is not match the type of the array
* @since 0.3.0.3
*/
public static int binarySearch(Object[] paoArray, Object poValue, Comparator poComparator)
{
return java.util.Arrays.binarySearch(paoArray, poValue, poComparator);
}
/*
* ----
* Misc
* ----
*/
/**
* Returns source code revision information.
*
* @return revision string
* @since 0.3.0.2
*/
public static String getMARFSourceCodeRevision()
{
return "$Revision: 1.38 $";
}
}
// EOF
Concatenate Java arrays
/*
* Convenience methods for working with Java arrays.
* Copyright (C) 2005 Stephen Ostermiller
* http://ostermiller.org/contact.pl?regarding=Java+Utilities
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* See COPYING.TXT for details.
*/
import java.io.IOException;
import java.lang.reflect.Array;
/**
* Convenience methods for working with Java arrays.
* More information about this class is available from .
*
* @author Stephen Ostermiller http://ostermiller.org/contact.pl?regarding=Java+Utilities
* @since ostermillerutils 1.06.00
*/
public final class ArrayHelper {
/**
* Concatenates the given arrays into a single long array.
* The returned array will be of the common super type of the
* two given arrays.
* <p>
* For example it can be called like this:<br>
* <pre>
* String[] arr = (String[])ArrayHelper.cat(new String[]{"one","two"}, new String[]{"three","four"});
* </pre>
*
* @param arr1 first array
* @param arr2 second array
* @return an array whose length is the sum of the given array"s lengths and contains all the elements in the given arrays.
* @since ostermillerutils 1.06.00
*/
public static Object[] cat(Object[] arr1, Object[] arr2){
// Use reflection to find the super class of both arrays
Class<?> commonSuperClass = Object.class;
boolean foundcommonSuperClass=false;
for (Class<?> c1 = arr1.getClass().getComponentType(); !foundcommonSuperClass && !c1.equals(Object.class); c1 = c1.getSuperclass()){
for (Class<?> c2 = arr2.getClass().getComponentType(); !foundcommonSuperClass && !c2.equals(Object.class); c2 = c2.getSuperclass()){
if (c2.equals(c1)){
foundcommonSuperClass = true;
commonSuperClass = c1;
}
}
}
// Create a new array of the correct type
Object[] result = (Object[])Array.newInstance(commonSuperClass, arr1.length + arr2.length);
// Copy the two arrays into the large array
System.arraycopy(arr1, 0, result, 0, arr1.length);
System.arraycopy(arr2, 0, result, arr1.length, arr2.length);
return result;
}
/**
* Tests two arrays to see if the arrays are equal.
* Two arrays will be equal only if they are the same length
* and contain objects that are equal in the same order.
*
* @param arr1 first array
* @param arr2 second array
* @return true iff two arguments are equal
* @since ostermillerutils 1.06.00
*/
public static boolean equal(Object[] arr1, Object[] arr2){
if (arr1 == null && arr2 == null) return true;
if (arr1 == null || arr2 == null) return false;
if (arr1.length != arr2.length) return false;
for (int i=0; i<arr1.length; i++){
if (!equalObjects(arr1[i], arr2[i])) return false;
}
return true;
}
/**
* Tests if the two objects are equal
*
* @param o1 first object
* @param o2 second object
* @since ostermillerutils 1.06.00
*/
private static boolean equalObjects(Object o1, Object o2){
if (o1 == null && o2 == null) return true;
if (o1 == null || o2 == null) return false;
return o1.equals(o2);
}
}
Copies the given array and adds the given element at the end of the new array.(boolean value type)
/* Copyright 2004 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import java.lang.reflect.Array;
/**
* <p>Operations on arrays, primitive arrays (like <code>int[]</code>) and
* primitive wrapper arrays (like <code>Integer[]</code>).</p>
*
* <p>This class tries to handle <code>null</code> input gracefully.
* An exception will not be thrown for a <code>null</code>
* array input. However, an Object array that contains a <code>null</code>
* element may throw an exception. Each method documents its behaviour.</p>
*
* @author Stephen Colebourne
* @author Moritz Petersen
* @author
* @author Maarten Coene
* @since 2.0
* @version $Id: ArrayUtils.java 632503 2008-03-01 00:21:52Z ggregory $
*/
public class Main {
/**
* <p>Copies the given array and adds the given element at the end of the new array.</p>
*
* <p>The new array contains the same elements of the input
* array plus the given element in the last position. The component type of
* the new array is the same as that of the input array.</p>
*
* <p>If the input array is <code>null</code>, a new one element array is returned
* whose component type is the same as the element.</p>
*
* <pre>
* ArrayUtils.add(null, true) = [true]
* ArrayUtils.add([true], false) = [true, false]
* ArrayUtils.add([true, false], true) = [true, false, true]
* </pre>
*
* @param array the array to copy and add the element to, may be <code>null</code>
* @param element the object to add at the last index of the new array
* @return A new array containing the existing elements plus the new element
* @since 2.1
*/
public static boolean[] add(boolean[] array, boolean element) {
boolean[] newArray = (boolean[])copyArrayGrow1(array, Boolean.TYPE);
newArray[newArray.length - 1] = element;
return newArray;
}
/**
* Returns a copy of the given array of size 1 greater than the argument.
* The last value of the array is left to the default value.
*
* @param array The array to copy, must not be <code>null</code>.
* @param newArrayComponentType If <code>array</code> is <code>null</code>, create a
* size 1 array of this type.
* @return A new copy of the array of size 1 greater than the input.
*/
private static Object copyArrayGrow1(Object array, Class newArrayComponentType) {
if (array != null) {
int arrayLength = Array.getLength(array);
Object newArray = Array.newInstance(array.getClass().getComponentType(), arrayLength + 1);
System.arraycopy(array, 0, newArray, 0, arrayLength);
return newArray;
}
return Array.newInstance(newArrayComponentType, 1);
}
}
Copies the given array and adds the given element at the end of the new array.(byte value type)
/* Copyright 2004 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import java.lang.reflect.Array;
/**
* <p>Operations on arrays, primitive arrays (like <code>int[]</code>) and
* primitive wrapper arrays (like <code>Integer[]</code>).</p>
*
* <p>This class tries to handle <code>null</code> input gracefully.
* An exception will not be thrown for a <code>null</code>
* array input. However, an Object array that contains a <code>null</code>
* element may throw an exception. Each method documents its behaviour.</p>
*
* @author Stephen Colebourne
* @author Moritz Petersen
* @author
* @author Maarten Coene
* @since 2.0
* @version $Id: ArrayUtils.java 632503 2008-03-01 00:21:52Z ggregory $
*/
public class Main {
/**
* <p>Copies the given array and adds the given element at the end of the new array.</p>
*
* <p>The new array contains the same elements of the input
* array plus the given element in the last position. The component type of
* the new array is the same as that of the input array.</p>
*
* <p>If the input array is <code>null</code>, a new one element array is returned
* whose component type is the same as the element.</p>
*
* <pre>
* ArrayUtils.add(null, 0) = [0]
* ArrayUtils.add([1], 0) = [1, 0]
* ArrayUtils.add([1, 0], 1) = [1, 0, 1]
* </pre>
*
* @param array the array to copy and add the element to, may be <code>null</code>
* @param element the object to add at the last index of the new array
* @return A new array containing the existing elements plus the new element
* @since 2.1
*/
public static byte[] add(byte[] array, byte element) {
byte[] newArray = (byte[])copyArrayGrow1(array, Byte.TYPE);
newArray[newArray.length - 1] = element;
return newArray;
}
/**
* Returns a copy of the given array of size 1 greater than the argument.
* The last value of the array is left to the default value.
*
* @param array The array to copy, must not be <code>null</code>.
* @param newArrayComponentType If <code>array</code> is <code>null</code>, create a
* size 1 array of this type.
* @return A new copy of the array of size 1 greater than the input.
*/
private static Object copyArrayGrow1(Object array, Class newArrayComponentType) {
if (array != null) {
int arrayLength = Array.getLength(array);
Object newArray = Array.newInstance(array.getClass().getComponentType(), arrayLength + 1);
System.arraycopy(array, 0, newArray, 0, arrayLength);
return newArray;
}
return Array.newInstance(newArrayComponentType, 1);
}
}
Copies the given array and adds the given element at the end of the new array. (char type value)
/* Copyright 2004 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import java.lang.reflect.Array;
/**
* <p>Operations on arrays, primitive arrays (like <code>int[]</code>) and
* primitive wrapper arrays (like <code>Integer[]</code>).</p>
*
* <p>This class tries to handle <code>null</code> input gracefully.
* An exception will not be thrown for a <code>null</code>
* array input. However, an Object array that contains a <code>null</code>
* element may throw an exception. Each method documents its behaviour.</p>
*
* @author Stephen Colebourne
* @author Moritz Petersen
* @author
* @author Maarten Coene
* @since 2.0
* @version $Id: ArrayUtils.java 632503 2008-03-01 00:21:52Z ggregory $
*/
public class Main {
/**
* <p>Copies the given array and adds the given element at the end of the new array.</p>
*
* <p>The new array contains the same elements of the input
* array plus the given element in the last position. The component type of
* the new array is the same as that of the input array.</p>
*
* <p>If the input array is <code>null</code>, a new one element array is returned
* whose component type is the same as the element.</p>
*
* <pre>
* ArrayUtils.add(null, "0") = ["0"]
* ArrayUtils.add(["1"], "0") = ["1", "0"]
* ArrayUtils.add(["1", "0"], "1") = ["1", "0", "1"]
* </pre>
*
* @param array the array to copy and add the element to, may be <code>null</code>
* @param element the object to add at the last index of the new array
* @return A new array containing the existing elements plus the new element
* @since 2.1
*/
public static char[] add(char[] array, char element) {
char[] newArray = (char[])copyArrayGrow1(array, Character.TYPE);
newArray[newArray.length - 1] = element;
return newArray;
}
/**
* Returns a copy of the given array of size 1 greater than the argument.
* The last value of the array is left to the default value.
*
* @param array The array to copy, must not be <code>null</code>.
* @param newArrayComponentType If <code>array</code> is <code>null</code>, create a
* size 1 array of this type.
* @return A new copy of the array of size 1 greater than the input.
*/
private static Object copyArrayGrow1(Object array, Class newArrayComponentType) {
if (array != null) {
int arrayLength = Array.getLength(array);
Object newArray = Array.newInstance(array.getClass().getComponentType(), arrayLength + 1);
System.arraycopy(array, 0, newArray, 0, arrayLength);
return newArray;
}
return Array.newInstance(newArrayComponentType, 1);
}
}
Copies the given array and adds the given element at the end of the new array.(double type value)
/* Copyright 2004 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import java.lang.reflect.Array;
/**
* <p>Operations on arrays, primitive arrays (like <code>int[]</code>) and
* primitive wrapper arrays (like <code>Integer[]</code>).</p>
*
* <p>This class tries to handle <code>null</code> input gracefully.
* An exception will not be thrown for a <code>null</code>
* array input. However, an Object array that contains a <code>null</code>
* element may throw an exception. Each method documents its behaviour.</p>
*
* @author Stephen Colebourne
* @author Moritz Petersen
* @author
* @author Maarten Coene
* @since 2.0
* @version $Id: ArrayUtils.java 632503 2008-03-01 00:21:52Z ggregory $
*/
public class Main {
/**
* <p>Copies the given array and adds the given element at the end of the new array.</p>
*
* <p>The new array contains the same elements of the input
* array plus the given element in the last position. The component type of
* the new array is the same as that of the input array.</p>
*
* <p>If the input array is <code>null</code>, a new one element array is returned
* whose component type is the same as the element.</p>
*
* <pre>
* ArrayUtils.add(null, 0) = [0]
* ArrayUtils.add([1], 0) = [1, 0]
* ArrayUtils.add([1, 0], 1) = [1, 0, 1]
* </pre>
*
* @param array the array to copy and add the element to, may be <code>null</code>
* @param element the object to add at the last index of the new array
* @return A new array containing the existing elements plus the new element
* @since 2.1
*/
public static double[] add(double[] array, double element) {
double[] newArray = (double[])copyArrayGrow1(array, Double.TYPE);
newArray[newArray.length - 1] = element;
return newArray;
}
/**
* Returns a copy of the given array of size 1 greater than the argument.
* The last value of the array is left to the default value.
*
* @param array The array to copy, must not be <code>null</code>.
* @param newArrayComponentType If <code>array</code> is <code>null</code>, create a
* size 1 array of this type.
* @return A new copy of the array of size 1 greater than the input.
*/
private static Object copyArrayGrow1(Object array, Class newArrayComponentType) {
if (array != null) {
int arrayLength = Array.getLength(array);
Object newArray = Array.newInstance(array.getClass().getComponentType(), arrayLength + 1);
System.arraycopy(array, 0, newArray, 0, arrayLength);
return newArray;
}
return Array.newInstance(newArrayComponentType, 1);
}
}
Copies the given array and adds the given element at the end of the new array. (float type value)
/* Copyright 2004 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import java.lang.reflect.Array;
/**
* <p>Operations on arrays, primitive arrays (like <code>int[]</code>) and
* primitive wrapper arrays (like <code>Integer[]</code>).</p>
*
* <p>This class tries to handle <code>null</code> input gracefully.
* An exception will not be thrown for a <code>null</code>
* array input. However, an Object array that contains a <code>null</code>
* element may throw an exception. Each method documents its behaviour.</p>
*
* @author Stephen Colebourne
* @author Moritz Petersen
* @author
* @author Maarten Coene
* @since 2.0
* @version $Id: ArrayUtils.java 632503 2008-03-01 00:21:52Z ggregory $
*/
public class Main {
/**
* <p>Copies the given array and adds the given element at the end of the new array.</p>
*
* <p>The new array contains the same elements of the input
* array plus the given element in the last position. The component type of
* the new array is the same as that of the input array.</p>
*
* <p>If the input array is <code>null</code>, a new one element array is returned
* whose component type is the same as the element.</p>
*
* <pre>
* ArrayUtils.add(null, 0) = [0]
* ArrayUtils.add([1], 0) = [1, 0]
* ArrayUtils.add([1, 0], 1) = [1, 0, 1]
* </pre>
*
* @param array the array to copy and add the element to, may be <code>null</code>
* @param element the object to add at the last index of the new array
* @return A new array containing the existing elements plus the new element
* @since 2.1
*/
public static float[] add(float[] array, float element) {
float[] newArray = (float[])copyArrayGrow1(array, Float.TYPE);
newArray[newArray.length - 1] = element;
return newArray;
}
/**
* Returns a copy of the given array of size 1 greater than the argument.
* The last value of the array is left to the default value.
*
* @param array The array to copy, must not be <code>null</code>.
* @param newArrayComponentType If <code>array</code> is <code>null</code>, create a
* size 1 array of this type.
* @return A new copy of the array of size 1 greater than the input.
*/
private static Object copyArrayGrow1(Object array, Class newArrayComponentType) {
if (array != null) {
int arrayLength = Array.getLength(array);
Object newArray = Array.newInstance(array.getClass().getComponentType(), arrayLength + 1);
System.arraycopy(array, 0, newArray, 0, arrayLength);
return newArray;
}
return Array.newInstance(newArrayComponentType, 1);
}
}
Copies the given array and adds the given element at the end of the new array.(int value type)
/* Copyright 2004 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import java.lang.reflect.Array;
/**
* <p>Operations on arrays, primitive arrays (like <code>int[]</code>) and
* primitive wrapper arrays (like <code>Integer[]</code>).</p>
*
* <p>This class tries to handle <code>null</code> input gracefully.
* An exception will not be thrown for a <code>null</code>
* array input. However, an Object array that contains a <code>null</code>
* element may throw an exception. Each method documents its behaviour.</p>
*
* @author Stephen Colebourne
* @author Moritz Petersen
* @author
* @author Maarten Coene
* @since 2.0
* @version $Id: ArrayUtils.java 632503 2008-03-01 00:21:52Z ggregory $
*/
public class Main {
/**
* <p>Copies the given array and adds the given element at the end of the new array.</p>
*
* <p>The new array contains the same elements of the input
* array plus the given element in the last position. The component type of
* the new array is the same as that of the input array.</p>
*
* <p>If the input array is <code>null</code>, a new one element array is returned
* whose component type is the same as the element.</p>
*
* <pre>
* ArrayUtils.add(null, 0) = [0]
* ArrayUtils.add([1], 0) = [1, 0]
* ArrayUtils.add([1, 0], 1) = [1, 0, 1]
* </pre>
*
* @param array the array to copy and add the element to, may be <code>null</code>
* @param element the object to add at the last index of the new array
* @return A new array containing the existing elements plus the new element
* @since 2.1
*/
public static int[] add(int[] array, int element) {
int[] newArray = (int[])copyArrayGrow1(array, Integer.TYPE);
newArray[newArray.length - 1] = element;
return newArray;
}
/**
* Returns a copy of the given array of size 1 greater than the argument.
* The last value of the array is left to the default value.
*
* @param array The array to copy, must not be <code>null</code>.
* @param newArrayComponentType If <code>array</code> is <code>null</code>, create a
* size 1 array of this type.
* @return A new copy of the array of size 1 greater than the input.
*/
private static Object copyArrayGrow1(Object array, Class newArrayComponentType) {
if (array != null) {
int arrayLength = Array.getLength(array);
Object newArray = Array.newInstance(array.getClass().getComponentType(), arrayLength + 1);
System.arraycopy(array, 0, newArray, 0, arrayLength);
return newArray;
}
return Array.newInstance(newArrayComponentType, 1);
}
}
Copies the given array and adds the given element at the end of the new array. (long value type)
/* Copyright 2004 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import java.lang.reflect.Array;
/**
* <p>Operations on arrays, primitive arrays (like <code>int[]</code>) and
* primitive wrapper arrays (like <code>Integer[]</code>).</p>
*
* <p>This class tries to handle <code>null</code> input gracefully.
* An exception will not be thrown for a <code>null</code>
* array input. However, an Object array that contains a <code>null</code>
* element may throw an exception. Each method documents its behaviour.</p>
*
* @author Stephen Colebourne
* @author Moritz Petersen
* @author
* @author Maarten Coene
* @since 2.0
* @version $Id: ArrayUtils.java 632503 2008-03-01 00:21:52Z ggregory $
*/
public class Main {
/**
* <p>Copies the given array and adds the given element at the end of the new array.</p>
*
* <p>The new array contains the same elements of the input
* array plus the given element in the last position. The component type of
* the new array is the same as that of the input array.</p>
*
* <p>If the input array is <code>null</code>, a new one element array is returned
* whose component type is the same as the element.</p>
*
* <pre>
* ArrayUtils.add(null, 0) = [0]
* ArrayUtils.add([1], 0) = [1, 0]
* ArrayUtils.add([1, 0], 1) = [1, 0, 1]
* </pre>
*
* @param array the array to copy and add the element to, may be <code>null</code>
* @param element the object to add at the last index of the new array
* @return A new array containing the existing elements plus the new element
* @since 2.1
*/
public static long[] add(long[] array, long element) {
long[] newArray = (long[])copyArrayGrow1(array, Long.TYPE);
newArray[newArray.length - 1] = element;
return newArray;
}
/**
* Returns a copy of the given array of size 1 greater than the argument.
* The last value of the array is left to the default value.
*
* @param array The array to copy, must not be <code>null</code>.
* @param newArrayComponentType If <code>array</code> is <code>null</code>, create a
* size 1 array of this type.
* @return A new copy of the array of size 1 greater than the input.
*/
private static Object copyArrayGrow1(Object array, Class newArrayComponentType) {
if (array != null) {
int arrayLength = Array.getLength(array);
Object newArray = Array.newInstance(array.getClass().getComponentType(), arrayLength + 1);
System.arraycopy(array, 0, newArray, 0, arrayLength);
return newArray;
}
return Array.newInstance(newArrayComponentType, 1);
}
}
Copies the given array and adds the given element at the end of the new array. (object value type)
/* Copyright 2004 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import java.lang.reflect.Array;
/**
* <p>Operations on arrays, primitive arrays (like <code>int[]</code>) and
* primitive wrapper arrays (like <code>Integer[]</code>).</p>
*
* <p>This class tries to handle <code>null</code> input gracefully.
* An exception will not be thrown for a <code>null</code>
* array input. However, an Object array that contains a <code>null</code>
* element may throw an exception. Each method documents its behaviour.</p>
*
* @author Stephen Colebourne
* @author Moritz Petersen
* @author
* @author Maarten Coene
* @since 2.0
* @version $Id: ArrayUtils.java 632503 2008-03-01 00:21:52Z ggregory $
*/
public class Main {
/**
* <p>Copies the given array and adds the given element at the end of the new array.</p>
*
* <p>The new array contains the same elements of the input
* array plus the given element in the last position. The component type of
* the new array is the same as that of the input array.</p>
*
* <p>If the input array is <code>null</code>, a new one element array is returned
* whose component type is the same as the element.</p>
*
* <pre>
* ArrayUtils.add(null, null) = [null]
* ArrayUtils.add(null, "a") = ["a"]
* ArrayUtils.add(["a"], null) = ["a", null]
* ArrayUtils.add(["a"], "b") = ["a", "b"]
* ArrayUtils.add(["a", "b"], "c") = ["a", "b", "c"]
* </pre>
*
* @param array the array to "add" the element to, may be <code>null</code>
* @param element the object to add
* @return A new array containing the existing elements plus the new element
* @since 2.1
*/
public static Object[] add(Object[] array, Object element) {
Class type = array != null ? array.getClass() : (element != null ? element.getClass() : Object.class);
Object[] newArray = (Object[]) copyArrayGrow1(array, type);
newArray[newArray.length - 1] = element;
return newArray;
}
/**
* Returns a copy of the given array of size 1 greater than the argument.
* The last value of the array is left to the default value.
*
* @param array The array to copy, must not be <code>null</code>.
* @param newArrayComponentType If <code>array</code> is <code>null</code>, create a
* size 1 array of this type.
* @return A new copy of the array of size 1 greater than the input.
*/
private static Object copyArrayGrow1(Object array, Class newArrayComponentType) {
if (array != null) {
int arrayLength = Array.getLength(array);
Object newArray = Array.newInstance(array.getClass().getComponentType(), arrayLength + 1);
System.arraycopy(array, 0, newArray, 0, arrayLength);
return newArray;
}
return Array.newInstance(newArrayComponentType, 1);
}
}
Copies the given array and adds the given element at the end of the new array.(short type array)
/* Copyright 2004 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import java.lang.reflect.Array;
/**
* <p>Operations on arrays, primitive arrays (like <code>int[]</code>) and
* primitive wrapper arrays (like <code>Integer[]</code>).</p>
*
* <p>This class tries to handle <code>null</code> input gracefully.
* An exception will not be thrown for a <code>null</code>
* array input. However, an Object array that contains a <code>null</code>
* element may throw an exception. Each method documents its behaviour.</p>
*
* @author Stephen Colebourne
* @author Moritz Petersen
* @author
* @author Maarten Coene
* @since 2.0
* @version $Id: ArrayUtils.java 632503 2008-03-01 00:21:52Z ggregory $
*/
public class Main {
/**
* <p>Copies the given array and adds the given element at the end of the new array.</p>
*
* <p>The new array contains the same elements of the input
* array plus the given element in the last position. The component type of
* the new array is the same as that of the input array.</p>
*
* <p>If the input array is <code>null</code>, a new one element array is returned
* whose component type is the same as the element.</p>
*
* <pre>
* ArrayUtils.add(null, 0) = [0]
* ArrayUtils.add([1], 0) = [1, 0]
* ArrayUtils.add([1, 0], 1) = [1, 0, 1]
* </pre>
*
* @param array the array to copy and add the element to, may be <code>null</code>
* @param element the object to add at the last index of the new array
* @return A new array containing the existing elements plus the new element
* @since 2.1
*/
public static short[] add(short[] array, short element) {
short[] newArray = (short[])copyArrayGrow1(array, Short.TYPE);
newArray[newArray.length - 1] = element;
return newArray;
}
/**
* Returns a copy of the given array of size 1 greater than the argument.
* The last value of the array is left to the default value.
*
* @param array The array to copy, must not be <code>null</code>.
* @param newArrayComponentType If <code>array</code> is <code>null</code>, create a
* size 1 array of this type.
* @return A new copy of the array of size 1 greater than the input.
*/
private static Object copyArrayGrow1(Object array, Class newArrayComponentType) {
if (array != null) {
int arrayLength = Array.getLength(array);
Object newArray = Array.newInstance(array.getClass().getComponentType(), arrayLength + 1);
System.arraycopy(array, 0, newArray, 0, arrayLength);
return newArray;
}
return Array.newInstance(newArrayComponentType, 1);
}
}
Inserts the specified element at the specified position in the array.
/* Copyright 2004 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import java.lang.reflect.Array;
/**
* <p>Operations on arrays, primitive arrays (like <code>int[]</code>) and
* primitive wrapper arrays (like <code>Integer[]</code>).</p>
*
* <p>This class tries to handle <code>null</code> input gracefully.
* An exception will not be thrown for a <code>null</code>
* array input. However, an Object array that contains a <code>null</code>
* element may throw an exception. Each method documents its behaviour.</p>
*
* @author Stephen Colebourne
* @author Moritz Petersen
* @author
* @author Maarten Coene
* @since 2.0
* @version $Id: ArrayUtils.java 632503 2008-03-01 00:21:52Z ggregory $
*/
public class Main {
/**
* <p>Inserts the specified element at the specified position in the array.
* Shifts the element currently at that position (if any) and any subsequent
* elements to the right (adds one to their indices).</p>
*
* <p>This method returns a new array with the same elements of the input
* array plus the given element on the specified position. The component
* type of the returned array is always the same as that of the input
* array.</p>
*
* <p>If the input array is <code>null</code>, a new one element array is returned
* whose component type is the same as the element.</p>
*
* <pre>
* ArrayUtils.add(null, 0, null) = [null]
* ArrayUtils.add(null, 0, "a") = ["a"]
* ArrayUtils.add(["a"], 1, null) = ["a", null]
* ArrayUtils.add(["a"], 1, "b") = ["a", "b"]
* ArrayUtils.add(["a", "b"], 3, "c") = ["a", "b", "c"]
* </pre>
*
* @param array the array to add the element to, may be <code>null</code>
* @param index the position of the new object
* @param element the object to add
* @return A new array containing the existing elements and the new element
* @throws IndexOutOfBoundsException if the index is out of range
* (index < 0 || index > array.length).
*/
public static Object[] add(Object[] array, int index, Object element) {
Class clss = null;
if (array != null) {
clss = array.getClass().getComponentType();
} else if (element != null) {
clss = element.getClass();
} else {
return new Object[]{null};
}
return (Object[]) add(array, index, element, clss);
}
/**
* Underlying implementation of add(array, index, element) methods.
* The last parameter is the class, which may not equal element.getClass
* for primitives.
*
* @param array the array to add the element to, may be <code>null</code>
* @param index the position of the new object
* @param element the object to add
* @param clss the type of the element being added
* @return A new array containing the existing elements and the new element
*/
private static Object add(Object array, int index, Object element, Class clss) {
if (array == null) {
if (index != 0) {
throw new IndexOutOfBoundsException("Index: " + index + ", Length: 0");
}
Object joinedArray = Array.newInstance(clss, 1);
Array.set(joinedArray, 0, element);
return joinedArray;
}
int length = Array.getLength(array);
if (index > length || index < 0) {
throw new IndexOutOfBoundsException("Index: " + index + ", Length: " + length);
}
Object result = Array.newInstance(clss, length + 1);
System.arraycopy(array, 0, result, 0, index);
Array.set(result, index, element);
if (index < length) {
System.arraycopy(array, index, result, index + 1, length - index);
}
return result;
}
}
Inserts the specified element at the specified position in the boolean-type-value array.
/* Copyright 2004 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import java.lang.reflect.Array;
/**
* <p>Operations on arrays, primitive arrays (like <code>int[]</code>) and
* primitive wrapper arrays (like <code>Integer[]</code>).</p>
*
* <p>This class tries to handle <code>null</code> input gracefully.
* An exception will not be thrown for a <code>null</code>
* array input. However, an Object array that contains a <code>null</code>
* element may throw an exception. Each method documents its behaviour.</p>
*
* @author Stephen Colebourne
* @author Moritz Petersen
* @author
* @author Maarten Coene
* @since 2.0
* @version $Id: ArrayUtils.java 632503 2008-03-01 00:21:52Z ggregory $
*/
public class Main {
/**
* <p>Inserts the specified element at the specified position in the array.
* Shifts the element currently at that position (if any) and any subsequent
* elements to the right (adds one to their indices).</p>
*
* <p>This method returns a new array with the same elements of the input
* array plus the given element on the specified position. The component
* type of the returned array is always the same as that of the input
* array.</p>
*
* <p>If the input array is <code>null</code>, a new one element array is returned
* whose component type is the same as the element.</p>
*
* <pre>
* ArrayUtils.add(null, 0, true) = [true]
* ArrayUtils.add([true], 0, false) = [false, true]
* ArrayUtils.add([false], 1, true) = [false, true]
* ArrayUtils.add([true, false], 1, true) = [true, true, false]
* </pre>
*
* @param array the array to add the element to, may be <code>null</code>
* @param index the position of the new object
* @param element the object to add
* @return A new array containing the existing elements and the new element
* @throws IndexOutOfBoundsException if the index is out of range
* (index < 0 || index > array.length).
*/
public static boolean[] add(boolean[] array, int index, boolean element) {
return (boolean[]) add(array, index, element, Boolean.TYPE);
}
/**
* Underlying implementation of add(array, index, element) methods.
* The last parameter is the class, which may not equal element.getClass
* for primitives.
*
* @param array the array to add the element to, may be <code>null</code>
* @param index the position of the new object
* @param element the object to add
* @param clss the type of the element being added
* @return A new array containing the existing elements and the new element
*/
private static Object add(Object array, int index, Object element, Class clss) {
if (array == null) {
if (index != 0) {
throw new IndexOutOfBoundsException("Index: " + index + ", Length: 0");
}
Object joinedArray = Array.newInstance(clss, 1);
Array.set(joinedArray, 0, element);
return joinedArray;
}
int length = Array.getLength(array);
if (index > length || index < 0) {
throw new IndexOutOfBoundsException("Index: " + index + ", Length: " + length);
}
Object result = Array.newInstance(clss, length + 1);
System.arraycopy(array, 0, result, 0, index);
Array.set(result, index, element);
if (index < length) {
System.arraycopy(array, index, result, index + 1, length - index);
}
return result;
}
}
Inserts the specified element at the specified position in the byte-type-value array.
/* Copyright 2004 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import java.lang.reflect.Array;
/**
* <p>Operations on arrays, primitive arrays (like <code>int[]</code>) and
* primitive wrapper arrays (like <code>Integer[]</code>).</p>
*
* <p>This class tries to handle <code>null</code> input gracefully.
* An exception will not be thrown for a <code>null</code>
* array input. However, an Object array that contains a <code>null</code>
* element may throw an exception. Each method documents its behaviour.</p>
*
* @author Stephen Colebourne
* @author Moritz Petersen
* @author
* @author Maarten Coene
* @since 2.0
* @version $Id: ArrayUtils.java 632503 2008-03-01 00:21:52Z ggregory $
*/
public class Main {
/**
* <p>Inserts the specified element at the specified position in the array.
* Shifts the element currently at that position (if any) and any subsequent
* elements to the right (adds one to their indices).</p>
*
* <p>This method returns a new array with the same elements of the input
* array plus the given element on the specified position. The component
* type of the returned array is always the same as that of the input
* array.</p>
*
* <p>If the input array is <code>null</code>, a new one element array is returned
* whose component type is the same as the element.</p>
*
* <pre>
* ArrayUtils.add([1], 0, 2) = [2, 1]
* ArrayUtils.add([2, 6], 2, 3) = [2, 6, 3]
* ArrayUtils.add([2, 6], 0, 1) = [1, 2, 6]
* ArrayUtils.add([2, 6, 3], 2, 1) = [2, 6, 1, 3]
* </pre>
*
* @param array the array to add the element to, may be <code>null</code>
* @param index the position of the new object
* @param element the object to add
* @return A new array containing the existing elements and the new element
* @throws IndexOutOfBoundsException if the index is out of range
* (index < 0 || index > array.length).
*/
public static byte[] add(byte[] array, int index, byte element) {
return (byte[]) add(array, index, new Byte(element), Byte.TYPE);
}
/**
* Underlying implementation of add(array, index, element) methods.
* The last parameter is the class, which may not equal element.getClass
* for primitives.
*
* @param array the array to add the element to, may be <code>null</code>
* @param index the position of the new object
* @param element the object to add
* @param clss the type of the element being added
* @return A new array containing the existing elements and the new element
*/
private static Object add(Object array, int index, Object element, Class clss) {
if (array == null) {
if (index != 0) {
throw new IndexOutOfBoundsException("Index: " + index + ", Length: 0");
}
Object joinedArray = Array.newInstance(clss, 1);
Array.set(joinedArray, 0, element);
return joinedArray;
}
int length = Array.getLength(array);
if (index > length || index < 0) {
throw new IndexOutOfBoundsException("Index: " + index + ", Length: " + length);
}
Object result = Array.newInstance(clss, length + 1);
System.arraycopy(array, 0, result, 0, index);
Array.set(result, index, element);
if (index < length) {
System.arraycopy(array, index, result, index + 1, length - index);
}
return result;
}
}
Inserts the specified element at the specified position in the char-type-value array.
/* Copyright 2004 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import java.lang.reflect.Array;
/**
* <p>Operations on arrays, primitive arrays (like <code>int[]</code>) and
* primitive wrapper arrays (like <code>Integer[]</code>).</p>
*
* <p>This class tries to handle <code>null</code> input gracefully.
* An exception will not be thrown for a <code>null</code>
* array input. However, an Object array that contains a <code>null</code>
* element may throw an exception. Each method documents its behaviour.</p>
*
* @author Stephen Colebourne
* @author Moritz Petersen
* @author
* @author Maarten Coene
* @since 2.0
* @version $Id: ArrayUtils.java 632503 2008-03-01 00:21:52Z ggregory $
*/
public class Main {
/**
* <p>Inserts the specified element at the specified position in the array.
* Shifts the element currently at that position (if any) and any subsequent
* elements to the right (adds one to their indices).</p>
*
* <p>This method returns a new array with the same elements of the input
* array plus the given element on the specified position. The component
* type of the returned array is always the same as that of the input
* array.</p>
*
* <p>If the input array is <code>null</code>, a new one element array is returned
* whose component type is the same as the element.</p>
*
* <pre>
* ArrayUtils.add(null, 0, "a") = ["a"]
* ArrayUtils.add(["a"], 0, "b") = ["b", "a"]
* ArrayUtils.add(["a", "b"], 0, "c") = ["c", "a", "b"]
* ArrayUtils.add(["a", "b"], 1, "k") = ["a", "k", "b"]
* ArrayUtils.add(["a", "b", "c"], 1, "t") = ["a", "t", "b", "c"]
* </pre>
*
* @param array the array to add the element to, may be <code>null</code>
* @param index the position of the new object
* @param element the object to add
* @return A new array containing the existing elements and the new element
* @throws IndexOutOfBoundsException if the index is out of range
* (index < 0 || index > array.length).
*/
public static char[] add(char[] array, int index, char element) {
return (char[]) add(array, index, new Character(element), Character.TYPE);
}
/**
* Underlying implementation of add(array, index, element) methods.
* The last parameter is the class, which may not equal element.getClass
* for primitives.
*
* @param array the array to add the element to, may be <code>null</code>
* @param index the position of the new object
* @param element the object to add
* @param clss the type of the element being added
* @return A new array containing the existing elements and the new element
*/
private static Object add(Object array, int index, Object element, Class clss) {
if (array == null) {
if (index != 0) {
throw new IndexOutOfBoundsException("Index: " + index + ", Length: 0");
}
Object joinedArray = Array.newInstance(clss, 1);
Array.set(joinedArray, 0, element);
return joinedArray;
}
int length = Array.getLength(array);
if (index > length || index < 0) {
throw new IndexOutOfBoundsException("Index: " + index + ", Length: " + length);
}
Object result = Array.newInstance(clss, length + 1);
System.arraycopy(array, 0, result, 0, index);
Array.set(result, index, element);
if (index < length) {
System.arraycopy(array, index, result, index + 1, length - index);
}
return result;
}
}
Inserts the specified element at the specified position in the double-type-value array.
/* Copyright 2004 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import java.lang.reflect.Array;
/**
* <p>Operations on arrays, primitive arrays (like <code>int[]</code>) and
* primitive wrapper arrays (like <code>Integer[]</code>).</p>
*
* <p>This class tries to handle <code>null</code> input gracefully.
* An exception will not be thrown for a <code>null</code>
* array input. However, an Object array that contains a <code>null</code>
* element may throw an exception. Each method documents its behaviour.</p>
*
* @author Stephen Colebourne
* @author Moritz Petersen
* @author
* @author Maarten Coene
* @since 2.0
* @version $Id: ArrayUtils.java 632503 2008-03-01 00:21:52Z ggregory $
*/
public class Main {
/**
* <p>Inserts the specified element at the specified position in the array.
* Shifts the element currently at that position (if any) and any subsequent
* elements to the right (adds one to their indices).</p>
*
* <p>This method returns a new array with the same elements of the input
* array plus the given element on the specified position. The component
* type of the returned array is always the same as that of the input
* array.</p>
*
* <p>If the input array is <code>null</code>, a new one element array is returned
* whose component type is the same as the element.</p>
*
* <pre>
* ArrayUtils.add([1.1], 0, 2.2) = [2.2, 1.1]
* ArrayUtils.add([2.3, 6.4], 2, 10.5) = [2.3, 6.4, 10.5]
* ArrayUtils.add([2.6, 6.7], 0, -4.8) = [-4.8, 2.6, 6.7]
* ArrayUtils.add([2.9, 6.0, 0.3], 2, 1.0) = [2.9, 6.0, 1.0, 0.3]
* </pre>
*
* @param array the array to add the element to, may be <code>null</code>
* @param index the position of the new object
* @param element the object to add
* @return A new array containing the existing elements and the new element
* @throws IndexOutOfBoundsException if the index is out of range
* (index < 0 || index > array.length).
*/
public static double[] add(double[] array, int index, double element) {
return (double[]) add(array, index, new Double(element), Double.TYPE);
}
/**
* Underlying implementation of add(array, index, element) methods.
* The last parameter is the class, which may not equal element.getClass
* for primitives.
*
* @param array the array to add the element to, may be <code>null</code>
* @param index the position of the new object
* @param element the object to add
* @param clss the type of the element being added
* @return A new array containing the existing elements and the new element
*/
private static Object add(Object array, int index, Object element, Class clss) {
if (array == null) {
if (index != 0) {
throw new IndexOutOfBoundsException("Index: " + index + ", Length: 0");
}
Object joinedArray = Array.newInstance(clss, 1);
Array.set(joinedArray, 0, element);
return joinedArray;
}
int length = Array.getLength(array);
if (index > length || index < 0) {
throw new IndexOutOfBoundsException("Index: " + index + ", Length: " + length);
}
Object result = Array.newInstance(clss, length + 1);
System.arraycopy(array, 0, result, 0, index);
Array.set(result, index, element);
if (index < length) {
System.arraycopy(array, index, result, index + 1, length - index);
}
return result;
}
}
Inserts the specified element at the specified position in the float-value-type array.
/* Copyright 2004 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import java.lang.reflect.Array;
/**
* <p>Operations on arrays, primitive arrays (like <code>int[]</code>) and
* primitive wrapper arrays (like <code>Integer[]</code>).</p>
*
* <p>This class tries to handle <code>null</code> input gracefully.
* An exception will not be thrown for a <code>null</code>
* array input. However, an Object array that contains a <code>null</code>
* element may throw an exception. Each method documents its behaviour.</p>
*
* @author Stephen Colebourne
* @author Moritz Petersen
* @author
* @author Maarten Coene
* @since 2.0
* @version $Id: ArrayUtils.java 632503 2008-03-01 00:21:52Z ggregory $
*/
public class Main {
/**
* <p>Inserts the specified element at the specified position in the array.
* Shifts the element currently at that position (if any) and any subsequent
* elements to the right (adds one to their indices).</p>
*
* <p>This method returns a new array with the same elements of the input
* array plus the given element on the specified position. The component
* type of the returned array is always the same as that of the input
* array.</p>
*
* <p>If the input array is <code>null</code>, a new one element array is returned
* whose component type is the same as the element.</p>
*
* <pre>
* ArrayUtils.add([1.1f], 0, 2.2f) = [2.2f, 1.1f]
* ArrayUtils.add([2.3f, 6.4f], 2, 10.5f) = [2.3f, 6.4f, 10.5f]
* ArrayUtils.add([2.6f, 6.7f], 0, -4.8f) = [-4.8f, 2.6f, 6.7f]
* ArrayUtils.add([2.9f, 6.0f, 0.3f], 2, 1.0f) = [2.9f, 6.0f, 1.0f, 0.3f]
* </pre>
*
* @param array the array to add the element to, may be <code>null</code>
* @param index the position of the new object
* @param element the object to add
* @return A new array containing the existing elements and the new element
* @throws IndexOutOfBoundsException if the index is out of range
* (index < 0 || index > array.length).
*/
public static float[] add(float[] array, int index, float element) {
return (float[]) add(array, index, new Float(element), Float.TYPE);
}
/**
* Underlying implementation of add(array, index, element) methods.
* The last parameter is the class, which may not equal element.getClass
* for primitives.
*
* @param array the array to add the element to, may be <code>null</code>
* @param index the position of the new object
* @param element the object to add
* @param clss the type of the element being added
* @return A new array containing the existing elements and the new element
*/
private static Object add(Object array, int index, Object element, Class clss) {
if (array == null) {
if (index != 0) {
throw new IndexOutOfBoundsException("Index: " + index + ", Length: 0");
}
Object joinedArray = Array.newInstance(clss, 1);
Array.set(joinedArray, 0, element);
return joinedArray;
}
int length = Array.getLength(array);
if (index > length || index < 0) {
throw new IndexOutOfBoundsException("Index: " + index + ", Length: " + length);
}
Object result = Array.newInstance(clss, length + 1);
System.arraycopy(array, 0, result, 0, index);
Array.set(result, index, element);
if (index < length) {
System.arraycopy(array, index, result, index + 1, length - index);
}
return result;
}
}
Inserts the specified element at the specified position in the int-type-value array.
/* Copyright 2004 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import java.lang.reflect.Array;
/**
* <p>Operations on arrays, primitive arrays (like <code>int[]</code>) and
* primitive wrapper arrays (like <code>Integer[]</code>).</p>
*
* <p>This class tries to handle <code>null</code> input gracefully.
* An exception will not be thrown for a <code>null</code>
* array input. However, an Object array that contains a <code>null</code>
* element may throw an exception. Each method documents its behaviour.</p>
*
* @author Stephen Colebourne
* @author Moritz Petersen
* @author
* @author Maarten Coene
* @since 2.0
* @version $Id: ArrayUtils.java 632503 2008-03-01 00:21:52Z ggregory $
*/
public class Main {
/**
* <p>Inserts the specified element at the specified position in the array.
* Shifts the element currently at that position (if any) and any subsequent
* elements to the right (adds one to their indices).</p>
*
* <p>This method returns a new array with the same elements of the input
* array plus the given element on the specified position. The component
* type of the returned array is always the same as that of the input
* array.</p>
*
* <p>If the input array is <code>null</code>, a new one element array is returned
* whose component type is the same as the element.</p>
*
* <pre>
* ArrayUtils.add([1], 0, 2) = [2, 1]
* ArrayUtils.add([2, 6], 2, 10) = [2, 6, 10]
* ArrayUtils.add([2, 6], 0, -4) = [-4, 2, 6]
* ArrayUtils.add([2, 6, 3], 2, 1) = [2, 6, 1, 3]
* </pre>
*
* @param array the array to add the element to, may be <code>null</code>
* @param index the position of the new object
* @param element the object to add
* @return A new array containing the existing elements and the new element
* @throws IndexOutOfBoundsException if the index is out of range
* (index < 0 || index > array.length).
*/
public static int[] add(int[] array, int index, int element) {
return (int[]) add(array, index, new Integer(element), Integer.TYPE);
}
/**
* Underlying implementation of add(array, index, element) methods.
* The last parameter is the class, which may not equal element.getClass
* for primitives.
*
* @param array the array to add the element to, may be <code>null</code>
* @param index the position of the new object
* @param element the object to add
* @param clss the type of the element being added
* @return A new array containing the existing elements and the new element
*/
private static Object add(Object array, int index, Object element, Class clss) {
if (array == null) {
if (index != 0) {
throw new IndexOutOfBoundsException("Index: " + index + ", Length: 0");
}
Object joinedArray = Array.newInstance(clss, 1);
Array.set(joinedArray, 0, element);
return joinedArray;
}
int length = Array.getLength(array);
if (index > length || index < 0) {
throw new IndexOutOfBoundsException("Index: " + index + ", Length: " + length);
}
Object result = Array.newInstance(clss, length + 1);
System.arraycopy(array, 0, result, 0, index);
Array.set(result, index, element);
if (index < length) {
System.arraycopy(array, index, result, index + 1, length - index);
}
return result;
}
}
Inserts the specified element at the specified position in the long-type-value array.
/* Copyright 2004 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import java.lang.reflect.Array;
/**
* <p>Operations on arrays, primitive arrays (like <code>int[]</code>) and
* primitive wrapper arrays (like <code>Integer[]</code>).</p>
*
* <p>This class tries to handle <code>null</code> input gracefully.
* An exception will not be thrown for a <code>null</code>
* array input. However, an Object array that contains a <code>null</code>
* element may throw an exception. Each method documents its behaviour.</p>
*
* @author Stephen Colebourne
* @author Moritz Petersen
* @author
* @author Maarten Coene
* @since 2.0
* @version $Id: ArrayUtils.java 632503 2008-03-01 00:21:52Z ggregory $
*/
public class Main {
/**
* <p>Inserts the specified element at the specified position in the array.
* Shifts the element currently at that position (if any) and any subsequent
* elements to the right (adds one to their indices).</p>
*
* <p>This method returns a new array with the same elements of the input
* array plus the given element on the specified position. The component
* type of the returned array is always the same as that of the input
* array.</p>
*
* <p>If the input array is <code>null</code>, a new one element array is returned
* whose component type is the same as the element.</p>
*
* <pre>
* ArrayUtils.add([1L], 0, 2L) = [2L, 1L]
* ArrayUtils.add([2L, 6L], 2, 10L) = [2L, 6L, 10L]
* ArrayUtils.add([2L, 6L], 0, -4L) = [-4L, 2L, 6L]
* ArrayUtils.add([2L, 6L, 3L], 2, 1L) = [2L, 6L, 1L, 3L]
* </pre>
*
* @param array the array to add the element to, may be <code>null</code>
* @param index the position of the new object
* @param element the object to add
* @return A new array containing the existing elements and the new element
* @throws IndexOutOfBoundsException if the index is out of range
* (index < 0 || index > array.length).
*/
public static long[] add(long[] array, int index, long element) {
return (long[]) add(array, index, new Long(element), Long.TYPE);
}
/**
* Underlying implementation of add(array, index, element) methods.
* The last parameter is the class, which may not equal element.getClass
* for primitives.
*
* @param array the array to add the element to, may be <code>null</code>
* @param index the position of the new object
* @param element the object to add
* @param clss the type of the element being added
* @return A new array containing the existing elements and the new element
*/
private static Object add(Object array, int index, Object element, Class clss) {
if (array == null) {
if (index != 0) {
throw new IndexOutOfBoundsException("Index: " + index + ", Length: 0");
}
Object joinedArray = Array.newInstance(clss, 1);
Array.set(joinedArray, 0, element);
return joinedArray;
}
int length = Array.getLength(array);
if (index > length || index < 0) {
throw new IndexOutOfBoundsException("Index: " + index + ", Length: " + length);
}
Object result = Array.newInstance(clss, length + 1);
System.arraycopy(array, 0, result, 0, index);
Array.set(result, index, element);
if (index < length) {
System.arraycopy(array, index, result, index + 1, length - index);
}
return result;
}
}
Inserts the specified element at the specified position in the short-value-type array.
/* Copyright 2004 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import java.lang.reflect.Array;
/**
* <p>Operations on arrays, primitive arrays (like <code>int[]</code>) and
* primitive wrapper arrays (like <code>Integer[]</code>).</p>
*
* <p>This class tries to handle <code>null</code> input gracefully.
* An exception will not be thrown for a <code>null</code>
* array input. However, an Object array that contains a <code>null</code>
* element may throw an exception. Each method documents its behaviour.</p>
*
* @author Stephen Colebourne
* @author Moritz Petersen
* @author
* @author Maarten Coene
* @since 2.0
* @version $Id: ArrayUtils.java 632503 2008-03-01 00:21:52Z ggregory $
*/
public class Main {
/**
* <p>Inserts the specified element at the specified position in the array.
* Shifts the element currently at that position (if any) and any subsequent
* elements to the right (adds one to their indices).</p>
*
* <p>This method returns a new array with the same elements of the input
* array plus the given element on the specified position. The component
* type of the returned array is always the same as that of the input
* array.</p>
*
* <p>If the input array is <code>null</code>, a new one element array is returned
* whose component type is the same as the element.</p>
*
* <pre>
* ArrayUtils.add([1], 0, 2) = [2, 1]
* ArrayUtils.add([2, 6], 2, 10) = [2, 6, 10]
* ArrayUtils.add([2, 6], 0, -4) = [-4, 2, 6]
* ArrayUtils.add([2, 6, 3], 2, 1) = [2, 6, 1, 3]
* </pre>
*
* @param array the array to add the element to, may be <code>null</code>
* @param index the position of the new object
* @param element the object to add
* @return A new array containing the existing elements and the new element
* @throws IndexOutOfBoundsException if the index is out of range
* (index < 0 || index > array.length).
*/
public static short[] add(short[] array, int index, short element) {
return (short[]) add(array, index, new Short(element), Short.TYPE);
}
/**
* Underlying implementation of add(array, index, element) methods.
* The last parameter is the class, which may not equal element.getClass
* for primitives.
*
* @param array the array to add the element to, may be <code>null</code>
* @param index the position of the new object
* @param element the object to add
* @param clss the type of the element being added
* @return A new array containing the existing elements and the new element
*/
private static Object add(Object array, int index, Object element, Class clss) {
if (array == null) {
if (index != 0) {
throw new IndexOutOfBoundsException("Index: " + index + ", Length: 0");
}
Object joinedArray = Array.newInstance(clss, 1);
Array.set(joinedArray, 0, element);
return joinedArray;
}
int length = Array.getLength(array);
if (index > length || index < 0) {
throw new IndexOutOfBoundsException("Index: " + index + ", Length: " + length);
}
Object result = Array.newInstance(clss, length + 1);
System.arraycopy(array, 0, result, 0, index);
Array.set(result, index, element);
if (index < length) {
System.arraycopy(array, index, result, index + 1, length - index);
}
return result;
}
}
Insert value to array
/*
* dbXML - Native XML Database
* Copyright (C) 1999-2004 The dbXML Group, L.L.C.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* $Id: Array.java,v 1.2 2004/02/12 00:17:58 bradford Exp $
*/
/**
* Array utility methods
*/
public final class Array {
private Array() {
}
public static Object[] insertArrayObject(Object[] vals, Object val, int idx) {
Object[] newVals = new Object[vals.length + 1];
if ( idx > 0 )
System.arraycopy(vals, 0, newVals, 0, idx);
newVals[idx] = val;
if ( idx < vals.length )
System.arraycopy(vals, idx, newVals, idx + 1, vals.length - idx);
return newVals;
}
public static Object[] deleteArrayObject(Object[] vals, int idx) {
Object[] newVals = new Object[vals.length - 1];
if ( idx > 0 )
System.arraycopy(vals, 0, newVals, 0, idx);
if ( idx < newVals.length )
System.arraycopy(vals, idx + 1, newVals, idx, newVals.length - idx);
return newVals;
}
public static long[] insertArrayLong(long[] vals, long val, int idx) {
long[] newVals = new long[vals.length + 1];
if ( idx > 0 )
System.arraycopy(vals, 0, newVals, 0, idx);
newVals[idx] = val;
if ( idx < vals.length )
System.arraycopy(vals, idx, newVals, idx + 1, vals.length - idx);
return newVals;
}
public static long[] deleteArrayLong(long[] vals, int idx) {
long[] newVals = new long[vals.length - 1];
if ( idx > 0 )
System.arraycopy(vals, 0, newVals, 0, idx);
if ( idx < newVals.length )
System.arraycopy(vals, idx + 1, newVals, idx, newVals.length - idx);
return newVals;
}
public static int[] insertArrayInt(int[] vals, int val, int idx) {
int[] newVals = new int[vals.length + 1];
if ( idx > 0 )
System.arraycopy(vals, 0, newVals, 0, idx);
newVals[idx] = val;
if ( idx < vals.length )
System.arraycopy(vals, idx, newVals, idx + 1, vals.length - idx);
return newVals;
}
public static int[] deleteArrayInt(int[] vals, int idx) {
int[] newVals = new int[vals.length - 1];
if ( idx > 0 )
System.arraycopy(vals, 0, newVals, 0, idx);
if ( idx < newVals.length )
System.arraycopy(vals, idx + 1, newVals, idx, newVals.length - idx);
return newVals;
}
public static short[] insertArrayShort(short[] vals, short val, int idx) {
short[] newVals = new short[vals.length + 1];
if ( idx > 0 )
System.arraycopy(vals, 0, newVals, 0, idx);
newVals[idx] = val;
if ( idx < vals.length )
System.arraycopy(vals, idx, newVals, idx + 1, vals.length - idx);
return newVals;
}
public static short[] deleteArrayShort(short[] vals, int idx) {
short[] newVals = new short[vals.length - 1];
if ( idx > 0 )
System.arraycopy(vals, 0, newVals, 0, idx);
if ( idx < newVals.length )
System.arraycopy(vals, idx + 1, newVals, idx, newVals.length - idx);
return newVals;
}
}
Removes the element at the specified position from the specified array.
/* Copyright 2004 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import java.lang.reflect.Array;
/**
* <p>Operations on arrays, primitive arrays (like <code>int[]</code>) and
* primitive wrapper arrays (like <code>Integer[]</code>).</p>
*
* <p>This class tries to handle <code>null</code> input gracefully.
* An exception will not be thrown for a <code>null</code>
* array input. However, an Object array that contains a <code>null</code>
* element may throw an exception. Each method documents its behaviour.</p>
*
* @author Stephen Colebourne
* @author Moritz Petersen
* @author
* @author Maarten Coene
* @since 2.0
* @version $Id: ArrayUtils.java 632503 2008-03-01 00:21:52Z ggregory $
*/
public class Main {
/**
* <p>Removes the element at the specified position from the specified array.
* All subsequent elements are shifted to the left (substracts one from
* their indices).</p>
*
* <p>This method returns a new array with the same elements of the input
* array except the element on the specified position. The component
* type of the returned array is always the same as that of the input
* array.</p>
*
* <p>If the input array is <code>null</code>, an IndexOutOfBoundsException
* will be thrown, because in that case no valid index can be specified.</p>
*
* <pre>
* ArrayUtils.remove([1], 0) = []
* ArrayUtils.remove([2, 6], 0) = [6]
* ArrayUtils.remove([2, 6], 1) = [2]
* ArrayUtils.remove([2, 6, 3], 1) = [2, 3]
* </pre>
*
* @param array the array to remove the element from, may not be <code>null</code>
* @param index the position of the element to be removed
* @return A new array containing the existing elements except the element
* at the specified position.
* @throws IndexOutOfBoundsException if the index is out of range
* (index < 0 || index >= array.length), or if the array is <code>null</code>.
* @since 2.1
*/
public static short[] remove(short[] array, int index) {
return (short[]) remove((Object) array, index);
}
/**
* <p>Removes the element at the specified position from the specified array.
* All subsequent elements are shifted to the left (substracts one from
* their indices).</p>
*
* <p>This method returns a new array with the same elements of the input
* array except the element on the specified position. The component
* type of the returned array is always the same as that of the input
* array.</p>
*
* <p>If the input array is <code>null</code>, an IndexOutOfBoundsException
* will be thrown, because in that case no valid index can be specified.</p>
*
* @param array the array to remove the element from, may not be <code>null</code>
* @param index the position of the element to be removed
* @return A new array containing the existing elements except the element
* at the specified position.
* @throws IndexOutOfBoundsException if the index is out of range
* (index < 0 || index >= array.length), or if the array is <code>null</code>.
* @since 2.1
*/
private static Object remove(Object array, int index) {
int length = getLength(array);
if (index < 0 || index >= length) {
throw new IndexOutOfBoundsException("Index: " + index + ", Length: " + length);
}
Object result = Array.newInstance(array.getClass().getComponentType(), length - 1);
System.arraycopy(array, 0, result, 0, index);
if (index < length - 1) {
System.arraycopy(array, index + 1, result, index, length - index - 1);
}
return result;
}
/**
* <p>Finds the index of the given value in the array starting at the given index.</p>
*
* <p>This method returns {@link #INDEX_NOT_FOUND} (<code>-1</code>) for a <code>null</code> input array.</p>
*
* <p>A negative startIndex is treated as zero. A startIndex larger than the array
* length will return {@link #INDEX_NOT_FOUND} (<code>-1</code>).</p>
*
* @param array the array to search through for the object, may be <code>null</code>
* @param valueToFind the value to find
* @param startIndex the index to start searching at
* @return the index of the value within the array,
* {@link #INDEX_NOT_FOUND} (<code>-1</code>) if not found or <code>null</code> array input
*/
public static int indexOf(short[] array, short valueToFind) {
if (array == null) {
return -1;
}
for (int i = 0; i < array.length; i++) {
if (valueToFind == array[i]) {
return i;
}
}
return -1;
}
/**
* <p>Returns the length of the specified array.
* This method can deal with <code>Object</code> arrays and with primitive arrays.</p>
*
* <p>If the input array is <code>null</code>, <code>0</code> is returned.</p>
*
* <pre>
* ArrayUtils.getLength(null) = 0
* ArrayUtils.getLength([]) = 0
* ArrayUtils.getLength([null]) = 1
* ArrayUtils.getLength([true, false]) = 2
* ArrayUtils.getLength([1, 2, 3]) = 3
* ArrayUtils.getLength(["a", "b", "c"]) = 3
* </pre>
*
* @param array the array to retrieve the length from, may be null
* @return The length of the array, or <code>0</code> if the array is <code>null</code>
* @throws IllegalArgumentException if the object arguement is not an array.
* @since 2.1
*/
public static int getLength(Object array) {
if (array == null) {
return 0;
}
return Array.getLength(array);
}
/**
* <p>Shallow clones an array returning a typecast result and handling
* <code>null</code>.</p>
*
* <p>The objects in the array are not cloned, thus there is no special
* handling for multi-dimensional arrays.</p>
*
* <p>This method returns <code>null</code> for a <code>null</code> input array.</p>
*
* @param array the array to shallow clone, may be <code>null</code>
* @return the cloned array, <code>null</code> if <code>null</code> input
*/
public static short[] clone(short[] array) {
if (array == null) {
return null;
}
return (short[]) array.clone();
}
}
Removes the element at the specified position from the specified long type array.
/* Copyright 2004 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import java.lang.reflect.Array;
/**
* <p>Operations on arrays, primitive arrays (like <code>int[]</code>) and
* primitive wrapper arrays (like <code>Integer[]</code>).</p>
*
* <p>This class tries to handle <code>null</code> input gracefully.
* An exception will not be thrown for a <code>null</code>
* array input. However, an Object array that contains a <code>null</code>
* element may throw an exception. Each method documents its behaviour.</p>
*
* @author Stephen Colebourne
* @author Moritz Petersen
* @author
* @author Maarten Coene
* @since 2.0
* @version $Id: ArrayUtils.java 632503 2008-03-01 00:21:52Z ggregory $
*/
public class Main {
/**
* <p>Removes the element at the specified position from the specified array.
* All subsequent elements are shifted to the left (substracts one from
* their indices).</p>
*
* <p>This method returns a new array with the same elements of the input
* array except the element on the specified position. The component
* type of the returned array is always the same as that of the input
* array.</p>
*
* <p>If the input array is <code>null</code>, an IndexOutOfBoundsException
* will be thrown, because in that case no valid index can be specified.</p>
*
* <pre>
* ArrayUtils.remove([1], 0) = []
* ArrayUtils.remove([2, 6], 0) = [6]
* ArrayUtils.remove([2, 6], 1) = [2]
* ArrayUtils.remove([2, 6, 3], 1) = [2, 3]
* </pre>
*
* @param array the array to remove the element from, may not be <code>null</code>
* @param index the position of the element to be removed
* @return A new array containing the existing elements except the element
* at the specified position.
* @throws IndexOutOfBoundsException if the index is out of range
* (index < 0 || index >= array.length), or if the array is <code>null</code>.
* @since 2.1
*/
public static long[] remove(long[] array, int index) {
return (long[]) remove((Object) array, index);
}
/**
* <p>Removes the first occurrence of the specified element from the
* specified array. All subsequent elements are shifted to the left
* (substracts one from their indices). If the array doesn"t contains
* such an element, no elements are removed from the array.</p>
*
* <p>This method returns a new array with the same elements of the input
* array except the first occurrence of the specified element. The component
* type of the returned array is always the same as that of the input
* array.</p>
*
* <pre>
* ArrayUtils.removeElement(null, 1) = null
* ArrayUtils.removeElement([], 1) = []
* ArrayUtils.removeElement([1], 2) = [1]
* ArrayUtils.removeElement([1, 3], 1) = [3]
* ArrayUtils.removeElement([1, 3, 1], 1) = [3, 1]
* </pre>
*
* @param array the array to remove the element from, may be <code>null</code>
* @param element the element to be removed
* @return A new array containing the existing elements except the first
* occurrence of the specified element.
* @since 2.1
*/
public static long[] removeElement(long[] array, long element) {
int index = indexOf(array, element);
if (index == -1) {
return clone(array);
}
return remove(array, index);
}
/**
* <p>Removes the element at the specified position from the specified array.
* All subsequent elements are shifted to the left (substracts one from
* their indices).</p>
*
* <p>This method returns a new array with the same elements of the input
* array except the element on the specified position. The component
* type of the returned array is always the same as that of the input
* array.</p>
*
* <p>If the input array is <code>null</code>, an IndexOutOfBoundsException
* will be thrown, because in that case no valid index can be specified.</p>
*
* @param array the array to remove the element from, may not be <code>null</code>
* @param index the position of the element to be removed
* @return A new array containing the existing elements except the element
* at the specified position.
* @throws IndexOutOfBoundsException if the index is out of range
* (index < 0 || index >= array.length), or if the array is <code>null</code>.
* @since 2.1
*/
private static Object remove(Object array, int index) {
int length = getLength(array);
if (index < 0 || index >= length) {
throw new IndexOutOfBoundsException("Index: " + index + ", Length: " + length);
}
Object result = Array.newInstance(array.getClass().getComponentType(), length - 1);
System.arraycopy(array, 0, result, 0, index);
if (index < length - 1) {
System.arraycopy(array, index + 1, result, index, length - index - 1);
}
return result;
}
/**
* <p>Finds the index of the given value in the array starting at the given index.</p>
*
* <p>This method returns {@link #INDEX_NOT_FOUND} (<code>-1</code>) for a <code>null</code> input array.</p>
*
* <p>A negative startIndex is treated as zero. A startIndex larger than the array
* length will return {@link #INDEX_NOT_FOUND} (<code>-1</code>).</p>
*
* @param array the array to search through for the object, may be <code>null</code>
* @param valueToFind the value to find
* @param startIndex the index to start searching at
* @return the index of the value within the array,
* {@link #INDEX_NOT_FOUND} (<code>-1</code>) if not found or <code>null</code> array input
*/
public static int indexOf(long[] array, long valueToFind) {
if (array == null) {
return -1;
}
for (int i = 0; i < array.length; i++) {
if (valueToFind == array[i]) {
return i;
}
}
return -1;
}
/**
* <p>Returns the length of the specified array.
* This method can deal with <code>Object</code> arrays and with primitive arrays.</p>
*
* <p>If the input array is <code>null</code>, <code>0</code> is returned.</p>
*
* <pre>
* ArrayUtils.getLength(null) = 0
* ArrayUtils.getLength([]) = 0
* ArrayUtils.getLength([null]) = 1
* ArrayUtils.getLength([true, false]) = 2
* ArrayUtils.getLength([1, 2, 3]) = 3
* ArrayUtils.getLength(["a", "b", "c"]) = 3
* </pre>
*
* @param array the array to retrieve the length from, may be null
* @return The length of the array, or <code>0</code> if the array is <code>null</code>
* @throws IllegalArgumentException if the object arguement is not an array.
* @since 2.1
*/
public static int getLength(Object array) {
if (array == null) {
return 0;
}
return Array.getLength(array);
}
/**
* <p>Shallow clones an array returning a typecast result and handling
* <code>null</code>.</p>
*
* <p>The objects in the array are not cloned, thus there is no special
* handling for multi-dimensional arrays.</p>
*
* <p>This method returns <code>null</code> for a <code>null</code> input array.</p>
*
* @param array the array to shallow clone, may be <code>null</code>
* @return the cloned array, <code>null</code> if <code>null</code> input
*/
public static long[] clone(long[] array) {
if (array == null) {
return null;
}
return (long[]) array.clone();
}
}
Removes the first occurrence of the specified element from the specified array.
/* Copyright 2004 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import java.lang.reflect.Array;
/**
* <p>Operations on arrays, primitive arrays (like <code>int[]</code>) and
* primitive wrapper arrays (like <code>Integer[]</code>).</p>
*
* <p>This class tries to handle <code>null</code> input gracefully.
* An exception will not be thrown for a <code>null</code>
* array input. However, an Object array that contains a <code>null</code>
* element may throw an exception. Each method documents its behaviour.</p>
*
* @author Stephen Colebourne
* @author Moritz Petersen
* @author
* @author Maarten Coene
* @since 2.0
* @version $Id: ArrayUtils.java 632503 2008-03-01 00:21:52Z ggregory $
*/
public class Main {
/**
* <p>Removes the first occurrence of the specified element from the
* specified array. All subsequent elements are shifted to the left
* (substracts one from their indices). If the array doesn"t contains
* such an element, no elements are removed from the array.</p>
*
* <p>This method returns a new array with the same elements of the input
* array except the first occurrence of the specified element. The component
* type of the returned array is always the same as that of the input
* array.</p>
*
* <pre>
* ArrayUtils.removeElement(null, 1) = null
* ArrayUtils.removeElement([], 1) = []
* ArrayUtils.removeElement([1], 2) = [1]
* ArrayUtils.removeElement([1, 3], 1) = [3]
* ArrayUtils.removeElement([1, 3, 1], 1) = [3, 1]
* </pre>
*
* @param array the array to remove the element from, may be <code>null</code>
* @param element the element to be removed
* @return A new array containing the existing elements except the first
* occurrence of the specified element.
* @since 2.1
*/
public static short[] removeElement(short[] array, short element) {
int index = indexOf(array, element);
if (index == -1) {
return clone(array);
}
return remove(array, index);
}
/**
* <p>Removes the element at the specified position from the specified array.
* All subsequent elements are shifted to the left (substracts one from
* their indices).</p>
*
* <p>This method returns a new array with the same elements of the input
* array except the element on the specified position. The component
* type of the returned array is always the same as that of the input
* array.</p>
*
* <p>If the input array is <code>null</code>, an IndexOutOfBoundsException
* will be thrown, because in that case no valid index can be specified.</p>
*
* <pre>
* ArrayUtils.remove([1], 0) = []
* ArrayUtils.remove([2, 6], 0) = [6]
* ArrayUtils.remove([2, 6], 1) = [2]
* ArrayUtils.remove([2, 6, 3], 1) = [2, 3]
* </pre>
*
* @param array the array to remove the element from, may not be <code>null</code>
* @param index the position of the element to be removed
* @return A new array containing the existing elements except the element
* at the specified position.
* @throws IndexOutOfBoundsException if the index is out of range
* (index < 0 || index >= array.length), or if the array is <code>null</code>.
* @since 2.1
*/
public static short[] remove(short[] array, int index) {
return (short[]) remove((Object) array, index);
}
/**
* <p>Removes the element at the specified position from the specified array.
* All subsequent elements are shifted to the left (substracts one from
* their indices).</p>
*
* <p>This method returns a new array with the same elements of the input
* array except the element on the specified position. The component
* type of the returned array is always the same as that of the input
* array.</p>
*
* <p>If the input array is <code>null</code>, an IndexOutOfBoundsException
* will be thrown, because in that case no valid index can be specified.</p>
*
* @param array the array to remove the element from, may not be <code>null</code>
* @param index the position of the element to be removed
* @return A new array containing the existing elements except the element
* at the specified position.
* @throws IndexOutOfBoundsException if the index is out of range
* (index < 0 || index >= array.length), or if the array is <code>null</code>.
* @since 2.1
*/
private static Object remove(Object array, int index) {
int length = getLength(array);
if (index < 0 || index >= length) {
throw new IndexOutOfBoundsException("Index: " + index + ", Length: " + length);
}
Object result = Array.newInstance(array.getClass().getComponentType(), length - 1);
System.arraycopy(array, 0, result, 0, index);
if (index < length - 1) {
System.arraycopy(array, index + 1, result, index, length - index - 1);
}
return result;
}
/**
* <p>Finds the index of the given value in the array starting at the given index.</p>
*
* <p>This method returns {@link #INDEX_NOT_FOUND} (<code>-1</code>) for a <code>null</code> input array.</p>
*
* <p>A negative startIndex is treated as zero. A startIndex larger than the array
* length will return {@link #INDEX_NOT_FOUND} (<code>-1</code>).</p>
*
* @param array the array to search through for the object, may be <code>null</code>
* @param valueToFind the value to find
* @param startIndex the index to start searching at
* @return the index of the value within the array,
* {@link #INDEX_NOT_FOUND} (<code>-1</code>) if not found or <code>null</code> array input
*/
public static int indexOf(short[] array, short valueToFind) {
if (array == null) {
return -1;
}
for (int i = 0; i < array.length; i++) {
if (valueToFind == array[i]) {
return i;
}
}
return -1;
}
/**
* <p>Returns the length of the specified array.
* This method can deal with <code>Object</code> arrays and with primitive arrays.</p>
*
* <p>If the input array is <code>null</code>, <code>0</code> is returned.</p>
*
* <pre>
* ArrayUtils.getLength(null) = 0
* ArrayUtils.getLength([]) = 0
* ArrayUtils.getLength([null]) = 1
* ArrayUtils.getLength([true, false]) = 2
* ArrayUtils.getLength([1, 2, 3]) = 3
* ArrayUtils.getLength(["a", "b", "c"]) = 3
* </pre>
*
* @param array the array to retrieve the length from, may be null
* @return The length of the array, or <code>0</code> if the array is <code>null</code>
* @throws IllegalArgumentException if the object arguement is not an array.
* @since 2.1
*/
public static int getLength(Object array) {
if (array == null) {
return 0;
}
return Array.getLength(array);
}
/**
* <p>Shallow clones an array returning a typecast result and handling
* <code>null</code>.</p>
*
* <p>The objects in the array are not cloned, thus there is no special
* handling for multi-dimensional arrays.</p>
*
* <p>This method returns <code>null</code> for a <code>null</code> input array.</p>
*
* @param array the array to shallow clone, may be <code>null</code>
* @return the cloned array, <code>null</code> if <code>null</code> input
*/
public static short[] clone(short[] array) {
if (array == null) {
return null;
}
return (short[]) array.clone();
}
}
Removes the first occurrence of the specified element from the specified long value array.
/* Copyright 2004 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import java.lang.reflect.Array;
/**
* <p>Operations on arrays, primitive arrays (like <code>int[]</code>) and
* primitive wrapper arrays (like <code>Integer[]</code>).</p>
*
* <p>This class tries to handle <code>null</code> input gracefully.
* An exception will not be thrown for a <code>null</code>
* array input. However, an Object array that contains a <code>null</code>
* element may throw an exception. Each method documents its behaviour.</p>
*
* @author Stephen Colebourne
* @author Moritz Petersen
* @author
* @author Maarten Coene
* @since 2.0
* @version $Id: ArrayUtils.java 632503 2008-03-01 00:21:52Z ggregory $
*/
public class Main {
/**
* <p>Removes the element at the specified position from the specified array.
* All subsequent elements are shifted to the left (substracts one from
* their indices).</p>
*
* <p>This method returns a new array with the same elements of the input
* array except the element on the specified position. The component
* type of the returned array is always the same as that of the input
* array.</p>
*
* <p>If the input array is <code>null</code>, an IndexOutOfBoundsException
* will be thrown, because in that case no valid index can be specified.</p>
*
* <pre>
* ArrayUtils.remove([1], 0) = []
* ArrayUtils.remove([2, 6], 0) = [6]
* ArrayUtils.remove([2, 6], 1) = [2]
* ArrayUtils.remove([2, 6, 3], 1) = [2, 3]
* </pre>
*
* @param array the array to remove the element from, may not be <code>null</code>
* @param index the position of the element to be removed
* @return A new array containing the existing elements except the element
* at the specified position.
* @throws IndexOutOfBoundsException if the index is out of range
* (index < 0 || index >= array.length), or if the array is <code>null</code>.
* @since 2.1
*/
public static long[] remove(long[] array, int index) {
return (long[]) remove((Object) array, index);
}
/**
* <p>Removes the first occurrence of the specified element from the
* specified array. All subsequent elements are shifted to the left
* (substracts one from their indices). If the array doesn"t contains
* such an element, no elements are removed from the array.</p>
*
* <p>This method returns a new array with the same elements of the input
* array except the first occurrence of the specified element. The component
* type of the returned array is always the same as that of the input
* array.</p>
*
* <pre>
* ArrayUtils.removeElement(null, 1) = null
* ArrayUtils.removeElement([], 1) = []
* ArrayUtils.removeElement([1], 2) = [1]
* ArrayUtils.removeElement([1, 3], 1) = [3]
* ArrayUtils.removeElement([1, 3, 1], 1) = [3, 1]
* </pre>
*
* @param array the array to remove the element from, may be <code>null</code>
* @param element the element to be removed
* @return A new array containing the existing elements except the first
* occurrence of the specified element.
* @since 2.1
*/
public static long[] removeElement(long[] array, long element) {
int index = indexOf(array, element);
if (index == -1) {
return clone(array);
}
return remove(array, index);
}
/**
* <p>Removes the element at the specified position from the specified array.
* All subsequent elements are shifted to the left (substracts one from
* their indices).</p>
*
* <p>This method returns a new array with the same elements of the input
* array except the element on the specified position. The component
* type of the returned array is always the same as that of the input
* array.</p>
*
* <p>If the input array is <code>null</code>, an IndexOutOfBoundsException
* will be thrown, because in that case no valid index can be specified.</p>
*
* @param array the array to remove the element from, may not be <code>null</code>
* @param index the position of the element to be removed
* @return A new array containing the existing elements except the element
* at the specified position.
* @throws IndexOutOfBoundsException if the index is out of range
* (index < 0 || index >= array.length), or if the array is <code>null</code>.
* @since 2.1
*/
private static Object remove(Object array, int index) {
int length = getLength(array);
if (index < 0 || index >= length) {
throw new IndexOutOfBoundsException("Index: " + index + ", Length: " + length);
}
Object result = Array.newInstance(array.getClass().getComponentType(), length - 1);
System.arraycopy(array, 0, result, 0, index);
if (index < length - 1) {
System.arraycopy(array, index + 1, result, index, length - index - 1);
}
return result;
}
/**
* <p>Finds the index of the given value in the array starting at the given index.</p>
*
* <p>This method returns {@link #INDEX_NOT_FOUND} (<code>-1</code>) for a <code>null</code> input array.</p>
*
* <p>A negative startIndex is treated as zero. A startIndex larger than the array
* length will return {@link #INDEX_NOT_FOUND} (<code>-1</code>).</p>
*
* @param array the array to search through for the object, may be <code>null</code>
* @param valueToFind the value to find
* @param startIndex the index to start searching at
* @return the index of the value within the array,
* {@link #INDEX_NOT_FOUND} (<code>-1</code>) if not found or <code>null</code> array input
*/
public static int indexOf(long[] array, long valueToFind) {
if (array == null) {
return -1;
}
for (int i = 0; i < array.length; i++) {
if (valueToFind == array[i]) {
return i;
}
}
return -1;
}
/**
* <p>Returns the length of the specified array.
* This method can deal with <code>Object</code> arrays and with primitive arrays.</p>
*
* <p>If the input array is <code>null</code>, <code>0</code> is returned.</p>
*
* <pre>
* ArrayUtils.getLength(null) = 0
* ArrayUtils.getLength([]) = 0
* ArrayUtils.getLength([null]) = 1
* ArrayUtils.getLength([true, false]) = 2
* ArrayUtils.getLength([1, 2, 3]) = 3
* ArrayUtils.getLength(["a", "b", "c"]) = 3
* </pre>
*
* @param array the array to retrieve the length from, may be null
* @return The length of the array, or <code>0</code> if the array is <code>null</code>
* @throws IllegalArgumentException if the object arguement is not an array.
* @since 2.1
*/
public static int getLength(Object array) {
if (array == null) {
return 0;
}
return Array.getLength(array);
}
/**
* <p>Shallow clones an array returning a typecast result and handling
* <code>null</code>.</p>
*
* <p>The objects in the array are not cloned, thus there is no special
* handling for multi-dimensional arrays.</p>
*
* <p>This method returns <code>null</code> for a <code>null</code> input array.</p>
*
* @param array the array to shallow clone, may be <code>null</code>
* @return the cloned array, <code>null</code> if <code>null</code> input
*/
public static long[] clone(long[] array) {
if (array == null) {
return null;
}
return (long[]) array.clone();
}
}