mirror of
https://github.com/apache/commons-lang.git
synced 2025-02-08 02:58:33 +00:00
Replaced private integer constants with private static enum.
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/lang/trunk@1627974 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
bc91bedd45
commit
52e854e3bd
@ -117,20 +117,24 @@ public class DateUtils {
|
|||||||
public static final int RANGE_MONTH_MONDAY = 6;
|
public static final int RANGE_MONTH_MONDAY = 6;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constant marker for truncating.
|
* Calendar modification types.
|
||||||
* @since 3.0
|
|
||||||
*/
|
*/
|
||||||
private static final int MODIFY_TRUNCATE = 0;
|
private static enum ModifyType {
|
||||||
/**
|
/**
|
||||||
* Constant marker for rounding.
|
* Truncation.
|
||||||
* @since 3.0
|
*/
|
||||||
*/
|
TRUNCATE,
|
||||||
private static final int MODIFY_ROUND = 1;
|
|
||||||
/**
|
/**
|
||||||
* Constant marker for ceiling.
|
* Rounding.
|
||||||
* @since 3.0
|
*/
|
||||||
*/
|
ROUND,
|
||||||
private static final int MODIFY_CEILING = 2;
|
|
||||||
|
/**
|
||||||
|
* Ceiling.
|
||||||
|
*/
|
||||||
|
CEILING
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>{@code DateUtils} instances should NOT be constructed in
|
* <p>{@code DateUtils} instances should NOT be constructed in
|
||||||
@ -709,7 +713,7 @@ public static Date round(final Date date, final int field) {
|
|||||||
}
|
}
|
||||||
final Calendar gval = Calendar.getInstance();
|
final Calendar gval = Calendar.getInstance();
|
||||||
gval.setTime(date);
|
gval.setTime(date);
|
||||||
modify(gval, field, MODIFY_ROUND);
|
modify(gval, field, ModifyType.ROUND);
|
||||||
return gval.getTime();
|
return gval.getTime();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -745,7 +749,7 @@ public static Calendar round(final Calendar date, final int field) {
|
|||||||
throw new IllegalArgumentException("The date must not be null");
|
throw new IllegalArgumentException("The date must not be null");
|
||||||
}
|
}
|
||||||
final Calendar rounded = (Calendar) date.clone();
|
final Calendar rounded = (Calendar) date.clone();
|
||||||
modify(rounded, field, MODIFY_ROUND);
|
modify(rounded, field, ModifyType.ROUND);
|
||||||
return rounded;
|
return rounded;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -812,7 +816,7 @@ public static Date truncate(final Date date, final int field) {
|
|||||||
}
|
}
|
||||||
final Calendar gval = Calendar.getInstance();
|
final Calendar gval = Calendar.getInstance();
|
||||||
gval.setTime(date);
|
gval.setTime(date);
|
||||||
modify(gval, field, MODIFY_TRUNCATE);
|
modify(gval, field, ModifyType.TRUNCATE);
|
||||||
return gval.getTime();
|
return gval.getTime();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -836,7 +840,7 @@ public static Calendar truncate(final Calendar date, final int field) {
|
|||||||
throw new IllegalArgumentException("The date must not be null");
|
throw new IllegalArgumentException("The date must not be null");
|
||||||
}
|
}
|
||||||
final Calendar truncated = (Calendar) date.clone();
|
final Calendar truncated = (Calendar) date.clone();
|
||||||
modify(truncated, field, MODIFY_TRUNCATE);
|
modify(truncated, field, ModifyType.TRUNCATE);
|
||||||
return truncated;
|
return truncated;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -892,7 +896,7 @@ public static Date ceiling(final Date date, final int field) {
|
|||||||
}
|
}
|
||||||
final Calendar gval = Calendar.getInstance();
|
final Calendar gval = Calendar.getInstance();
|
||||||
gval.setTime(date);
|
gval.setTime(date);
|
||||||
modify(gval, field, MODIFY_CEILING);
|
modify(gval, field, ModifyType.CEILING);
|
||||||
return gval.getTime();
|
return gval.getTime();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -917,7 +921,7 @@ public static Calendar ceiling(final Calendar date, final int field) {
|
|||||||
throw new IllegalArgumentException("The date must not be null");
|
throw new IllegalArgumentException("The date must not be null");
|
||||||
}
|
}
|
||||||
final Calendar ceiled = (Calendar) date.clone();
|
final Calendar ceiled = (Calendar) date.clone();
|
||||||
modify(ceiled, field, MODIFY_CEILING);
|
modify(ceiled, field, ModifyType.CEILING);
|
||||||
return ceiled;
|
return ceiled;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -960,7 +964,7 @@ public static Date ceiling(final Object date, final int field) {
|
|||||||
* @param modType type to truncate, round or ceiling
|
* @param modType type to truncate, round or ceiling
|
||||||
* @throws ArithmeticException if the year is over 280 million
|
* @throws ArithmeticException if the year is over 280 million
|
||||||
*/
|
*/
|
||||||
private static void modify(final Calendar val, final int field, final int modType) {
|
private static void modify(final Calendar val, final int field, final ModifyType modType) {
|
||||||
if (val.get(Calendar.YEAR) > 280000000) {
|
if (val.get(Calendar.YEAR) > 280000000) {
|
||||||
throw new ArithmeticException("Calendar value too large for accurate calculations");
|
throw new ArithmeticException("Calendar value too large for accurate calculations");
|
||||||
}
|
}
|
||||||
@ -981,7 +985,7 @@ private static void modify(final Calendar val, final int field, final int modTyp
|
|||||||
|
|
||||||
// truncate milliseconds
|
// truncate milliseconds
|
||||||
final int millisecs = val.get(Calendar.MILLISECOND);
|
final int millisecs = val.get(Calendar.MILLISECOND);
|
||||||
if (MODIFY_TRUNCATE == modType || millisecs < 500) {
|
if (ModifyType.TRUNCATE == modType || millisecs < 500) {
|
||||||
time = time - millisecs;
|
time = time - millisecs;
|
||||||
}
|
}
|
||||||
if (field == Calendar.SECOND) {
|
if (field == Calendar.SECOND) {
|
||||||
@ -990,7 +994,7 @@ private static void modify(final Calendar val, final int field, final int modTyp
|
|||||||
|
|
||||||
// truncate seconds
|
// truncate seconds
|
||||||
final int seconds = val.get(Calendar.SECOND);
|
final int seconds = val.get(Calendar.SECOND);
|
||||||
if (!done && (MODIFY_TRUNCATE == modType || seconds < 30)) {
|
if (!done && (ModifyType.TRUNCATE == modType || seconds < 30)) {
|
||||||
time = time - (seconds * 1000L);
|
time = time - (seconds * 1000L);
|
||||||
}
|
}
|
||||||
if (field == Calendar.MINUTE) {
|
if (field == Calendar.MINUTE) {
|
||||||
@ -999,7 +1003,7 @@ private static void modify(final Calendar val, final int field, final int modTyp
|
|||||||
|
|
||||||
// truncate minutes
|
// truncate minutes
|
||||||
final int minutes = val.get(Calendar.MINUTE);
|
final int minutes = val.get(Calendar.MINUTE);
|
||||||
if (!done && (MODIFY_TRUNCATE == modType || minutes < 30)) {
|
if (!done && (ModifyType.TRUNCATE == modType || minutes < 30)) {
|
||||||
time = time - (minutes * 60000L);
|
time = time - (minutes * 60000L);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1015,7 +1019,7 @@ private static void modify(final Calendar val, final int field, final int modTyp
|
|||||||
for (final int element : aField) {
|
for (final int element : aField) {
|
||||||
if (element == field) {
|
if (element == field) {
|
||||||
//This is our field... we stop looping
|
//This is our field... we stop looping
|
||||||
if (modType == MODIFY_CEILING || (modType == MODIFY_ROUND && roundUp)) {
|
if (modType == ModifyType.CEILING || (modType == ModifyType.ROUND && roundUp)) {
|
||||||
if (field == DateUtils.SEMI_MONTH) {
|
if (field == DateUtils.SEMI_MONTH) {
|
||||||
//This is a special case that's hard to generalize
|
//This is a special case that's hard to generalize
|
||||||
//If the date is 1, we round up to 16, otherwise
|
//If the date is 1, we round up to 16, otherwise
|
||||||
|
Loading…
x
Reference in New Issue
Block a user