Enumset Abstract class Source parsing

Source: Internet
Author: User
Tags addall

Enumset
Collection class specifically designed for enumeration classes, all elements must be enum types
The set elements of the Enumset are ordered and stored internally in the form of a bit vector, thus occupying little memory and high efficiency
Do not allow null elements to be added
Source

 PackageJava.util;ImportSun.misc.sharedsecrets;publicAbstract  class Enumset<e extends Enum<e>>  Extends abstractset<E>Implements Cloneable, java.io.serializable{/** * Element type * /    FinalClass<e> ElementType;/** * Through array storage elements */    FinalEnum[] Universe;PrivateStatic enum[] Zero_length_enum_array =Newenum[0]; Enumset (Class<e>elementtype, enum[] universe) { This. ElementType = ElementType; This. Universe = Universe; }/** * Creates an empty enum set and formulates its element type * @param ElementType The class object of the element type for this en UM * Set * @throws nullpointerexception if <tt>elementType</tt> is null * /public static <eextendsEnum<e>> enumset<e> noneof (class<e> elementtype) {enum[] universe = Getuniverse (ElementType);if(Universe = =NULL)Throw NewClassCastException (ElementType +"not an enum");if(Universe.length <= -)return NewRegularenumset<> (ElementType, Universe);Else            return NewJumboenumset<> (ElementType, Universe); }/** * Creates an enumeration containing all elements in the specified element type set * * @param ElementType The class object of the element type for T His enum * set * @throws nullpointerexception if <tt>elementType</tt> is null * /public static <eextendsEnum<e>> enumset<e> AllOf (class<e> elementtype) {enumset<e> result = NoneOf (elementType        ); Result.addall ();returnResult }/** * Adds All of the elements from the appropriate enum type to this enum * set, which are empty prior to the     Call. */    Abstractvoid AddAll ();/** * Creates an enumeration that sets the same element type as the specified enumeration set * * @param s The enum set from which to initialize this enum set * @throws nullpointerexception if <tt>s</tt> is null * /public static <eextendsEnum<e>> enumset<e> copyOf (enumset<e> s) {returnS.clone (); }/** * Creates an enumeration set initialized from the specified collection, initially containing the same elements * @param c the collection from which to initialize this enum set * @throws illegalargumentexception If <tt>c</tt> is not a * <tt>EnumSet</tt> in Stance and contains no elements * @throws nullpointerexception if <tt>c</tt> is null * /public static <eextendsEnum<e>> enumset<e> copyOf (collection<e> c) {if(c instanceof Enumset) {return((enumset<e>) c). Clone (); }Else{if(C.isempty ())Throw NewIllegalArgumentException ("Collection is empty");            iterator<e> i = C.iterator ();            E first = I.next (); enumset<e> result = Enumset.of (first); while(I.hasnext ()) Result.add (I.next ());returnResult }    }/** * Creates an enumeration set whose elements are the same as S * @param s The enum set from whose complement to initialize this enum set * @throws nullpointerexception if <tt>s</tt> is null * /public static <eextendsEnum<e>> enumset<e> Complementof (enumset<e> s) {enumset<e> result = CopyOf (s); Result.complement ();returnResult }/** * 1 Elements Enumeration Collection * * @param e The element that this set is to contain initially * @throws /c2> NullPointerException If <tt>e</tt> is null * @return An enum set initially containing the SP ecified element * /public static <eextendsEnum<e>> enumset<e> of (e e) {enumset<e> result = noneof (E.getdeclaringclass ()); Result.add (e);returnResult }/** * 2 Elements Enumeration Collection * * @param E1 An element the This set was to contain initially * @param 
       E2 Another element, the this set was to contain initially * @throws nullpointerexception if any parameters Is null * @return An enum set initially containing the specified elements * /public static <eextendsEnum<e>> enumset<e> of (e E1, e E2) {enumset<e> result = noneof (E1.getdeclaringclass ());        Result.add (E1); Result.add (E2);returnResult }/** * 3 Elements Enumeration Collection * * @param E1 An element the This set was to contain initially * @param 
       E2 Another element the This set is to contain initially * @param E3 another element Contain initially * @throws nullpointerexception If any parameters is null * @return an enum SE T initially containing the specified elements * /public static <eextendsEnum<e>> enumset<e> of (e E1, e E2, E E3) {enumset<e> result = noneof (E1.getdeclaringclass ());        Result.add (E1);        Result.add (E2); Result.add (E3);returnResult }/** * 4 Elements Enumeration set * @param E1 An element the This set is to contain initially * @param E2 Another element, the this set was to contain initially * @param E3 another element N initially * @param e4 Another element, the this set are to contain initially * @throws nullpoin     Terexception If any parameters is null * @return An enum set initially containing the specified elements */public static <eextendsEnum<e>> enumset<e> of (e E1, e E2, E E3, E e4) {enumset<e> result = noneof (E1.GETDECLARINGCLA        SS ());        Result.add (E1);        Result.add (E2);        Result.add (E3); Result.add (E4);returnResult }/** * 5 Elements Enumeration Collection * * @param E1 An element the This set was to contain initially * @param 
       E2 Another element the This set is to contain initially * @param E3 another element Contain initially * @param e4 Another element, this set are to contain initially * @param e5 Another element, the this set was to contain initially * @throws nullpointerexception If any parameters be Nu ll * @return An enum set initially containing the specified elements * /public static <eextendsEnum<e>> enumset<e> of (e E1, e E2, E E3, E E4, E e5)        {enumset<e> result = noneof (E1.getdeclaringclass ());        Result.add (E1);        Result.add (E2);        Result.add (E3);        Result.add (E4); Result.add (E5);returnResult }/** * N Elements Enumeration Collection * * @param First an element, the set is to contain initially * @param Rest the remaining elements the set is to contain initially * @throws nullpointerexception if any of th E specified elements is null, * or if <tt>rest</tt> was null * @return an enum set Initia Lly containing the specified elements * /    @SafeVarargspublic static <eextendsEnum<e>> enumset<e> of (e First, E ... rest) {enumset<e> result = noneof (First.getdeclaringclas        s ()); Result.add (first); for(e e:rest) Result.add (e);returnResult }/** * Enumeration set of elements within a range * @param from the first element in the range * @param to the Las t element in the range * @throws nullpointerexception If {@code by} or {@code to} is nul L * @throws illegalargumentexception If {@code From.compareto (To) > 0} * @return A Enum set initially containing all of the elements in the "range defined by the" specified endpoints * * public static <eextendsEnum<e>> enumset<e> Range (e from, E to) {if(From.compareto (To) >0)Throw NewIllegalArgumentException (from +">"+ to);        enumset<e> result = noneof (From.getdeclaringclass ()); Result.addrange (from, to);returnResult }/** * Adds The specified range to this enum set, which are empty prior * to the call. */    Abstractvoid AddRange (E from, E to);/** * Returns A copy of this set. * * @return A copy of this set */Public enumset<e> Clone () {Try{return(enumset<e>)Super. Clone (); }Catch(Clonenotsupportedexception e) {Throw NewAssertionerror (e); }    }/** * Complements the contents of this enum set. */    Abstractvoid complement ();/** * Throws An exception if e are not a of the correct type for this enum set. */    Finalvoid Typecheck (e e) {Class eClass = E.getclass ();if(EClass! = ElementType && eclass.getsuperclass ()! = ElementType)Throw NewClassCastException (EClass +" != "+ ElementType); }/** * Returns all of the values comprising E.     * The result is uncloned, cached, and gkfx by all callers. */    PrivateStatic <eextendsEnum<e>> e[] Getuniverse (class<e> elementtype) {returnSharedsecrets.getjavalangaccess (). getenumconstantsshared (ElementType); }/** * This class was used to serialize all enumset instances, regardless of * implementation type.  It captures their "logical contents" and they * is reconstructed using public static factories. This was necessary * to ensure that the existence of a particular implementation type was * an implementation detail     . * * @serial include * *    PrivateStatic class serializationproxy <e extends Enum<e>> Implements Java.io.Serializable {/** * The element type of this enum set. * * @serial  * *        Private FinalClass<e> ElementType;/** * The elements contained in this enum set. * * @serial  * *        Private FinalEnum[] elements;            Serializationproxy (enumset<e> set) {ElementType = Set.elementtype;        elements = Set.toarray (Zero_length_enum_array); }PrivateObject Readresolve () {enumset<e> result = enumset.noneof (ElementType); for(Enum e:elements) Result.add ((e) e);returnResult }PrivateStaticFinalLong Serialversionuid =362491234563181265L } Object Writereplace () {return NewSerializationproxy<> ( This); }//ReadObject method for the serialization proxy pattern    //See effective Java, Second Ed., Item.    Privatevoid ReadObject (Java.io.ObjectInputStream stream)throwsjava.io.InvalidObjectException {Throw NewJava.io.InvalidObjectException ("Proxy Required"); }}

Enumset Abstract class Source parsing

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.