Skip to content

Commit

Permalink
Removed unneeded cast operations.
Browse files Browse the repository at this point in the history
  • Loading branch information
david-waltermire committed Oct 27, 2024
1 parent b39ea7c commit 6ba20a5
Showing 1 changed file with 21 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -241,8 +241,7 @@ private static IDateItem subtractDurationFromDate(
@NonNull ZonedDateTime dateTime,
@NonNull TemporalAmount duration) {
@SuppressWarnings("null")
@NonNull
ZonedDateTime result = dateTime.minus(duration);
@NonNull ZonedDateTime result = dateTime.minus(duration);
return IDateItem.valueOf(result);
}

Expand All @@ -264,8 +263,7 @@ public static IYearMonthDurationItem opSubtractYearMonthDurations(
Period duration2 = arg2.asPeriod();

@SuppressWarnings("null")
@NonNull
Period duration = duration1.minus(duration2);
@NonNull Period duration = duration1.minus(duration2);
return IYearMonthDurationItem.valueOf(duration);
}

Expand All @@ -287,8 +285,7 @@ public static IDayTimeDurationItem opSubtractDayTimeDurations(
Duration duration2 = arg2.asDuration();

@SuppressWarnings("null")
@NonNull
Duration duration = duration1.minus(duration2);
@NonNull Duration duration = duration1.minus(duration2);
return IDayTimeDurationItem.valueOf(duration);
}

Expand Down Expand Up @@ -320,8 +317,7 @@ public static IDayTimeDurationItem opSubtractDateTimes(@NonNull IDateTimeItem ti
@NonNull
private static IDayTimeDurationItem between(@NonNull ZonedDateTime time1, @NonNull ZonedDateTime time2) {
@SuppressWarnings("null")
@NonNull
Duration between = Duration.between(time1, time2);
@NonNull Duration between = Duration.between(time1, time2);
return IDayTimeDurationItem.valueOf(between);
}

Expand All @@ -340,8 +336,7 @@ public static IDateTimeItem opSubtractYearMonthDurationFromDateTime(
@NonNull IDateTimeItem moment,
@NonNull IYearMonthDurationItem duration) {
@SuppressWarnings("null")
@NonNull
ZonedDateTime dateTime = moment.asZonedDateTime().minus(duration.asPeriod());
@NonNull ZonedDateTime dateTime = moment.asZonedDateTime().minus(duration.asPeriod());
return IDateTimeItem.valueOf(dateTime);
}

Expand All @@ -361,8 +356,7 @@ public static IDateTimeItem opSubtractDayTimeDurationFromDateTime(
@NonNull IDayTimeDurationItem duration) {

@SuppressWarnings("null")
@NonNull
ZonedDateTime dateTime = moment.asZonedDateTime().plus(duration.asDuration());
@NonNull ZonedDateTime dateTime = moment.asZonedDateTime().plus(duration.asDuration());
return IDateTimeItem.valueOf(dateTime);
}

Expand All @@ -389,8 +383,7 @@ public static IYearMonthDurationItem opMultiplyYearMonthDuration(
}

@SuppressWarnings("null")
@NonNull
Period period = arg1.asPeriod().multipliedBy(arg2Int);
@NonNull Period period = arg1.asPeriod().multipliedBy(arg2Int);
return IYearMonthDurationItem.valueOf(period);
}

Expand All @@ -416,8 +409,7 @@ public static IDayTimeDurationItem opMultiplyDayTimeDuration(
}

@SuppressWarnings("null")
@NonNull
Duration duration = arg1.asDuration().multipliedBy(arg2Long);
@NonNull Duration duration = arg1.asDuration().multipliedBy(arg2Long);
return IDayTimeDurationItem.valueOf(duration);
}

Expand Down Expand Up @@ -465,8 +457,7 @@ public static IDayTimeDurationItem opDivideDayTimeDuration(
@NonNull INumericItem arg2) {
try {
@SuppressWarnings("null")
@NonNull
Duration duration = arg1.asDuration().dividedBy(FunctionUtils.asLong(arg2.round()));
@NonNull Duration duration = arg1.asDuration().dividedBy(FunctionUtils.asLong(arg2.round()));
return IDayTimeDurationItem.valueOf(duration);
} catch (ArithmeticException ex) {
throw new ArithmeticFunctionException(ArithmeticFunctionException.DIVISION_BY_ZERO, "Division by zero", ex);
Expand Down Expand Up @@ -760,17 +751,15 @@ public static INumericItem opNumericAdd(@NonNull INumericItem left, @NonNull INu
BigInteger integerRight = right.asInteger();

@SuppressWarnings("null")
@NonNull
BigInteger result = integerLeft.add(integerRight);
@NonNull BigInteger result = integerLeft.add(integerRight);
retval = IIntegerItem.valueOf(result);
} else {
// create a decimal result
BigDecimal decimalLeft = left.asDecimal();
BigDecimal decimalRight = right.asDecimal();

@SuppressWarnings("null")
@NonNull
BigDecimal result = decimalLeft.add(decimalRight, FunctionUtils.MATH_CONTEXT);
@NonNull BigDecimal result = decimalLeft.add(decimalRight, FunctionUtils.MATH_CONTEXT);
retval = IDecimalItem.valueOf(result);
}
return retval;
Expand All @@ -795,17 +784,15 @@ public static INumericItem opNumericSubtract(@NonNull INumericItem left, @NonNul
BigInteger integerRight = right.asInteger();

@SuppressWarnings("null")
@NonNull
BigInteger result = integerLeft.subtract(integerRight);
@NonNull BigInteger result = integerLeft.subtract(integerRight);
retval = IIntegerItem.valueOf(result);
} else {
// create a decimal result
BigDecimal decimalLeft = left.asDecimal();
BigDecimal decimalRight = right.asDecimal();

@SuppressWarnings("null")
@NonNull
BigDecimal result = decimalLeft.subtract(decimalRight, FunctionUtils.MATH_CONTEXT);
@NonNull BigDecimal result = decimalLeft.subtract(decimalRight, FunctionUtils.MATH_CONTEXT);
retval = IDecimalItem.valueOf(result);
}
return retval;
Expand All @@ -827,17 +814,15 @@ public static INumericItem opNumericMultiply(@NonNull INumericItem left, @NonNul
if (left instanceof IIntegerItem || right instanceof IIntegerItem) {
// create an integer result
@SuppressWarnings("null")
@NonNull
BigInteger result = left.asInteger().multiply(right.asInteger());
@NonNull BigInteger result = left.asInteger().multiply(right.asInteger());
retval = IIntegerItem.valueOf(result);
} else {
// create a decimal result
BigDecimal decimalLeft = left.asDecimal();
BigDecimal decimalRight = right.asDecimal();

@SuppressWarnings("null")
@NonNull
BigDecimal result = decimalLeft.multiply(decimalRight, FunctionUtils.MATH_CONTEXT);
@NonNull BigDecimal result = decimalLeft.multiply(decimalRight, FunctionUtils.MATH_CONTEXT);
retval = IDecimalItem.valueOf(result);
}
return retval;
Expand Down Expand Up @@ -866,8 +851,7 @@ public static IDecimalItem opNumericDivide(@NonNull INumericItem dividend, @NonN
BigDecimal decimalDividend = dividend.asDecimal();

@SuppressWarnings("null")
@NonNull
BigDecimal result = decimalDividend.divide(decimalDivisor, FunctionUtils.MATH_CONTEXT);
@NonNull BigDecimal result = decimalDividend.divide(decimalDivisor, FunctionUtils.MATH_CONTEXT);
return IDecimalItem.valueOf(result);
}

Expand All @@ -894,8 +878,7 @@ public static IIntegerItem opNumericIntegerDivide(@NonNull INumericItem dividend
}

@SuppressWarnings("null")
@NonNull
BigInteger result = dividend.asInteger().divide(integerDivisor);
@NonNull BigInteger result = dividend.asInteger().divide(integerDivisor);
retval = IIntegerItem.valueOf(result);
} else {
// create a decimal result
Expand All @@ -909,8 +892,7 @@ public static IIntegerItem opNumericIntegerDivide(@NonNull INumericItem dividend
BigDecimal decimalDividend = dividend.asDecimal();

@SuppressWarnings("null")
@NonNull
BigInteger result
@NonNull BigInteger result
= decimalDividend.divideToIntegralValue(decimalDivisor, FunctionUtils.MATH_CONTEXT).toBigInteger();
retval = IIntegerItem.valueOf(result);
}
Expand Down Expand Up @@ -943,8 +925,7 @@ public static INumericItem opNumericMod(@NonNull INumericItem dividend, @NonNull
retval = dividend;
} else {
@SuppressWarnings("null")
@NonNull
BigDecimal result = decimalDividend.remainder(decimalDivisor, FunctionUtils.MATH_CONTEXT);
@NonNull BigDecimal result = decimalDividend.remainder(decimalDivisor, FunctionUtils.MATH_CONTEXT);
retval = IDecimalItem.valueOf(result);
}
return retval;
Expand All @@ -966,16 +947,14 @@ public static INumericItem opNumericUnaryMinus(@NonNull INumericItem item) {
BigInteger integer = item.asInteger();

@SuppressWarnings("null")
@NonNull
BigInteger result = integer.negate();
@NonNull BigInteger result = integer.negate();
retval = IIntegerItem.valueOf(result);
} else if (item instanceof IDecimalItem) {
// create a decimal result
BigDecimal decimal = item.asDecimal();

@SuppressWarnings("null")
@NonNull
BigDecimal result = decimal.negate(FunctionUtils.MATH_CONTEXT);
@NonNull BigDecimal result = decimal.negate(FunctionUtils.MATH_CONTEXT);
retval = IDecimalItem.valueOf(result);
} else {
throw new InvalidTypeMetapathException(item);
Expand Down

0 comments on commit 6ba20a5

Please sign in to comment.