Last active
December 26, 2015 06:49
-
-
Save t3hk0d3/7110513 to your computer and use it in GitHub Desktop.
written in browser, have no IDE there
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
protected enum IntervalType { | |
UNKNOWN(0), | |
MINUTE(60, "minute", "m"), | |
HOUR(3600, "hour", "h"), | |
DAY(86400, "day", "d"), | |
WEEK(604800, "week", "w"), | |
MONTH(2592000, "month"), | |
YEAR(31104000, "year"); | |
private final int value; | |
private final String[] labels; | |
private IntervalType(int seconds, String... labels) { | |
// save into private final properties | |
this.value = seconds; | |
this.labels = labels; | |
} | |
public int value() { | |
return this.value; | |
} | |
public String[] labels() { | |
return this.labels; | |
} | |
public static IntervalType byLabel(String label) { | |
if(intervalMap.containsKey(label) { | |
return intervalMap.get(label); | |
} else { | |
return UNKNOWN; | |
} | |
} | |
private final static Map<String, IntervalType> intervalMap = new HashMap<String, IntervalType>(); | |
static { | |
for(IntervalType type : IntervalType.values()) { | |
for(String label : type.labels()) { | |
intervalMap.put(label, type); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment