SupportClass.cs 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. //
  2. // In order to convert some functionality to Visual C#, the Java Language Conversion Assistant
  3. // creates "support classes" that duplicate the original functionality.
  4. //
  5. // Support classes replicate the functionality of the original code, but in some cases they are
  6. // substantially different architecturally. Although every effort is made to preserve the
  7. // original architecture of the application in the converted project, the user should be aware that
  8. // the primary goal of these support classes is to replicate functionality, and that at times
  9. // the architecture of the resulting solution may differ somewhat.
  10. //
  11. using System;
  12. using System.Collections.Generic;
  13. using System.Text;
  14. namespace FastReport.Barcode.Aztec
  15. {
  16. /// <summary>
  17. /// Contains conversion support elements such as classes, interfaces and static methods.
  18. /// </summary>
  19. internal static class SupportClass
  20. {
  21. /*******************************/
  22. /// <summary>
  23. /// Copies an array of chars obtained from a String into a specified array of chars
  24. /// </summary>
  25. /// <param name="sourceString">The String to get the chars from</param>
  26. /// <param name="sourceStart">Position of the String to start getting the chars</param>
  27. /// <param name="sourceEnd">Position of the String to end getting the chars</param>
  28. /// <param name="destinationArray">Array to return the chars</param>
  29. /// <param name="destinationStart">Position of the destination array of chars to start storing the chars</param>
  30. /// <returns>An array of chars</returns>
  31. public static void GetCharsFromString(System.String sourceString, int sourceStart, int sourceEnd, char[] destinationArray, int destinationStart)
  32. {
  33. int sourceCounter = sourceStart;
  34. int destinationCounter = destinationStart;
  35. while (sourceCounter < sourceEnd)
  36. {
  37. destinationArray[destinationCounter] = (char)sourceString[sourceCounter];
  38. sourceCounter++;
  39. destinationCounter++;
  40. }
  41. }
  42. /*******************************/
  43. /// <summary>
  44. /// Sets the capacity for the specified List
  45. /// </summary>
  46. /// <param name="vector">The List which capacity will be set</param>
  47. /// <param name="newCapacity">The new capacity value</param>
  48. public static void SetCapacity<T>(System.Collections.Generic.IList<T> vector, int newCapacity) where T : new()
  49. {
  50. while (newCapacity > vector.Count)
  51. vector.Add(new T());
  52. while (newCapacity < vector.Count)
  53. vector.RemoveAt(vector.Count - 1);
  54. }
  55. /// <summary>
  56. /// Converts a string-Collection to an array
  57. /// </summary>
  58. /// <param name="strings">The strings.</param>
  59. /// <returns></returns>
  60. public static String[] toStringArray(ICollection<string> strings)
  61. {
  62. String[] result = new String[strings.Count];
  63. strings.CopyTo(result, 0);
  64. return result;
  65. }
  66. /// <summary>
  67. /// Joins all elements to one string.
  68. /// </summary>
  69. /// <typeparam name="T"></typeparam>
  70. /// <param name="separator">The separator.</param>
  71. /// <param name="values">The values.</param>
  72. /// <returns></returns>
  73. public static string Join<T>(string separator, IEnumerable<T> values)
  74. {
  75. StringBuilder builder = new StringBuilder();
  76. separator = separator ?? String.Empty;
  77. if (values != null)
  78. {
  79. foreach (T value in values)
  80. {
  81. builder.Append(value);
  82. builder.Append(separator);
  83. }
  84. if (builder.Length > 0)
  85. builder.Length -= separator.Length;
  86. }
  87. return builder.ToString();
  88. }
  89. /// <summary>
  90. /// Fills the specified array.
  91. /// (can't use extension method because of .Net 2.0 support)
  92. /// </summary>
  93. /// <typeparam name="T"></typeparam>
  94. /// <param name="array">The array.</param>
  95. /// <param name="value">The value.</param>
  96. public static void Fill<T>(T[] array, T value)
  97. {
  98. for (int i = 0; i < array.Length; i++)
  99. {
  100. array[i] = value;
  101. }
  102. }
  103. /// <summary>
  104. /// Fills the specified array.
  105. /// (can't use extension method because of .Net 2.0 support)
  106. /// </summary>
  107. /// <typeparam name="T"></typeparam>
  108. /// <param name="array">The array.</param>
  109. /// <param name="startIndex">The start index.</param>
  110. /// <param name="endIndex">The end index.</param>
  111. /// <param name="value">The value.</param>
  112. public static void Fill<T>(T[] array, int startIndex, int endIndex, T value)
  113. {
  114. for (int i = startIndex; i < endIndex; i++)
  115. {
  116. array[i] = value;
  117. }
  118. }
  119. public static string ToBinaryString(int x)
  120. {
  121. char[] bits = new char[32];
  122. int i = 0;
  123. while (x != 0)
  124. {
  125. bits[i++] = (x & 1) == 1 ? '1' : '0';
  126. x >>= 1;
  127. }
  128. Array.Reverse(bits, 0, i);
  129. return new string(bits);
  130. }
  131. public static int bitCount(int n)
  132. {
  133. int ret = 0;
  134. while (n != 0)
  135. {
  136. n &= (n - 1);
  137. ret++;
  138. }
  139. return ret;
  140. }
  141. ///// <summary>
  142. ///// Savely gets the value of a decoding hint
  143. ///// if hints is null the default is returned
  144. ///// </summary>
  145. ///// <typeparam name="T"></typeparam>
  146. ///// <param name="hints">The hints.</param>
  147. ///// <param name="hintType">Type of the hint.</param>
  148. ///// <param name="default">The @default.</param>
  149. ///// <returns></returns>
  150. //public static T GetValue<T>(IDictionary<DecodeHintType, object> hints, DecodeHintType hintType, T @default)
  151. //{
  152. // // can't use extension method because of .Net 2.0 support
  153. // if (hints == null)
  154. // return @default;
  155. // if (!hints.ContainsKey(hintType))
  156. // return @default;
  157. // return (T)hints[hintType];
  158. //}
  159. }
  160. }