Byte.hx 14 KB

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