You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2019/09/04 00:17:34 UTC
[commons-lang] branch master updated: Refactor duplicate code.
This is an automated email from the ASF dual-hosted git repository.
ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-lang.git
The following commit(s) were added to refs/heads/master by this push:
new 5e7d64d Refactor duplicate code.
5e7d64d is described below
commit 5e7d64d6b2719afb1e5f4785d80d24ac5a19a782
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Tue Sep 3 16:20:19 2019 -0400
Refactor duplicate code.
---
.../org/apache/commons/lang3/time/DateUtils.java | 32 ++++++++++++----------
1 file changed, 18 insertions(+), 14 deletions(-)
diff --git a/src/main/java/org/apache/commons/lang3/time/DateUtils.java b/src/main/java/org/apache/commons/lang3/time/DateUtils.java
index 065afb8..da96dff 100644
--- a/src/main/java/org/apache/commons/lang3/time/DateUtils.java
+++ b/src/main/java/org/apache/commons/lang3/time/DateUtils.java
@@ -165,7 +165,7 @@ public class DateUtils {
*/
public static boolean isSameDay(final Date date1, final Date date2) {
if (date1 == null || date2 == null) {
- throw new IllegalArgumentException("The date must not be null");
+ throw nullDateIllegalArgumentException();
}
final Calendar cal1 = Calendar.getInstance();
cal1.setTime(date1);
@@ -189,7 +189,7 @@ public class DateUtils {
*/
public static boolean isSameDay(final Calendar cal1, final Calendar cal2) {
if (cal1 == null || cal2 == null) {
- throw new IllegalArgumentException("The date must not be null");
+ throw nullDateIllegalArgumentException();
}
return cal1.get(Calendar.ERA) == cal2.get(Calendar.ERA) &&
cal1.get(Calendar.YEAR) == cal2.get(Calendar.YEAR) &&
@@ -210,7 +210,7 @@ public class DateUtils {
*/
public static boolean isSameInstant(final Date date1, final Date date2) {
if (date1 == null || date2 == null) {
- throw new IllegalArgumentException("The date must not be null");
+ throw nullDateIllegalArgumentException();
}
return date1.getTime() == date2.getTime();
}
@@ -228,7 +228,7 @@ public class DateUtils {
*/
public static boolean isSameInstant(final Calendar cal1, final Calendar cal2) {
if (cal1 == null || cal2 == null) {
- throw new IllegalArgumentException("The date must not be null");
+ throw nullDateIllegalArgumentException();
}
return cal1.getTime().getTime() == cal2.getTime().getTime();
}
@@ -248,7 +248,7 @@ public class DateUtils {
*/
public static boolean isSameLocalTime(final Calendar cal1, final Calendar cal2) {
if (cal1 == null || cal2 == null) {
- throw new IllegalArgumentException("The date must not be null");
+ throw nullDateIllegalArgumentException();
}
return cal1.get(Calendar.MILLISECOND) == cal2.get(Calendar.MILLISECOND) &&
cal1.get(Calendar.SECOND) == cal2.get(Calendar.SECOND) &&
@@ -741,13 +741,17 @@ public class DateUtils {
*/
public static Calendar round(final Calendar date, final int field) {
if (date == null) {
- throw new IllegalArgumentException("The date must not be null");
+ throw nullDateIllegalArgumentException();
}
final Calendar rounded = (Calendar) date.clone();
modify(rounded, field, ModifyType.ROUND);
return rounded;
}
+ private static IllegalArgumentException nullDateIllegalArgumentException() {
+ return new IllegalArgumentException("The date must not be null");
+ }
+
/**
* <p>Rounds a date, leaving the field specified as the most
* significant field.</p>
@@ -778,7 +782,7 @@ public class DateUtils {
*/
public static Date round(final Object date, final int field) {
if (date == null) {
- throw new IllegalArgumentException("The date must not be null");
+ throw nullDateIllegalArgumentException();
}
if (date instanceof Date) {
return round((Date) date, field);
@@ -830,7 +834,7 @@ public class DateUtils {
*/
public static Calendar truncate(final Calendar date, final int field) {
if (date == null) {
- throw new IllegalArgumentException("The date must not be null");
+ throw nullDateIllegalArgumentException();
}
final Calendar truncated = (Calendar) date.clone();
modify(truncated, field, ModifyType.TRUNCATE);
@@ -855,7 +859,7 @@ public class DateUtils {
*/
public static Date truncate(final Object date, final int field) {
if (date == null) {
- throw new IllegalArgumentException("The date must not be null");
+ throw nullDateIllegalArgumentException();
}
if (date instanceof Date) {
return truncate((Date) date, field);
@@ -909,7 +913,7 @@ public class DateUtils {
*/
public static Calendar ceiling(final Calendar date, final int field) {
if (date == null) {
- throw new IllegalArgumentException("The date must not be null");
+ throw nullDateIllegalArgumentException();
}
final Calendar ceiled = (Calendar) date.clone();
modify(ceiled, field, ModifyType.CEILING);
@@ -935,7 +939,7 @@ public class DateUtils {
*/
public static Date ceiling(final Object date, final int field) {
if (date == null) {
- throw new IllegalArgumentException("The date must not be null");
+ throw nullDateIllegalArgumentException();
}
if (date instanceof Date) {
return ceiling((Date) date, field);
@@ -1153,7 +1157,7 @@ public class DateUtils {
*/
public static Iterator<Calendar> iterator(final Calendar focus, final int rangeStyle) {
if (focus == null) {
- throw new IllegalArgumentException("The date must not be null");
+ throw nullDateIllegalArgumentException();
}
Calendar start = null;
Calendar end = null;
@@ -1243,7 +1247,7 @@ public class DateUtils {
*/
public static Iterator<?> iterator(final Object focus, final int rangeStyle) {
if (focus == null) {
- throw new IllegalArgumentException("The date must not be null");
+ throw nullDateIllegalArgumentException();
}
if (focus instanceof Date) {
return iterator((Date) focus, rangeStyle);
@@ -1663,7 +1667,7 @@ public class DateUtils {
*/
private static long getFragment(final Calendar calendar, final int fragment, final TimeUnit unit) {
if (calendar == null) {
- throw new IllegalArgumentException("The date must not be null");
+ throw nullDateIllegalArgumentException();
}
long result = 0;