Added an enum for months

This commit is contained in:
Lennart Hensler committed 2015-03-04 22:48:44 +01:00
1 parent 7f864b05b2
commit dc6d604d48
1 file changed
+34
@@ -0,0 +1,34 @@
package com.sap.sse.datamining.shared;
public enum Month {
January, February, March, April, May, June, Juli, August, September, October, November, December;
/**
* Private cache of all the constants.
*/
private static final Month[] VALUES = Month.values();
/**
* @param month the month as <code>int</code> to represent, from 1 (January) to 12 (December)
* @return the month, not null
* @throws IllegalArgumentException if the given month isn't valid
*/
public static Month fromInt(int month) {
if (month < 1 || month > 12) {
throw new IllegalArgumentException("Invalid value for MonthOfYear: " + month);
}
return VALUES[month - 1];
}
/**
* Gets the month {@code int} value.<br />
* The values are numbered from 1 (January) to 12 (December).
*
* @return the month as <code>int</code>, from 1 (January) to 12 (December)
*/
public int asInt() {
return ordinal() + 1;
}
}