Short.hx 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387
  1. package java.lang;
  2. /*
  3. * Copyright (c) 1996, 2009, Oracle and/or its affiliates. All rights reserved.
  4. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  5. *
  6. * This code is free software; you can redistribute it and/or modify it
  7. * under the terms of the GNU General Public License version 2 only, as
  8. * published by the Free Software Foundation. Oracle designates this
  9. * particular file as subject to the "Classpath" exception as provided
  10. * by Oracle in the LICENSE file that accompanied this code.
  11. *
  12. * This code is distributed in the hope that it will be useful, but WITHOUT
  13. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  14. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  15. * version 2 for more details (a copy is included in the LICENSE file that
  16. * accompanied this code).
  17. *
  18. * You should have received a copy of the GNU General Public License version
  19. * 2 along with this work; if not, write to the Free Software Foundation,
  20. * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  21. *
  22. * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  23. * or visit www.oracle.com if you need additional information or have any
  24. * questions.
  25. */
  26. /**
  27. * The {@code Short} class wraps a value of primitive type {@code
  28. * short} in an object. An object of type {@code Short} contains a
  29. * single field whose type is {@code short}.
  30. *
  31. * <p>In addition, this class provides several methods for converting
  32. * a {@code short} to a {@code String} and a {@code String} to a
  33. * {@code short}, as well as other constants and methods useful when
  34. * dealing with a {@code short}.
  35. *
  36. * @author Nakul Saraiya
  37. * @author Joseph D. Darcy
  38. * @see java.lang.Number
  39. * @since JDK1.1
  40. */
  41. @:require(java1) extern class Short extends java.lang.Number implements java.lang.Comparable<Short>
  42. {
  43. /**
  44. * A constant holding the minimum value a {@code short} can
  45. * have, -2<sup>15</sup>.
  46. */
  47. public static var MIN_VALUE(default, null) : java.StdTypes.Int16;
  48. /**
  49. * A constant holding the maximum value a {@code short} can
  50. * have, 2<sup>15</sup>-1.
  51. */
  52. public static var MAX_VALUE(default, null) : java.StdTypes.Int16;
  53. /**
  54. * The {@code Class} instance representing the primitive type
  55. * {@code short}.
  56. */
  57. public static var TYPE(default, null) : Class<Short>;
  58. /**
  59. * Returns a new {@code String} object representing the
  60. * specified {@code short}. The radix is assumed to be 10.
  61. *
  62. * @param s the {@code short} to be converted
  63. * @return the string representation of the specified {@code short}
  64. * @see java.lang.Integer#toString(int)
  65. */
  66. @:native('toString') @:overload public static function _toString(s : java.StdTypes.Int16) : String;
  67. /**
  68. * Parses the string argument as a signed {@code short} in the
  69. * radix specified by the second argument. The characters in the
  70. * string must all be digits, of the specified radix (as
  71. * determined by whether {@link java.lang.Character#digit(char,
  72. * int)} returns a nonnegative value) except that the first
  73. * character may be an ASCII minus sign {@code '-'}
  74. * (<code>'&#92;u002D'</code>) to indicate a negative value or an
  75. * ASCII plus sign {@code '+'} (<code>'&#92;u002B'</code>) to
  76. * indicate a positive value. The resulting {@code short} value
  77. * is returned.
  78. *
  79. * <p>An exception of type {@code NumberFormatException} is
  80. * thrown if any of the following situations occurs:
  81. * <ul>
  82. * <li> The first argument is {@code null} or is a string of
  83. * length zero.
  84. *
  85. * <li> The radix is either smaller than {@link
  86. * java.lang.Character#MIN_RADIX} or larger than {@link
  87. * java.lang.Character#MAX_RADIX}.
  88. *
  89. * <li> Any character of the string is not a digit of the
  90. * specified radix, except that the first character may be a minus
  91. * sign {@code '-'} (<code>'&#92;u002D'</code>) or plus sign
  92. * {@code '+'} (<code>'&#92;u002B'</code>) provided that the
  93. * string is longer than length 1.
  94. *
  95. * <li> The value represented by the string is not a value of type
  96. * {@code short}.
  97. * </ul>
  98. *
  99. * @param s the {@code String} containing the
  100. * {@code short} representation to be parsed
  101. * @param radix the radix to be used while parsing {@code s}
  102. * @return the {@code short} represented by the string
  103. * argument in the specified radix.
  104. * @throws NumberFormatException If the {@code String}
  105. * does not contain a parsable {@code short}.
  106. */
  107. @:overload public static function parseShort(s : String, radix : Int) : java.StdTypes.Int16;
  108. /**
  109. * Parses the string argument as a signed decimal {@code
  110. * short}. The characters in the string must all be decimal
  111. * digits, except that the first character may be an ASCII minus
  112. * sign {@code '-'} (<code>'&#92;u002D'</code>) to indicate a
  113. * negative value or an ASCII plus sign {@code '+'}
  114. * (<code>'&#92;u002B'</code>) to indicate a positive value. The
  115. * resulting {@code short} value is returned, exactly as if the
  116. * argument and the radix 10 were given as arguments to the {@link
  117. * #parseShort(java.lang.String, int)} method.
  118. *
  119. * @param s a {@code String} containing the {@code short}
  120. * representation to be parsed
  121. * @return the {@code short} value represented by the
  122. * argument in decimal.
  123. * @throws NumberFormatException If the string does not
  124. * contain a parsable {@code short}.
  125. */
  126. @:overload public static function parseShort(s : String) : java.StdTypes.Int16;
  127. /**
  128. * Returns a {@code Short} object holding the value
  129. * extracted from the specified {@code String} when parsed
  130. * with the radix given by the second argument. The first argument
  131. * is interpreted as representing a signed {@code short} in
  132. * the radix specified by the second argument, exactly as if the
  133. * argument were given to the {@link #parseShort(java.lang.String,
  134. * int)} method. The result is a {@code Short} object that
  135. * represents the {@code short} value specified by the string.
  136. *
  137. * <p>In other words, this method returns a {@code Short} object
  138. * equal to the value of:
  139. *
  140. * <blockquote>
  141. * {@code new Short(Short.parseShort(s, radix))}
  142. * </blockquote>
  143. *
  144. * @param s the string to be parsed
  145. * @param radix the radix to be used in interpreting {@code s}
  146. * @return a {@code Short} object holding the value
  147. * represented by the string argument in the
  148. * specified radix.
  149. * @throws NumberFormatException If the {@code String} does
  150. * not contain a parsable {@code short}.
  151. */
  152. @:overload public static function valueOf(s : String, radix : Int) : Short;
  153. /**
  154. * Returns a {@code Short} object holding the
  155. * value given by the specified {@code String}. The argument
  156. * is interpreted as representing a signed decimal
  157. * {@code short}, exactly as if the argument were given to
  158. * the {@link #parseShort(java.lang.String)} method. The result is
  159. * a {@code Short} object that represents the
  160. * {@code short} value specified by the string.
  161. *
  162. * <p>In other words, this method returns a {@code Short} object
  163. * equal to the value of:
  164. *
  165. * <blockquote>
  166. * {@code new Short(Short.parseShort(s))}
  167. * </blockquote>
  168. *
  169. * @param s the string to be parsed
  170. * @return a {@code Short} object holding the value
  171. * represented by the string argument
  172. * @throws NumberFormatException If the {@code String} does
  173. * not contain a parsable {@code short}.
  174. */
  175. @:overload public static function valueOf(s : String) : Short;
  176. /**
  177. * Returns a {@code Short} instance representing the specified
  178. * {@code short} value.
  179. * If a new {@code Short} instance is not required, this method
  180. * should generally be used in preference to the constructor
  181. * {@link #Short(short)}, as this method is likely to yield
  182. * significantly better space and time performance by caching
  183. * frequently requested values.
  184. *
  185. * This method will always cache values in the range -128 to 127,
  186. * inclusive, and may cache other values outside of this range.
  187. *
  188. * @param s a short value.
  189. * @return a {@code Short} instance representing {@code s}.
  190. * @since 1.5
  191. */
  192. @:require(java5) @:overload public static function valueOf(s : java.StdTypes.Int16) : Short;
  193. /**
  194. * Decodes a {@code String} into a {@code Short}.
  195. * Accepts decimal, hexadecimal, and octal numbers given by
  196. * the following grammar:
  197. *
  198. * <blockquote>
  199. * <dl>
  200. * <dt><i>DecodableString:</i>
  201. * <dd><i>Sign<sub>opt</sub> DecimalNumeral</i>
  202. * <dd><i>Sign<sub>opt</sub></i> {@code 0x} <i>HexDigits</i>
  203. * <dd><i>Sign<sub>opt</sub></i> {@code 0X} <i>HexDigits</i>
  204. * <dd><i>Sign<sub>opt</sub></i> {@code #} <i>HexDigits</i>
  205. * <dd><i>Sign<sub>opt</sub></i> {@code 0} <i>OctalDigits</i>
  206. * <p>
  207. * <dt><i>Sign:</i>
  208. * <dd>{@code -}
  209. * <dd>{@code +}
  210. * </dl>
  211. * </blockquote>
  212. *
  213. * <i>DecimalNumeral</i>, <i>HexDigits</i>, and <i>OctalDigits</i>
  214. * are as defined in section 3.10.1 of
  215. * <cite>The Java&trade; Language Specification</cite>,
  216. * except that underscores are not accepted between digits.
  217. *
  218. * <p>The sequence of characters following an optional
  219. * sign and/or radix specifier ("{@code 0x}", "{@code 0X}",
  220. * "{@code #}", or leading zero) is parsed as by the {@code
  221. * Short.parseShort} method with the indicated radix (10, 16, or
  222. * 8). This sequence of characters must represent a positive
  223. * value or a {@link NumberFormatException} will be thrown. The
  224. * result is negated if first character of the specified {@code
  225. * String} is the minus sign. No whitespace characters are
  226. * permitted in the {@code String}.
  227. *
  228. * @param nm the {@code String} to decode.
  229. * @return a {@code Short} object holding the {@code short}
  230. * value represented by {@code nm}
  231. * @throws NumberFormatException if the {@code String} does not
  232. * contain a parsable {@code short}.
  233. * @see java.lang.Short#parseShort(java.lang.String, int)
  234. */
  235. @:overload public static function decode(nm : String) : Short;
  236. /**
  237. * Constructs a newly allocated {@code Short} object that
  238. * represents the specified {@code short} value.
  239. *
  240. * @param value the value to be represented by the
  241. * {@code Short}.
  242. */
  243. @:overload public function new(value : java.StdTypes.Int16) : Void;
  244. /**
  245. * Constructs a newly allocated {@code Short} object that
  246. * represents the {@code short} value indicated by the
  247. * {@code String} parameter. The string is converted to a
  248. * {@code short} value in exactly the manner used by the
  249. * {@code parseShort} method for radix 10.
  250. *
  251. * @param s the {@code String} to be converted to a
  252. * {@code Short}
  253. * @throws NumberFormatException If the {@code String}
  254. * does not contain a parsable {@code short}.
  255. * @see java.lang.Short#parseShort(java.lang.String, int)
  256. */
  257. @:overload public function new(s : String) : Void;
  258. /**
  259. * Returns the value of this {@code Short} as a
  260. * {@code byte}.
  261. */
  262. @:overload override public function byteValue() : java.StdTypes.Int8;
  263. /**
  264. * Returns the value of this {@code Short} as a
  265. * {@code short}.
  266. */
  267. @:overload override public function shortValue() : java.StdTypes.Int16;
  268. /**
  269. * Returns the value of this {@code Short} as an
  270. * {@code int}.
  271. */
  272. @:overload override public function intValue() : Int;
  273. /**
  274. * Returns the value of this {@code Short} as a
  275. * {@code long}.
  276. */
  277. @:overload override public function longValue() : haxe.Int64;
  278. /**
  279. * Returns the value of this {@code Short} as a
  280. * {@code float}.
  281. */
  282. @:overload override public function floatValue() : Single;
  283. /**
  284. * Returns the value of this {@code Short} as a
  285. * {@code double}.
  286. */
  287. @:overload override public function doubleValue() : Float;
  288. /**
  289. * Returns a {@code String} object representing this
  290. * {@code Short}'s value. The value is converted to signed
  291. * decimal representation and returned as a string, exactly as if
  292. * the {@code short} value were given as an argument to the
  293. * {@link java.lang.Short#toString(short)} method.
  294. *
  295. * @return a string representation of the value of this object in
  296. * base&nbsp;10.
  297. */
  298. @:overload public function toString() : String;
  299. /**
  300. * Returns a hash code for this {@code Short}; equal to the result
  301. * of invoking {@code intValue()}.
  302. *
  303. * @return a hash code value for this {@code Short}
  304. */
  305. @:overload public function hashCode() : Int;
  306. /**
  307. * Compares this object to the specified object. The result is
  308. * {@code true} if and only if the argument is not
  309. * {@code null} and is a {@code Short} object that
  310. * contains the same {@code short} value as this object.
  311. *
  312. * @param obj the object to compare with
  313. * @return {@code true} if the objects are the same;
  314. * {@code false} otherwise.
  315. */
  316. @:overload public function equals(obj : Dynamic) : Bool;
  317. /**
  318. * Compares two {@code Short} objects numerically.
  319. *
  320. * @param anotherShort the {@code Short} to be compared.
  321. * @return the value {@code 0} if this {@code Short} is
  322. * equal to the argument {@code Short}; a value less than
  323. * {@code 0} if this {@code Short} is numerically less
  324. * than the argument {@code Short}; and a value greater than
  325. * {@code 0} if this {@code Short} is numerically
  326. * greater than the argument {@code Short} (signed
  327. * comparison).
  328. * @since 1.2
  329. */
  330. @:require(java2) @:overload public function compareTo(anotherShort : Short) : Int;
  331. /**
  332. * Compares two {@code short} values numerically.
  333. * The value returned is identical to what would be returned by:
  334. * <pre>
  335. * Short.valueOf(x).compareTo(Short.valueOf(y))
  336. * </pre>
  337. *
  338. * @param x the first {@code short} to compare
  339. * @param y the second {@code short} to compare
  340. * @return the value {@code 0} if {@code x == y};
  341. * a value less than {@code 0} if {@code x < y}; and
  342. * a value greater than {@code 0} if {@code x > y}
  343. * @since 1.7
  344. */
  345. @:require(java7) @:overload public static function compare(x : java.StdTypes.Int16, y : java.StdTypes.Int16) : Int;
  346. /**
  347. * The number of bits used to represent a {@code short} value in two's
  348. * complement binary form.
  349. * @since 1.5
  350. */
  351. @:require(java5) public static var SIZE(default, null) : Int;
  352. /**
  353. * Returns the value obtained by reversing the order of the bytes in the
  354. * two's complement representation of the specified {@code short} value.
  355. *
  356. * @return the value obtained by reversing (or, equivalently, swapping)
  357. * the bytes in the specified {@code short} value.
  358. * @since 1.5
  359. */
  360. @:require(java5) @:overload public static function reverseBytes(i : java.StdTypes.Int16) : java.StdTypes.Int16;
  361. }