mirror of
https://github.com/eclipse-sailing-analytics/sailing-analytics.git
synced 2026-10-08 21:30:57 +00:00
Added an enum for months
This commit is contained in:
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;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user