Integer.hx 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796
  1. package java.lang;
  2. /*
  3. * Copyright (c) 1994, 2010, 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 Integer} class wraps a value of the primitive type
  28. * {@code int} in an object. An object of type {@code Integer}
  29. * contains a single field whose type is {@code int}.
  30. *
  31. * <p>In addition, this class provides several methods for converting
  32. * an {@code int} to a {@code String} and a {@code String} to an
  33. * {@code int}, as well as other constants and methods useful when
  34. * dealing with an {@code int}.
  35. *
  36. * <p>Implementation note: The implementations of the "bit twiddling"
  37. * methods (such as {@link #highestOneBit(int) highestOneBit} and
  38. * {@link #numberOfTrailingZeros(int) numberOfTrailingZeros}) are
  39. * based on material from Henry S. Warren, Jr.'s <i>Hacker's
  40. * Delight</i>, (Addison Wesley, 2002).
  41. *
  42. * @author Lee Boynton
  43. * @author Arthur van Hoff
  44. * @author Josh Bloch
  45. * @author Joseph D. Darcy
  46. * @since JDK1.0
  47. */
  48. @:require(java0) extern class Integer extends java.lang.Number implements java.lang.Comparable<Integer>
  49. {
  50. /**
  51. * A constant holding the minimum value an {@code int} can
  52. * have, -2<sup>31</sup>.
  53. */
  54. public static var MIN_VALUE(default, null) : Int;
  55. /**
  56. * A constant holding the maximum value an {@code int} can
  57. * have, 2<sup>31</sup>-1.
  58. */
  59. public static var MAX_VALUE(default, null) : Int;
  60. /**
  61. * The {@code Class} instance representing the primitive type
  62. * {@code int}.
  63. *
  64. * @since JDK1.1
  65. */
  66. @:require(java1) public static var TYPE(default, null) : Class<Integer>;
  67. /**
  68. * Returns a string representation of the first argument in the
  69. * radix specified by the second argument.
  70. *
  71. * <p>If the radix is smaller than {@code Character.MIN_RADIX}
  72. * or larger than {@code Character.MAX_RADIX}, then the radix
  73. * {@code 10} is used instead.
  74. *
  75. * <p>If the first argument is negative, the first element of the
  76. * result is the ASCII minus character {@code '-'}
  77. * (<code>'&#92;u002D'</code>). If the first argument is not
  78. * negative, no sign character appears in the result.
  79. *
  80. * <p>The remaining characters of the result represent the magnitude
  81. * of the first argument. If the magnitude is zero, it is
  82. * represented by a single zero character {@code '0'}
  83. * (<code>'&#92;u0030'</code>); otherwise, the first character of
  84. * the representation of the magnitude will not be the zero
  85. * character. The following ASCII characters are used as digits:
  86. *
  87. * <blockquote>
  88. * {@code 0123456789abcdefghijklmnopqrstuvwxyz}
  89. * </blockquote>
  90. *
  91. * These are <code>'&#92;u0030'</code> through
  92. * <code>'&#92;u0039'</code> and <code>'&#92;u0061'</code> through
  93. * <code>'&#92;u007A'</code>. If {@code radix} is
  94. * <var>N</var>, then the first <var>N</var> of these characters
  95. * are used as radix-<var>N</var> digits in the order shown. Thus,
  96. * the digits for hexadecimal (radix 16) are
  97. * {@code 0123456789abcdef}. If uppercase letters are
  98. * desired, the {@link java.lang.String#toUpperCase()} method may
  99. * be called on the result:
  100. *
  101. * <blockquote>
  102. * {@code Integer.toString(n, 16).toUpperCase()}
  103. * </blockquote>
  104. *
  105. * @param i an integer to be converted to a string.
  106. * @param radix the radix to use in the string representation.
  107. * @return a string representation of the argument in the specified radix.
  108. * @see java.lang.Character#MAX_RADIX
  109. * @see java.lang.Character#MIN_RADIX
  110. */
  111. @:native('toString') @:overload public static function _toString(i : Int, radix : Int) : String;
  112. /**
  113. * Returns a string representation of the integer argument as an
  114. * unsigned integer in base&nbsp;16.
  115. *
  116. * <p>The unsigned integer value is the argument plus 2<sup>32</sup>
  117. * if the argument is negative; otherwise, it is equal to the
  118. * argument. This value is converted to a string of ASCII digits
  119. * in hexadecimal (base&nbsp;16) with no extra leading
  120. * {@code 0}s. If the unsigned magnitude is zero, it is
  121. * represented by a single zero character {@code '0'}
  122. * (<code>'&#92;u0030'</code>); otherwise, the first character of
  123. * the representation of the unsigned magnitude will not be the
  124. * zero character. The following characters are used as
  125. * hexadecimal digits:
  126. *
  127. * <blockquote>
  128. * {@code 0123456789abcdef}
  129. * </blockquote>
  130. *
  131. * These are the characters <code>'&#92;u0030'</code> through
  132. * <code>'&#92;u0039'</code> and <code>'&#92;u0061'</code> through
  133. * <code>'&#92;u0066'</code>. If uppercase letters are
  134. * desired, the {@link java.lang.String#toUpperCase()} method may
  135. * be called on the result:
  136. *
  137. * <blockquote>
  138. * {@code Integer.toHexString(n).toUpperCase()}
  139. * </blockquote>
  140. *
  141. * @param i an integer to be converted to a string.
  142. * @return the string representation of the unsigned integer value
  143. * represented by the argument in hexadecimal (base&nbsp;16).
  144. * @since JDK1.0.2
  145. */
  146. @:require(java0) @:overload public static function toHexString(i : Int) : String;
  147. /**
  148. * Returns a string representation of the integer argument as an
  149. * unsigned integer in base&nbsp;8.
  150. *
  151. * <p>The unsigned integer value is the argument plus 2<sup>32</sup>
  152. * if the argument is negative; otherwise, it is equal to the
  153. * argument. This value is converted to a string of ASCII digits
  154. * in octal (base&nbsp;8) with no extra leading {@code 0}s.
  155. *
  156. * <p>If the unsigned magnitude is zero, it is represented by a
  157. * single zero character {@code '0'}
  158. * (<code>'&#92;u0030'</code>); otherwise, the first character of
  159. * the representation of the unsigned magnitude will not be the
  160. * zero character. The following characters are used as octal
  161. * digits:
  162. *
  163. * <blockquote>
  164. * {@code 01234567}
  165. * </blockquote>
  166. *
  167. * These are the characters <code>'&#92;u0030'</code> through
  168. * <code>'&#92;u0037'</code>.
  169. *
  170. * @param i an integer to be converted to a string.
  171. * @return the string representation of the unsigned integer value
  172. * represented by the argument in octal (base&nbsp;8).
  173. * @since JDK1.0.2
  174. */
  175. @:require(java0) @:overload public static function toOctalString(i : Int) : String;
  176. /**
  177. * Returns a string representation of the integer argument as an
  178. * unsigned integer in base&nbsp;2.
  179. *
  180. * <p>The unsigned integer value is the argument plus 2<sup>32</sup>
  181. * if the argument is negative; otherwise it is equal to the
  182. * argument. This value is converted to a string of ASCII digits
  183. * in binary (base&nbsp;2) with no extra leading {@code 0}s.
  184. * If the unsigned magnitude is zero, it is represented by a
  185. * single zero character {@code '0'}
  186. * (<code>'&#92;u0030'</code>); otherwise, the first character of
  187. * the representation of the unsigned magnitude will not be the
  188. * zero character. The characters {@code '0'}
  189. * (<code>'&#92;u0030'</code>) and {@code '1'}
  190. * (<code>'&#92;u0031'</code>) are used as binary digits.
  191. *
  192. * @param i an integer to be converted to a string.
  193. * @return the string representation of the unsigned integer value
  194. * represented by the argument in binary (base&nbsp;2).
  195. * @since JDK1.0.2
  196. */
  197. @:require(java0) @:overload public static function toBinaryString(i : Int) : String;
  198. /**
  199. * Returns a {@code String} object representing the
  200. * specified integer. The argument is converted to signed decimal
  201. * representation and returned as a string, exactly as if the
  202. * argument and radix 10 were given as arguments to the {@link
  203. * #toString(int, int)} method.
  204. *
  205. * @param i an integer to be converted.
  206. * @return a string representation of the argument in base&nbsp;10.
  207. */
  208. @:native('toString') @:overload public static function _toString(i : Int) : String;
  209. /**
  210. * Parses the string argument as a signed integer in the radix
  211. * specified by the second argument. The characters in the string
  212. * must all be digits of the specified radix (as determined by
  213. * whether {@link java.lang.Character#digit(char, int)} returns a
  214. * nonnegative value), except that the first character may be an
  215. * ASCII minus sign {@code '-'} (<code>'&#92;u002D'</code>) to
  216. * indicate a negative value or an ASCII plus sign {@code '+'}
  217. * (<code>'&#92;u002B'</code>) to indicate a positive value. The
  218. * resulting integer value is returned.
  219. *
  220. * <p>An exception of type {@code NumberFormatException} is
  221. * thrown if any of the following situations occurs:
  222. * <ul>
  223. * <li>The first argument is {@code null} or is a string of
  224. * length zero.
  225. *
  226. * <li>The radix is either smaller than
  227. * {@link java.lang.Character#MIN_RADIX} or
  228. * larger than {@link java.lang.Character#MAX_RADIX}.
  229. *
  230. * <li>Any character of the string is not a digit of the specified
  231. * radix, except that the first character may be a minus sign
  232. * {@code '-'} (<code>'&#92;u002D'</code>) or plus sign
  233. * {@code '+'} (<code>'&#92;u002B'</code>) provided that the
  234. * string is longer than length 1.
  235. *
  236. * <li>The value represented by the string is not a value of type
  237. * {@code int}.
  238. * </ul>
  239. *
  240. * <p>Examples:
  241. * <blockquote><pre>
  242. * parseInt("0", 10) returns 0
  243. * parseInt("473", 10) returns 473
  244. * parseInt("+42", 10) returns 42
  245. * parseInt("-0", 10) returns 0
  246. * parseInt("-FF", 16) returns -255
  247. * parseInt("1100110", 2) returns 102
  248. * parseInt("2147483647", 10) returns 2147483647
  249. * parseInt("-2147483648", 10) returns -2147483648
  250. * parseInt("2147483648", 10) throws a NumberFormatException
  251. * parseInt("99", 8) throws a NumberFormatException
  252. * parseInt("Kona", 10) throws a NumberFormatException
  253. * parseInt("Kona", 27) returns 411787
  254. * </pre></blockquote>
  255. *
  256. * @param s the {@code String} containing the integer
  257. * representation to be parsed
  258. * @param radix the radix to be used while parsing {@code s}.
  259. * @return the integer represented by the string argument in the
  260. * specified radix.
  261. * @exception NumberFormatException if the {@code String}
  262. * does not contain a parsable {@code int}.
  263. */
  264. @:overload public static function parseInt(s : String, radix : Int) : Int;
  265. /**
  266. * Parses the string argument as a signed decimal integer. The
  267. * characters in the string must all be decimal digits, except
  268. * that the first character may be an ASCII minus sign {@code '-'}
  269. * (<code>'&#92;u002D'</code>) to indicate a negative value or an
  270. * ASCII plus sign {@code '+'} (<code>'&#92;u002B'</code>) to
  271. * indicate a positive value. The resulting integer value is
  272. * returned, exactly as if the argument and the radix 10 were
  273. * given as arguments to the {@link #parseInt(java.lang.String,
  274. * int)} method.
  275. *
  276. * @param s a {@code String} containing the {@code int}
  277. * representation to be parsed
  278. * @return the integer value represented by the argument in decimal.
  279. * @exception NumberFormatException if the string does not contain a
  280. * parsable integer.
  281. */
  282. @:overload public static function parseInt(s : String) : Int;
  283. /**
  284. * Returns an {@code Integer} object holding the value
  285. * extracted from the specified {@code String} when parsed
  286. * with the radix given by the second argument. The first argument
  287. * is interpreted as representing a signed integer in the radix
  288. * specified by the second argument, exactly as if the arguments
  289. * were given to the {@link #parseInt(java.lang.String, int)}
  290. * method. The result is an {@code Integer} object that
  291. * represents the integer value specified by the string.
  292. *
  293. * <p>In other words, this method returns an {@code Integer}
  294. * object equal to the value of:
  295. *
  296. * <blockquote>
  297. * {@code new Integer(Integer.parseInt(s, radix))}
  298. * </blockquote>
  299. *
  300. * @param s the string to be parsed.
  301. * @param radix the radix to be used in interpreting {@code s}
  302. * @return an {@code Integer} object holding the value
  303. * represented by the string argument in the specified
  304. * radix.
  305. * @exception NumberFormatException if the {@code String}
  306. * does not contain a parsable {@code int}.
  307. */
  308. @:overload public static function valueOf(s : String, radix : Int) : Integer;
  309. /**
  310. * Returns an {@code Integer} object holding the
  311. * value of the specified {@code String}. The argument is
  312. * interpreted as representing a signed decimal integer, exactly
  313. * as if the argument were given to the {@link
  314. * #parseInt(java.lang.String)} method. The result is an
  315. * {@code Integer} object that represents the integer value
  316. * specified by the string.
  317. *
  318. * <p>In other words, this method returns an {@code Integer}
  319. * object equal to the value of:
  320. *
  321. * <blockquote>
  322. * {@code new Integer(Integer.parseInt(s))}
  323. * </blockquote>
  324. *
  325. * @param s the string to be parsed.
  326. * @return an {@code Integer} object holding the value
  327. * represented by the string argument.
  328. * @exception NumberFormatException if the string cannot be parsed
  329. * as an integer.
  330. */
  331. @:overload public static function valueOf(s : String) : Integer;
  332. /**
  333. * Returns an {@code Integer} instance representing the specified
  334. * {@code int} value. If a new {@code Integer} instance is not
  335. * required, this method should generally be used in preference to
  336. * the constructor {@link #Integer(int)}, as this method is likely
  337. * to yield significantly better space and time performance by
  338. * caching frequently requested values.
  339. *
  340. * This method will always cache values in the range -128 to 127,
  341. * inclusive, and may cache other values outside of this range.
  342. *
  343. * @param i an {@code int} value.
  344. * @return an {@code Integer} instance representing {@code i}.
  345. * @since 1.5
  346. */
  347. @:require(java5) @:overload public static function valueOf(i : Int) : Integer;
  348. /**
  349. * Constructs a newly allocated {@code Integer} object that
  350. * represents the specified {@code int} value.
  351. *
  352. * @param value the value to be represented by the
  353. * {@code Integer} object.
  354. */
  355. @:overload public function new(value : Int) : Void;
  356. /**
  357. * Constructs a newly allocated {@code Integer} object that
  358. * represents the {@code int} value indicated by the
  359. * {@code String} parameter. The string is converted to an
  360. * {@code int} value in exactly the manner used by the
  361. * {@code parseInt} method for radix 10.
  362. *
  363. * @param s the {@code String} to be converted to an
  364. * {@code Integer}.
  365. * @exception NumberFormatException if the {@code String} does not
  366. * contain a parsable integer.
  367. * @see java.lang.Integer#parseInt(java.lang.String, int)
  368. */
  369. @:overload public function new(s : String) : Void;
  370. /**
  371. * Returns the value of this {@code Integer} as a
  372. * {@code byte}.
  373. */
  374. @:overload override public function byteValue() : java.StdTypes.Int8;
  375. /**
  376. * Returns the value of this {@code Integer} as a
  377. * {@code short}.
  378. */
  379. @:overload override public function shortValue() : java.StdTypes.Int16;
  380. /**
  381. * Returns the value of this {@code Integer} as an
  382. * {@code int}.
  383. */
  384. @:overload override public function intValue() : Int;
  385. /**
  386. * Returns the value of this {@code Integer} as a
  387. * {@code long}.
  388. */
  389. @:overload override public function longValue() : haxe.Int64;
  390. /**
  391. * Returns the value of this {@code Integer} as a
  392. * {@code float}.
  393. */
  394. @:overload override public function floatValue() : Single;
  395. /**
  396. * Returns the value of this {@code Integer} as a
  397. * {@code double}.
  398. */
  399. @:overload override public function doubleValue() : Float;
  400. /**
  401. * Returns a {@code String} object representing this
  402. * {@code Integer}'s value. The value is converted to signed
  403. * decimal representation and returned as a string, exactly as if
  404. * the integer value were given as an argument to the {@link
  405. * java.lang.Integer#toString(int)} method.
  406. *
  407. * @return a string representation of the value of this object in
  408. * base&nbsp;10.
  409. */
  410. @:overload public function toString() : String;
  411. /**
  412. * Returns a hash code for this {@code Integer}.
  413. *
  414. * @return a hash code value for this object, equal to the
  415. * primitive {@code int} value represented by this
  416. * {@code Integer} object.
  417. */
  418. @:overload public function hashCode() : Int;
  419. /**
  420. * Compares this object to the specified object. The result is
  421. * {@code true} if and only if the argument is not
  422. * {@code null} and is an {@code Integer} object that
  423. * contains the same {@code int} value as this object.
  424. *
  425. * @param obj the object to compare with.
  426. * @return {@code true} if the objects are the same;
  427. * {@code false} otherwise.
  428. */
  429. @:overload public function equals(obj : Dynamic) : Bool;
  430. /**
  431. * Determines the integer value of the system property with the
  432. * specified name.
  433. *
  434. * <p>The first argument is treated as the name of a system property.
  435. * System properties are accessible through the
  436. * {@link java.lang.System#getProperty(java.lang.String)} method. The
  437. * string value of this property is then interpreted as an integer
  438. * value and an {@code Integer} object representing this value is
  439. * returned. Details of possible numeric formats can be found with
  440. * the definition of {@code getProperty}.
  441. *
  442. * <p>If there is no property with the specified name, if the specified name
  443. * is empty or {@code null}, or if the property does not have
  444. * the correct numeric format, then {@code null} is returned.
  445. *
  446. * <p>In other words, this method returns an {@code Integer}
  447. * object equal to the value of:
  448. *
  449. * <blockquote>
  450. * {@code getInteger(nm, null)}
  451. * </blockquote>
  452. *
  453. * @param nm property name.
  454. * @return the {@code Integer} value of the property.
  455. * @see java.lang.System#getProperty(java.lang.String)
  456. * @see java.lang.System#getProperty(java.lang.String, java.lang.String)
  457. */
  458. @:overload public static function getInteger(nm : String) : Integer;
  459. /**
  460. * Determines the integer value of the system property with the
  461. * specified name.
  462. *
  463. * <p>The first argument is treated as the name of a system property.
  464. * System properties are accessible through the {@link
  465. * java.lang.System#getProperty(java.lang.String)} method. The
  466. * string value of this property is then interpreted as an integer
  467. * value and an {@code Integer} object representing this value is
  468. * returned. Details of possible numeric formats can be found with
  469. * the definition of {@code getProperty}.
  470. *
  471. * <p>The second argument is the default value. An {@code Integer} object
  472. * that represents the value of the second argument is returned if there
  473. * is no property of the specified name, if the property does not have
  474. * the correct numeric format, or if the specified name is empty or
  475. * {@code null}.
  476. *
  477. * <p>In other words, this method returns an {@code Integer} object
  478. * equal to the value of:
  479. *
  480. * <blockquote>
  481. * {@code getInteger(nm, new Integer(val))}
  482. * </blockquote>
  483. *
  484. * but in practice it may be implemented in a manner such as:
  485. *
  486. * <blockquote><pre>
  487. * Integer result = getInteger(nm, null);
  488. * return (result == null) ? new Integer(val) : result;
  489. * </pre></blockquote>
  490. *
  491. * to avoid the unnecessary allocation of an {@code Integer}
  492. * object when the default value is not needed.
  493. *
  494. * @param nm property name.
  495. * @param val default value.
  496. * @return the {@code Integer} value of the property.
  497. * @see java.lang.System#getProperty(java.lang.String)
  498. * @see java.lang.System#getProperty(java.lang.String, java.lang.String)
  499. */
  500. @:overload public static function getInteger(nm : String, val : Int) : Integer;
  501. /**
  502. * Returns the integer value of the system property with the
  503. * specified name. The first argument is treated as the name of a
  504. * system property. System properties are accessible through the
  505. * {@link java.lang.System#getProperty(java.lang.String)} method.
  506. * The string value of this property is then interpreted as an
  507. * integer value, as per the {@code Integer.decode} method,
  508. * and an {@code Integer} object representing this value is
  509. * returned.
  510. *
  511. * <ul><li>If the property value begins with the two ASCII characters
  512. * {@code 0x} or the ASCII character {@code #}, not
  513. * followed by a minus sign, then the rest of it is parsed as a
  514. * hexadecimal integer exactly as by the method
  515. * {@link #valueOf(java.lang.String, int)} with radix 16.
  516. * <li>If the property value begins with the ASCII character
  517. * {@code 0} followed by another character, it is parsed as an
  518. * octal integer exactly as by the method
  519. * {@link #valueOf(java.lang.String, int)} with radix 8.
  520. * <li>Otherwise, the property value is parsed as a decimal integer
  521. * exactly as by the method {@link #valueOf(java.lang.String, int)}
  522. * with radix 10.
  523. * </ul>
  524. *
  525. * <p>The second argument is the default value. The default value is
  526. * returned if there is no property of the specified name, if the
  527. * property does not have the correct numeric format, or if the
  528. * specified name is empty or {@code null}.
  529. *
  530. * @param nm property name.
  531. * @param val default value.
  532. * @return the {@code Integer} value of the property.
  533. * @see java.lang.System#getProperty(java.lang.String)
  534. * @see java.lang.System#getProperty(java.lang.String, java.lang.String)
  535. * @see java.lang.Integer#decode
  536. */
  537. @:overload public static function getInteger(nm : String, val : Integer) : Integer;
  538. /**
  539. * Decodes a {@code String} into an {@code Integer}.
  540. * Accepts decimal, hexadecimal, and octal numbers given
  541. * by the following grammar:
  542. *
  543. * <blockquote>
  544. * <dl>
  545. * <dt><i>DecodableString:</i>
  546. * <dd><i>Sign<sub>opt</sub> DecimalNumeral</i>
  547. * <dd><i>Sign<sub>opt</sub></i> {@code 0x} <i>HexDigits</i>
  548. * <dd><i>Sign<sub>opt</sub></i> {@code 0X} <i>HexDigits</i>
  549. * <dd><i>Sign<sub>opt</sub></i> {@code #} <i>HexDigits</i>
  550. * <dd><i>Sign<sub>opt</sub></i> {@code 0} <i>OctalDigits</i>
  551. * <p>
  552. * <dt><i>Sign:</i>
  553. * <dd>{@code -}
  554. * <dd>{@code +}
  555. * </dl>
  556. * </blockquote>
  557. *
  558. * <i>DecimalNumeral</i>, <i>HexDigits</i>, and <i>OctalDigits</i>
  559. * are as defined in section 3.10.1 of
  560. * <cite>The Java&trade; Language Specification</cite>,
  561. * except that underscores are not accepted between digits.
  562. *
  563. * <p>The sequence of characters following an optional
  564. * sign and/or radix specifier ("{@code 0x}", "{@code 0X}",
  565. * "{@code #}", or leading zero) is parsed as by the {@code
  566. * Integer.parseInt} method with the indicated radix (10, 16, or
  567. * 8). This sequence of characters must represent a positive
  568. * value or a {@link NumberFormatException} will be thrown. The
  569. * result is negated if first character of the specified {@code
  570. * String} is the minus sign. No whitespace characters are
  571. * permitted in the {@code String}.
  572. *
  573. * @param nm the {@code String} to decode.
  574. * @return an {@code Integer} object holding the {@code int}
  575. * value represented by {@code nm}
  576. * @exception NumberFormatException if the {@code String} does not
  577. * contain a parsable integer.
  578. * @see java.lang.Integer#parseInt(java.lang.String, int)
  579. */
  580. @:overload public static function decode(nm : String) : Integer;
  581. /**
  582. * Compares two {@code Integer} objects numerically.
  583. *
  584. * @param anotherInteger the {@code Integer} to be compared.
  585. * @return the value {@code 0} if this {@code Integer} is
  586. * equal to the argument {@code Integer}; a value less than
  587. * {@code 0} if this {@code Integer} is numerically less
  588. * than the argument {@code Integer}; and a value greater
  589. * than {@code 0} if this {@code Integer} is numerically
  590. * greater than the argument {@code Integer} (signed
  591. * comparison).
  592. * @since 1.2
  593. */
  594. @:require(java2) @:overload public function compareTo(anotherInteger : Integer) : Int;
  595. /**
  596. * Compares two {@code int} values numerically.
  597. * The value returned is identical to what would be returned by:
  598. * <pre>
  599. * Integer.valueOf(x).compareTo(Integer.valueOf(y))
  600. * </pre>
  601. *
  602. * @param x the first {@code int} to compare
  603. * @param y the second {@code int} to compare
  604. * @return the value {@code 0} if {@code x == y};
  605. * a value less than {@code 0} if {@code x < y}; and
  606. * a value greater than {@code 0} if {@code x > y}
  607. * @since 1.7
  608. */
  609. @:require(java7) @:overload public static function compare(x : Int, y : Int) : Int;
  610. /**
  611. * The number of bits used to represent an {@code int} value in two's
  612. * complement binary form.
  613. *
  614. * @since 1.5
  615. */
  616. @:require(java5) public static var SIZE(default, null) : Int;
  617. /**
  618. * Returns an {@code int} value with at most a single one-bit, in the
  619. * position of the highest-order ("leftmost") one-bit in the specified
  620. * {@code int} value. Returns zero if the specified value has no
  621. * one-bits in its two's complement binary representation, that is, if it
  622. * is equal to zero.
  623. *
  624. * @return an {@code int} value with a single one-bit, in the position
  625. * of the highest-order one-bit in the specified value, or zero if
  626. * the specified value is itself equal to zero.
  627. * @since 1.5
  628. */
  629. @:require(java5) @:overload public static function highestOneBit(i : Int) : Int;
  630. /**
  631. * Returns an {@code int} value with at most a single one-bit, in the
  632. * position of the lowest-order ("rightmost") one-bit in the specified
  633. * {@code int} value. Returns zero if the specified value has no
  634. * one-bits in its two's complement binary representation, that is, if it
  635. * is equal to zero.
  636. *
  637. * @return an {@code int} value with a single one-bit, in the position
  638. * of the lowest-order one-bit in the specified value, or zero if
  639. * the specified value is itself equal to zero.
  640. * @since 1.5
  641. */
  642. @:require(java5) @:overload public static function lowestOneBit(i : Int) : Int;
  643. /**
  644. * Returns the number of zero bits preceding the highest-order
  645. * ("leftmost") one-bit in the two's complement binary representation
  646. * of the specified {@code int} value. Returns 32 if the
  647. * specified value has no one-bits in its two's complement representation,
  648. * in other words if it is equal to zero.
  649. *
  650. * <p>Note that this method is closely related to the logarithm base 2.
  651. * For all positive {@code int} values x:
  652. * <ul>
  653. * <li>floor(log<sub>2</sub>(x)) = {@code 31 - numberOfLeadingZeros(x)}
  654. * <li>ceil(log<sub>2</sub>(x)) = {@code 32 - numberOfLeadingZeros(x - 1)}
  655. * </ul>
  656. *
  657. * @return the number of zero bits preceding the highest-order
  658. * ("leftmost") one-bit in the two's complement binary representation
  659. * of the specified {@code int} value, or 32 if the value
  660. * is equal to zero.
  661. * @since 1.5
  662. */
  663. @:require(java5) @:overload public static function numberOfLeadingZeros(i : Int) : Int;
  664. /**
  665. * Returns the number of zero bits following the lowest-order ("rightmost")
  666. * one-bit in the two's complement binary representation of the specified
  667. * {@code int} value. Returns 32 if the specified value has no
  668. * one-bits in its two's complement representation, in other words if it is
  669. * equal to zero.
  670. *
  671. * @return the number of zero bits following the lowest-order ("rightmost")
  672. * one-bit in the two's complement binary representation of the
  673. * specified {@code int} value, or 32 if the value is equal
  674. * to zero.
  675. * @since 1.5
  676. */
  677. @:require(java5) @:overload public static function numberOfTrailingZeros(i : Int) : Int;
  678. /**
  679. * Returns the number of one-bits in the two's complement binary
  680. * representation of the specified {@code int} value. This function is
  681. * sometimes referred to as the <i>population count</i>.
  682. *
  683. * @return the number of one-bits in the two's complement binary
  684. * representation of the specified {@code int} value.
  685. * @since 1.5
  686. */
  687. @:require(java5) @:overload public static function bitCount(i : Int) : Int;
  688. /**
  689. * Returns the value obtained by rotating the two's complement binary
  690. * representation of the specified {@code int} value left by the
  691. * specified number of bits. (Bits shifted out of the left hand, or
  692. * high-order, side reenter on the right, or low-order.)
  693. *
  694. * <p>Note that left rotation with a negative distance is equivalent to
  695. * right rotation: {@code rotateLeft(val, -distance) == rotateRight(val,
  696. * distance)}. Note also that rotation by any multiple of 32 is a
  697. * no-op, so all but the last five bits of the rotation distance can be
  698. * ignored, even if the distance is negative: {@code rotateLeft(val,
  699. * distance) == rotateLeft(val, distance & 0x1F)}.
  700. *
  701. * @return the value obtained by rotating the two's complement binary
  702. * representation of the specified {@code int} value left by the
  703. * specified number of bits.
  704. * @since 1.5
  705. */
  706. @:require(java5) @:overload public static function rotateLeft(i : Int, distance : Int) : Int;
  707. /**
  708. * Returns the value obtained by rotating the two's complement binary
  709. * representation of the specified {@code int} value right by the
  710. * specified number of bits. (Bits shifted out of the right hand, or
  711. * low-order, side reenter on the left, or high-order.)
  712. *
  713. * <p>Note that right rotation with a negative distance is equivalent to
  714. * left rotation: {@code rotateRight(val, -distance) == rotateLeft(val,
  715. * distance)}. Note also that rotation by any multiple of 32 is a
  716. * no-op, so all but the last five bits of the rotation distance can be
  717. * ignored, even if the distance is negative: {@code rotateRight(val,
  718. * distance) == rotateRight(val, distance & 0x1F)}.
  719. *
  720. * @return the value obtained by rotating the two's complement binary
  721. * representation of the specified {@code int} value right by the
  722. * specified number of bits.
  723. * @since 1.5
  724. */
  725. @:require(java5) @:overload public static function rotateRight(i : Int, distance : Int) : Int;
  726. /**
  727. * Returns the value obtained by reversing the order of the bits in the
  728. * two's complement binary representation of the specified {@code int}
  729. * value.
  730. *
  731. * @return the value obtained by reversing order of the bits in the
  732. * specified {@code int} value.
  733. * @since 1.5
  734. */
  735. @:require(java5) @:overload public static function reverse(i : Int) : Int;
  736. /**
  737. * Returns the signum function of the specified {@code int} value. (The
  738. * return value is -1 if the specified value is negative; 0 if the
  739. * specified value is zero; and 1 if the specified value is positive.)
  740. *
  741. * @return the signum function of the specified {@code int} value.
  742. * @since 1.5
  743. */
  744. @:require(java5) @:overload public static function signum(i : Int) : Int;
  745. /**
  746. * Returns the value obtained by reversing the order of the bytes in the
  747. * two's complement representation of the specified {@code int} value.
  748. *
  749. * @return the value obtained by reversing the bytes in the specified
  750. * {@code int} value.
  751. * @since 1.5
  752. */
  753. @:require(java5) @:overload public static function reverseBytes(i : Int) : Int;
  754. }