public enum Month {
// ===================================================================
// {[> Identifiers
// ===============
JANUARY(1, "January"),
FEBRUARY(2, "February"),
MARCH(3, "March"),
APRIL(4, "April"),
MAY(5, "May"),
JUNE(6, "June"),
JULY(7, "July"),
AUGUST(8, "August"),
SEPTEMBER(9, "Septembe"),
OCTOBER(10, "October"),
NOVEMBER(11, "November"),
DECEMBER(12, "December");
// ===================================================================
// {[> Attributes
// ==============
private final String name;
private final int order;
// ===================================================================
// {[> Initializers and Constructors
// =================================
Month(int order, String name) {
this.name = name;
this.order = order;
}
// ===================================================================
// {[> Public Static Methods
// =========================
public static Month byName(String name) {
for (Month m : Month.values()) {
if (m.name.equalsIgnoreCase(name)) {
return m;
}
}
throw new NoSuchElementException("No month found for name: " + name);
}
public static Month byOrder(int order) {
for (Month m : Month.values()) {
if (m.order == order) {
return m;
}
}
throw new NoSuchElementException("No month found for order: " + order);
}
// ===================================================================
// {[> Public Methods
// ==================
public String getName() {
return name;
}
public int getOrder() {
return order;
}
}