2 // In order to convert some functionality to Visual C#, the Java Language Conversion Assistant
\r
3 // creates "support classes" that duplicate the original functionality.
\r
5 // Support classes replicate the functionality of the original code, but in some cases they are
\r
6 // substantially different architecturally. Although every effort is made to preserve the
\r
7 // original architecture of the application in the converted project, the user should be aware that
\r
8 // the primary goal of these support classes is to replicate functionality, and that at times
\r
9 // the architecture of the resulting solution may differ somewhat.
\r
15 /// Contains conversion support elements such as classes, interfaces and static methods.
\r
17 public class SupportClass
\r
20 /// Converts an array of sbytes to an array of bytes
\r
22 /// <param name="sbyteArray">The array of sbytes to be converted</param>
\r
23 /// <returns>The new array of bytes</returns>
\r
24 public static byte[] ToByteArray(sbyte[] sbyteArray)
\r
26 byte[] byteArray = null;
\r
28 if (sbyteArray != null)
\r
30 byteArray = new byte[sbyteArray.Length];
\r
31 for(int index=0; index < sbyteArray.Length; index++)
\r
32 byteArray[index] = (byte) sbyteArray[index];
\r
38 /// Converts a string to an array of bytes
\r
40 /// <param name="sourceString">The string to be converted</param>
\r
41 /// <returns>The new array of bytes</returns>
\r
42 public static byte[] ToByteArray(System.String sourceString)
\r
44 return System.Text.UTF8Encoding.UTF8.GetBytes(sourceString);
\r
48 /// Converts a array of object-type instances to a byte-type array.
\r
50 /// <param name="tempObjectArray">Array to convert.</param>
\r
51 /// <returns>An array of byte type elements.</returns>
\r
52 public static byte[] ToByteArray(System.Object[] tempObjectArray)
\r
54 byte[] byteArray = null;
\r
55 if (tempObjectArray != null)
\r
57 byteArray = new byte[tempObjectArray.Length];
\r
58 for (int index = 0; index < tempObjectArray.Length; index++)
\r
59 byteArray[index] = (byte)tempObjectArray[index];
\r
64 /*******************************/
\r
66 /// Performs an unsigned bitwise right shift with the specified number
\r
68 /// <param name="number">Number to operate on</param>
\r
69 /// <param name="bits">Ammount of bits to shift</param>
\r
70 /// <returns>The resulting number from the shift operation</returns>
\r
71 public static int URShift(int number, int bits)
\r
74 return number >> bits;
\r
76 return (number >> bits) + (2 << ~bits);
\r
80 /// Performs an unsigned bitwise right shift with the specified number
\r
82 /// <param name="number">Number to operate on</param>
\r
83 /// <param name="bits">Ammount of bits to shift</param>
\r
84 /// <returns>The resulting number from the shift operation</returns>
\r
85 public static int URShift(int number, long bits)
\r
87 return URShift(number, (int)bits);
\r
91 /// Performs an unsigned bitwise right shift with the specified number
\r
93 /// <param name="number">Number to operate on</param>
\r
94 /// <param name="bits">Ammount of bits to shift</param>
\r
95 /// <returns>The resulting number from the shift operation</returns>
\r
96 public static long URShift(long number, int bits)
\r
99 return number >> bits;
\r
101 return (number >> bits) + (2L << ~bits);
\r
105 /// Performs an unsigned bitwise right shift with the specified number
\r
107 /// <param name="number">Number to operate on</param>
\r
108 /// <param name="bits">Ammount of bits to shift</param>
\r
109 /// <returns>The resulting number from the shift operation</returns>
\r
110 public static long URShift(long number, long bits)
\r
112 return URShift(number, (int)bits);
\r
115 /*******************************/
\r
117 /// This method returns the literal value received
\r
119 /// <param name="literal">The literal to return</param>
\r
120 /// <returns>The received value</returns>
\r
121 public static long Identity(long literal)
\r
127 /// This method returns the literal value received
\r
129 /// <param name="literal">The literal to return</param>
\r
130 /// <returns>The received value</returns>
\r
131 public static ulong Identity(ulong literal)
\r
137 /// This method returns the literal value received
\r
139 /// <param name="literal">The literal to return</param>
\r
140 /// <returns>The received value</returns>
\r
141 public static float Identity(float literal)
\r
147 /// This method returns the literal value received
\r
149 /// <param name="literal">The literal to return</param>
\r
150 /// <returns>The received value</returns>
\r
151 public static double Identity(double literal)
\r
156 /*******************************/
\r
158 /// Copies an array of chars obtained from a String into a specified array of chars
\r
160 /// <param name="sourceString">The String to get the chars from</param>
\r
161 /// <param name="sourceStart">Position of the String to start getting the chars</param>
\r
162 /// <param name="sourceEnd">Position of the String to end getting the chars</param>
\r
163 /// <param name="destinationArray">Array to return the chars</param>
\r
164 /// <param name="destinationStart">Position of the destination array of chars to start storing the chars</param>
\r
165 /// <returns>An array of chars</returns>
\r
166 public static void GetCharsFromString(System.String sourceString, int sourceStart, int sourceEnd, char[] destinationArray, int destinationStart)
\r
169 int destinationCounter;
\r
170 sourceCounter = sourceStart;
\r
171 destinationCounter = destinationStart;
\r
172 while (sourceCounter < sourceEnd)
\r
174 destinationArray[destinationCounter] = (char) sourceString[sourceCounter];
\r
176 destinationCounter++;
\r
180 /*******************************/
\r
182 /// Sets the capacity for the specified ArrayList
\r
184 /// <param name="vector">The ArrayList which capacity will be set</param>
\r
185 /// <param name="newCapacity">The new capacity value</param>
\r
186 public static void SetCapacity(System.Collections.ArrayList vector, int newCapacity)
\r
188 if (newCapacity > vector.Count)
\r
189 vector.AddRange(new Array[newCapacity-vector.Count]);
\r
190 else if (newCapacity < vector.Count)
\r
191 vector.RemoveRange(newCapacity, vector.Count - newCapacity);
\r
192 vector.Capacity = newCapacity;
\r
197 /*******************************/
\r
199 /// Receives a byte array and returns it transformed in an sbyte array
\r
201 /// <param name="byteArray">Byte array to process</param>
\r
202 /// <returns>The transformed array</returns>
\r
203 public static sbyte[] ToSByteArray(byte[] byteArray)
\r
205 sbyte[] sbyteArray = null;
\r
206 if (byteArray != null)
\r
208 sbyteArray = new sbyte[byteArray.Length];
\r
209 for(int index=0; index < byteArray.Length; index++)
\r
210 sbyteArray[index] = (sbyte) byteArray[index];
\r