Enum.hx 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. package java.lang;
  2. /*
  3. * Copyright (c) 2003, 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. * This is the common base class of all Java language enumeration types.
  28. *
  29. * More information about enums, including descriptions of the
  30. * implicitly declared methods synthesized by the compiler, can be
  31. * found in section 8.9 of
  32. * <cite>The Java&trade; Language Specification</cite>.
  33. *
  34. * <p> Note that when using an enumeration type as the type of a set
  35. * or as the type of the keys in a map, specialized and efficient
  36. * {@linkplain java.util.EnumSet set} and {@linkplain
  37. * java.util.EnumMap map} implementations are available.
  38. *
  39. * @param <E> The enum type subclass
  40. * @author Josh Bloch
  41. * @author Neal Gafter
  42. * @see Class#getEnumConstants()
  43. * @see java.util.EnumSet
  44. * @see java.util.EnumMap
  45. * @since 1.5
  46. */
  47. @:require(java5) extern class Enum<E> implements java.lang.Comparable<E> implements java.io.Serializable
  48. {
  49. /**
  50. * Returns the name of this enum constant, exactly as declared in its
  51. * enum declaration.
  52. *
  53. * <b>Most programmers should use the {@link #toString} method in
  54. * preference to this one, as the toString method may return
  55. * a more user-friendly name.</b> This method is designed primarily for
  56. * use in specialized situations where correctness depends on getting the
  57. * exact name, which will not vary from release to release.
  58. *
  59. * @return the name of this enum constant
  60. */
  61. @:overload @:final public function name() : String;
  62. /**
  63. * Returns the ordinal of this enumeration constant (its position
  64. * in its enum declaration, where the initial constant is assigned
  65. * an ordinal of zero).
  66. *
  67. * Most programmers will have no use for this method. It is
  68. * designed for use by sophisticated enum-based data structures, such
  69. * as {@link java.util.EnumSet} and {@link java.util.EnumMap}.
  70. *
  71. * @return the ordinal of this enumeration constant
  72. */
  73. @:overload @:final public function ordinal() : Int;
  74. /**
  75. * Sole constructor. Programmers cannot invoke this constructor.
  76. * It is for use by code emitted by the compiler in response to
  77. * enum type declarations.
  78. *
  79. * @param name - The name of this enum constant, which is the identifier
  80. * used to declare it.
  81. * @param ordinal - The ordinal of this enumeration constant (its position
  82. * in the enum declaration, where the initial constant is assigned
  83. * an ordinal of zero).
  84. */
  85. @:overload private function new(name : String, ordinal : Int) : Void;
  86. /**
  87. * Returns the name of this enum constant, as contained in the
  88. * declaration. This method may be overridden, though it typically
  89. * isn't necessary or desirable. An enum type should override this
  90. * method when a more "programmer-friendly" string form exists.
  91. *
  92. * @return the name of this enum constant
  93. */
  94. @:overload public function toString() : String;
  95. /**
  96. * Returns true if the specified object is equal to this
  97. * enum constant.
  98. *
  99. * @param other the object to be compared for equality with this object.
  100. * @return true if the specified object is equal to this
  101. * enum constant.
  102. */
  103. @:overload @:final public function equals(other : Dynamic) : Bool;
  104. /**
  105. * Returns a hash code for this enum constant.
  106. *
  107. * @return a hash code for this enum constant.
  108. */
  109. @:overload @:final public function hashCode() : Int;
  110. /**
  111. * Throws CloneNotSupportedException. This guarantees that enums
  112. * are never cloned, which is necessary to preserve their "singleton"
  113. * status.
  114. *
  115. * @return (never returns)
  116. */
  117. @:overload @:final private function clone() : Dynamic;
  118. /**
  119. * Compares this enum with the specified object for order. Returns a
  120. * negative integer, zero, or a positive integer as this object is less
  121. * than, equal to, or greater than the specified object.
  122. *
  123. * Enum constants are only comparable to other enum constants of the
  124. * same enum type. The natural order implemented by this
  125. * method is the order in which the constants are declared.
  126. */
  127. @:overload @:final public function compareTo(o : E) : Int;
  128. /**
  129. * Returns the Class object corresponding to this enum constant's
  130. * enum type. Two enum constants e1 and e2 are of the
  131. * same enum type if and only if
  132. * e1.getDeclaringClass() == e2.getDeclaringClass().
  133. * (The value returned by this method may differ from the one returned
  134. * by the {@link Object#getClass} method for enum constants with
  135. * constant-specific class bodies.)
  136. *
  137. * @return the Class object corresponding to this enum constant's
  138. * enum type
  139. */
  140. @:overload @:final public function getDeclaringClass() : Class<E>;
  141. /**
  142. * Returns the enum constant of the specified enum type with the
  143. * specified name. The name must match exactly an identifier used
  144. * to declare an enum constant in this type. (Extraneous whitespace
  145. * characters are not permitted.)
  146. *
  147. * <p>Note that for a particular enum type {@code T}, the
  148. * implicitly declared {@code public static T valueOf(String)}
  149. * method on that enum may be used instead of this method to map
  150. * from a name to the corresponding enum constant. All the
  151. * constants of an enum type can be obtained by calling the
  152. * implicit {@code public static T[] values()} method of that
  153. * type.
  154. *
  155. * @param <T> The enum type whose constant is to be returned
  156. * @param enumType the {@code Class} object of the enum type from which
  157. * to return a constant
  158. * @param name the name of the constant to return
  159. * @return the enum constant of the specified enum type with the
  160. * specified name
  161. * @throws IllegalArgumentException if the specified enum type has
  162. * no constant with the specified name, or the specified
  163. * class object does not represent an enum type
  164. * @throws NullPointerException if {@code enumType} or {@code name}
  165. * is null
  166. * @since 1.5
  167. */
  168. @:require(java5) @:overload public static function valueOf<T : Enum<T>>(enumType : Class<T>, name : String) : T;
  169. /**
  170. * enum classes cannot have finalize methods.
  171. */
  172. @:overload @:final private function finalize() : Void;
  173. }