Showing the changes to Source/Libraries/TSFJavaLibrary/src/org/gpa/tsf/util/ArrayExtensions.java (1 of 915 files). Show all
Unified · Split
| @@ -0,0 +1,195 @@ | ||
| 1 | +//****************************************************************************************************** | |
| 2 | +// ArrayExtensions.java - Gbtc | |
| 3 | +// | |
| 4 | +// Copyright � 2010, Grid Protection Alliance. All Rights Reserved. | |
| 5 | +// | |
| 6 | +// Licensed to the Grid Protection Alliance (GPA) under one or more contributor license agreements. See | |
| 7 | +// the NOTICE file distributed with this work for additional information regarding copyright ownership. | |
| 8 | +// The GPA licenses this file to you under the Eclipse Public License -v 1.0 (the "License"); you may | |
| 9 | +// not use this file except in compliance with the License. You may obtain a copy of the License at: | |
| 10 | +// | |
| 11 | +// http://www.opensource.org/licenses/eclipse-1.0.php | |
| 12 | +// | |
| 13 | +// Unless agreed to in writing, the subject software distributed under the License is distributed on an | |
| 14 | +// "AS-IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. Refer to the | |
| 15 | +// License for the specific language governing permissions and limitations. | |
| 16 | +// | |
| 17 | +// Code Modification History: | |
| 18 | +// ---------------------------------------------------------------------------------------------------- | |
| 19 | +// 04/18/2012 - Stephen C. Wills | |
| 20 | +// Generated original version of source code. | |
| 21 | +// | |
| 22 | +//****************************************************************************************************** | |
| 23 | + | |
| 24 | +package org.gpa.tsf.util; | |
| 25 | + | |
| 26 | +/** | |
| 27 | + * Utility class that provides additional functionality for arrays. | |
| 28 | + */ | |
| 29 | +public class ArrayExtensions | |
| 30 | +{ | |
| 31 | + /** | |
| 32 | + * Copies the specified number of bytes from the source array to the | |
| 33 | + * destination array, starting from the given offsets in each array. | |
| 34 | + * | |
| 35 | + * @param source the source array | |
| 36 | + * @param srcOffset the offset into the source array where the data | |
| 37 | + * to be copied starts | |
| 38 | + * @param dest the destination array | |
| 39 | + * @param destOffset the offset into the destination array where the | |
| 40 | + * data is to be copied | |
| 41 | + * @param length the amount of data to be copied | |
| 42 | + */ | |
| 43 | + public static void blockCopy(byte[] source, int srcOffset, byte[] dest, int destOffset, int length) | |
| 44 | + { | |
| 45 | + for (int i = 0; i < length; i++) | |
| 46 | + dest[destOffset + i] = source[srcOffset + i]; | |
| 47 | + } | |
| 48 | + | |
| 49 | + /** | |
| 50 | + * Copies the specified number of short integers from the source array | |
| 51 | + * to the destination array, starting from the given offsets in each | |
| 52 | + * array. | |
| 53 | + * | |
| 54 | + * @param source the source array | |
| 55 | + * @param srcOffset the offset into the source array where the data | |
| 56 | + * to be copied starts | |
| 57 | + * @param dest the destination array | |
| 58 | + * @param destOffset the offset into the destination array where the | |
| 59 | + * data is to be copied | |
| 60 | + * @param length the amount of data to be copied | |
| 61 | + */ | |
| 62 | + public static void blockCopy(short[] source, int srcOffset, short[] dest, int destOffset, int length) | |
| 63 | + { | |
| 64 | + for (int i = 0; i < length; i++) | |
| 65 | + dest[destOffset + i] = source[srcOffset + i]; | |
| 66 | + } | |
| 67 | + | |
| 68 | + /** | |
| 69 | + * Copies the specified number of integers from the source array to the | |
| 70 | + * destination array, starting from the given offsets in each array. | |
| 71 | + * | |
| 72 | + * @param source the source array | |
| 73 | + * @param srcOffset the offset into the source array where the data | |
| 74 | + * to be copied starts | |
| 75 | + * @param dest the destination array | |
| 76 | + * @param destOffset the offset into the destination array where the | |
| 77 | + * data is to be copied | |
| 78 | + * @param length the amount of data to be copied | |
| 79 | + */ | |
| 80 | + public static void blockCopy(int[] source, int srcOffset, int[] dest, int destOffset, int length) | |
| 81 | + { | |
| 82 | + for (int i = 0; i < length; i++) | |
| 83 | + dest[destOffset + i] = source[srcOffset + i]; | |
| 84 | + } | |
| 85 | + | |
| 86 | + /** | |
| 87 | + * Copies the specified number of long integers from the source array | |
| 88 | + * to the destination array, starting from the given offsets in each | |
| 89 | + * array. | |
| 90 | + * | |
| 91 | + * @param source the source array | |
| 92 | + * @param srcOffset the offset into the source array where the data | |
| 93 | + * to be copied starts | |
| 94 | + * @param dest the destination array | |
| 95 | + * @param destOffset the offset into the destination array where the | |
| 96 | + * data is to be copied | |
| 97 | + * @param length the amount of data to be copied | |
| 98 | + */ | |
| 99 | + public static void blockCopy(long[] source, int srcOffset, long[] dest, int destOffset, int length) | |
| 100 | + { | |
| 101 | + for (int i = 0; i < length; i++) | |
| 102 | + dest[destOffset + i] = source[srcOffset + i]; | |
| 103 | + } | |
| 104 | + | |
| 105 | + /** | |
| 106 | + * Copies the specified number of floats from the source array to the | |
| 107 | + * destination array, starting from the given offsets in each array. | |
| 108 | + * | |
| 109 | + * @param source the source array | |
| 110 | + * @param srcOffset the offset into the source array where the data | |
| 111 | + * to be copied starts | |
| 112 | + * @param dest the destination array | |
| 113 | + * @param destOffset the offset into the destination array where the | |
| 114 | + * data is to be copied | |
| 115 | + * @param length the amount of data to be copied | |
| 116 | + */ | |
| 117 | + public static void blockCopy(float[] source, int srcOffset, float[] dest, int destOffset, int length) | |
| 118 | + { | |
| 119 | + for (int i = 0; i < length; i++) | |
| 120 | + dest[destOffset + i] = source[srcOffset + i]; | |
| 121 | + } | |
| 122 | + | |
| 123 | + /** | |
| 124 | + * Copies the specified number of doubles from the source array to the | |
| 125 | + * destination array, starting from the given offsets in each array. | |
| 126 | + * | |
| 127 | + * @param source the source array | |
| 128 | + * @param srcOffset the offset into the source array where the data | |
| 129 | + * to be copied starts | |
| 130 | + * @param dest the destination array | |
| 131 | + * @param destOffset the offset into the destination array where the | |
| 132 | + * data is to be copied | |
| 133 | + * @param length the amount of data to be copied | |
| 134 | + */ | |
| 135 | + public static void blockCopy(double[] source, int srcOffset, double[] dest, int destOffset, int length) | |
| 136 | + { | |
| 137 | + for (int i = 0; i < length; i++) | |
| 138 | + dest[destOffset + i] = source[srcOffset + i]; | |
| 139 | + } | |
| 140 | + | |
| 141 | + /** | |
| 142 | + * Copies the specified number of boolean values from the source array | |
| 143 | + * to the destination array, starting from the given offsets in each | |
| 144 | + * array. | |
| 145 | + * | |
| 146 | + * @param source the source array | |
| 147 | + * @param srcOffset the offset into the source array where the data | |
| 148 | + * to be copied starts | |
| 149 | + * @param dest the destination array | |
| 150 | + * @param destOffset the offset into the destination array where the | |
| 151 | + * data is to be copied | |
| 152 | + * @param length the amount of data to be copied | |
| 153 | + */ | |
| 154 | + public static void blockCopy(boolean[] source, int srcOffset, boolean[] dest, int destOffset, int length) | |
| 155 | + { | |
| 156 | + for (int i = 0; i < length; i++) | |
| 157 | + dest[destOffset + i] = source[srcOffset + i]; | |
| 158 | + } | |
| 159 | + | |
| 160 | + /** | |
| 161 | + * Copies the specified number of characters from the source array to the | |
| 162 | + * destination array, starting from the given offsets in each array. | |
| 163 | + * | |
| 164 | + * @param source the source array | |
| 165 | + * @param srcOffset the offset into the source array where the data | |
| 166 | + * to be copied starts | |
| 167 | + * @param dest the destination array | |
| 168 | + * @param destOffset the offset into the destination array where the | |
| 169 | + * data is to be copied | |
| 170 | + * @param length the amount of data to be copied | |
| 171 | + */ | |
| 172 | + public static void blockCopy(char[] source, int srcOffset, char[] dest, int destOffset, int length) | |
| 173 | + { | |
| 174 | + for (int i = 0; i < length; i++) | |
| 175 | + dest[destOffset + i] = source[srcOffset + i]; | |
| 176 | + } | |
| 177 | + | |
| 178 | + /** | |
| 179 | + * Copies the specified number of objects from the source array to the | |
| 180 | + * destination array, starting from the given offsets in each array. | |
| 181 | + * | |
| 182 | + * @param source the source array | |
| 183 | + * @param srcOffset the offset into the source array where the data | |
| 184 | + * to be copied starts | |
| 185 | + * @param dest the destination array | |
| 186 | + * @param destOffset the offset into the destination array where the | |
| 187 | + * data is to be copied | |
| 188 | + * @param length the amount of data to be copied | |
| 189 | + */ | |
| 190 | + public static <T> void blockCopy(T[] source, int srcOffset, T[] dest, int destOffset, int length) | |
| 191 | + { | |
| 192 | + for (int i = 0; i < length; i++) | |
| 193 | + dest[destOffset + i] = source[srcOffset + i]; | |
| 194 | + } | |
| 195 | +} | |