java enum type practice

Notice type enumeration type

public  enum BulletinsType { 
    DELAY_BULLETINS ( "Extension bulletin",. 7 ), 
    FLOWMARK_BULLETINS ( "bids announcement",. 8 ), 
    RUNOFF_BULLETINS ( "annulment bulletin", 10 ), 
    PREQUALIFICATION_BULLETINS ( "pre-qualification announcement", 2 ), 
    CLEAR_BULLETINS ( "Clarification announcement ",. 3 ), 
    FRUIT_BULLETINS ( " successful results announcement ",. 4 ), 
    CHANGE_BULLETINS ( " change announcement ",. 5 ), 
    BEFOREHAND_BULLETINS ( " pre-bid announcement ",. 6 ), 
    EVALUATION_BULLETINS ( " evaluation report ",. 9 );
     Private String typeName;  
    private int index;
    BulletinsType (String typeName, int index) {  
         the this .typeName = typeName;  
         the this .index = index;   
    }   
    / **  
     * index according to the type of announcement, enumerate instances return type. 
     * @Param typeName type name 
      * /   
    public  static BulletinsType fromIndex ( int index) {  
         for (BulletinsType type: BulletinsType.values ()) {  
             IF (type.getIndex () == index) {  
                 return type;   
            }   
        }   
        return  null ;  
    }      
    / **  
     * The type name, return type enumerate instances. 
     * @Param typeName type name 
      * /   
    public  static BulletinsType fromTypeName (String typeName) {  
         for (BulletinsType type: BulletinsType.values ()) {  
             IF (. Type.getTypeName () the equals (typeName)) {  
                 return type;   
            }   
        }   
        return  null ;   
    }   
    public String the getTypeName () {  
         return  the this .typeName;   
    }       
    public  int getIndex () {  
        return this.index;  
    }  

 

// this code can be obtained by the corresponding enum type Key 
BulletinsType bulletinsType = BulletinsType.fromIndex (bulletins.getCodeType ());

 Notice type are fixed, service systems will be able to get the type name by codeType directly from the enumeration in the class

Guess you like

Origin www.cnblogs.com/jkwll/p/11375262.html