Java enumeration class usage instances

  • 2020-04-01 03:52:55
  • OfStack

This article illustrates the use of Java enumeration classes. Share with you for your reference. The details are as follows:


package com.school.stereotype; 
 
public enum EventStatus { 
    
  DRAFT("DRAFT", " Not release "), 
   
  PUBLISHED("PUBLISHED", " The published "); 
   
  private String value; 
   
  private String text; 
   
  private EventStatus(String status, String desc) { 
    value = status; 
    text = desc; 
  } 
   
  public String getValue() { 
    return value; 
  } 
   
  public String getText() { 
    return text; 
  } 
   
  public static EventStatus getInstance(String status) { 
    EventStatus[] allStatus = EventStatus.values(); 
    for (EventStatus ws : allStatus) { 
      if (ws.getValue().equalsIgnoreCase(status)) { 
        return ws; 
      } 
    } 
    throw new IllegalArgumentException("status The value is invalid and there is no enumeration object that conforms to the course state "); 
  } 
}

I hope this article has been helpful to your Java programming.


Related articles: