From 0a5724e1fcb616d4012e3cd9b7bf915311241eed Mon Sep 17 00:00:00 2001 From: Emmanuel Bourg Date: Mon, 18 Nov 2024 13:30:47 +0100 Subject: [PATCH] Use Integer.compare() to compare integers --- .../routines/AbstractCalendarValidator.java | 17 ++--------------- 1 file changed, 2 insertions(+), 15 deletions(-) diff --git a/src/main/java/org/apache/commons/validator/routines/AbstractCalendarValidator.java b/src/main/java/org/apache/commons/validator/routines/AbstractCalendarValidator.java index 5552377cb..a3e5264ed 100644 --- a/src/main/java/org/apache/commons/validator/routines/AbstractCalendarValidator.java +++ b/src/main/java/org/apache/commons/validator/routines/AbstractCalendarValidator.java @@ -75,14 +75,7 @@ public AbstractCalendarValidator(final boolean strict, final int dateStyle, fina * if it is less than the seconds or +1 if it is greater than the seconds. */ private int calculateCompareResult(final Calendar value, final Calendar compare, final int field) { - final int difference = value.get(field) - compare.get(field); - if (difference < 0) { - return -1; - } - if (difference > 0) { - return 1; - } - return 0; + return Integer.compare(value.get(field), compare.get(field)); } /** @@ -177,13 +170,7 @@ protected int compare(final Calendar value, final Calendar compare, final int fi protected int compareQuarters(final Calendar value, final Calendar compare, final int monthOfFirstQuarter) { final int valueQuarter = calculateQuarter(value, monthOfFirstQuarter); final int compareQuarter = calculateQuarter(compare, monthOfFirstQuarter); - if (valueQuarter < compareQuarter) { - return -1; - } - if (valueQuarter > compareQuarter) { - return 1; - } - return 0; + return Integer.compare(valueQuarter, compareQuarter); } /**