use special enum for DateBucket units
Preparation step for having custom intervals.
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
package org.lucares.pdb.plot.api;
|
||||
|
||||
import java.time.temporal.ChronoUnit;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -10,38 +9,6 @@ import org.lucares.pdb.api.DateTimeRange;
|
||||
import org.lucares.utils.LongToDateBucket;
|
||||
|
||||
public class Interval {
|
||||
public enum IntervalTimeUnit {
|
||||
MINUTE, HOUR, DAY, WEEK, MONTH, YEAR;
|
||||
|
||||
public static boolean isValid(final String value) {
|
||||
for (final IntervalTimeUnit e : values()) {
|
||||
if (e.name().equals(value)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public ChronoUnit toChronoUnit() {
|
||||
switch (this) {
|
||||
case MINUTE:
|
||||
return ChronoUnit.MINUTES;
|
||||
case HOUR:
|
||||
return ChronoUnit.HOURS;
|
||||
case DAY:
|
||||
return ChronoUnit.DAYS;
|
||||
case WEEK:
|
||||
return ChronoUnit.WEEKS;
|
||||
case MONTH:
|
||||
return ChronoUnit.MONTHS;
|
||||
case YEAR:
|
||||
return ChronoUnit.YEARS;
|
||||
default:
|
||||
throw new IllegalArgumentException("Unexpected value: " + this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private final IntervalTimeUnit intervalTimeUnit;
|
||||
|
||||
private final int value;
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
package org.lucares.pdb.plot.api;
|
||||
|
||||
import org.lucares.utils.DateBucketUnit;
|
||||
|
||||
public enum IntervalTimeUnit {
|
||||
MINUTE, HOUR, DAY, WEEK, MONTH, YEAR;
|
||||
|
||||
public static boolean isValid(final String value) {
|
||||
for (final IntervalTimeUnit e : values()) {
|
||||
if (e.name().equals(value)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public DateBucketUnit toChronoUnit() {
|
||||
switch (this) {
|
||||
case MINUTE:
|
||||
return DateBucketUnit.MINUTE;
|
||||
case HOUR:
|
||||
return DateBucketUnit.HOUR;
|
||||
case DAY:
|
||||
return DateBucketUnit.DAY;
|
||||
case WEEK:
|
||||
return DateBucketUnit.WEEK;
|
||||
case MONTH:
|
||||
return DateBucketUnit.MONTH;
|
||||
case YEAR:
|
||||
return DateBucketUnit.YEAR;
|
||||
default:
|
||||
throw new IllegalArgumentException("Unexpected value: " + this);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user