提交 766d64b7 authored 作者: Evgenij Ryazanov's avatar Evgenij Ryazanov

Use the same grouped checks for negative value in all Interval methods

上级 9ea58704
...@@ -148,7 +148,7 @@ public final class Interval { ...@@ -148,7 +148,7 @@ public final class Interval {
* @return INTERVAL YEAR TO MONTH * @return INTERVAL YEAR TO MONTH
*/ */
public static Interval ofYearsMonths(long years, int months) { public static Interval ofYearsMonths(long years, int months) {
boolean negative = years < 0 || months < 0; boolean negative = (years | months) < 0;
if (negative) { if (negative) {
if (years > 0 || months > 0) { if (years > 0 || months > 0) {
throw new IllegalArgumentException(); throw new IllegalArgumentException();
...@@ -173,7 +173,7 @@ public final class Interval { ...@@ -173,7 +173,7 @@ public final class Interval {
* @return INTERVAL DAY TO HOUR * @return INTERVAL DAY TO HOUR
*/ */
public static Interval ofDaysHours(long days, int hours) { public static Interval ofDaysHours(long days, int hours) {
boolean negative = days < 0 || hours < 0; boolean negative = (days | hours) < 0;
if (negative) { if (negative) {
if (days > 0 || hours > 0) { if (days > 0 || hours > 0) {
throw new IllegalArgumentException(); throw new IllegalArgumentException();
...@@ -200,7 +200,7 @@ public final class Interval { ...@@ -200,7 +200,7 @@ public final class Interval {
* @return INTERVAL DAY TO MINUTE * @return INTERVAL DAY TO MINUTE
*/ */
public static Interval ofDaysHoursMinutes(long days, int hours, int minutes) { public static Interval ofDaysHoursMinutes(long days, int hours, int minutes) {
boolean negative = days < 0 || (hours | minutes) < 0; boolean negative = (days | hours | minutes) < 0;
if (negative) { if (negative) {
if (days > 0 || hours > 0 || minutes > 0) { if (days > 0 || hours > 0 || minutes > 0) {
throw new IllegalArgumentException(); throw new IllegalArgumentException();
...@@ -259,7 +259,7 @@ public final class Interval { ...@@ -259,7 +259,7 @@ public final class Interval {
* @return INTERVAL DAY TO SECOND * @return INTERVAL DAY TO SECOND
*/ */
public static Interval ofDaysHoursMinutesNanos(long days, int hours, int minutes, long nanos) { public static Interval ofDaysHoursMinutesNanos(long days, int hours, int minutes, long nanos) {
boolean negative = (days | nanos) < 0 || (hours | minutes) < 0; boolean negative = (days | hours | minutes | nanos) < 0;
if (negative) { if (negative) {
if (days > 0 || hours > 0 || minutes > 0 || nanos > 0) { if (days > 0 || hours > 0 || minutes > 0 || nanos > 0) {
throw new IllegalArgumentException(); throw new IllegalArgumentException();
...@@ -268,7 +268,7 @@ public final class Interval { ...@@ -268,7 +268,7 @@ public final class Interval {
hours = -hours; hours = -hours;
minutes = -minutes; minutes = -minutes;
nanos = -nanos; nanos = -nanos;
if ((hours | minutes) < 0 || nanos < 0) { if ((hours | minutes | nanos) < 0) {
// Integer.MIN_VALUE, Long.MIN_VALUE // Integer.MIN_VALUE, Long.MIN_VALUE
throw new IllegalArgumentException(); throw new IllegalArgumentException();
} }
...@@ -340,7 +340,7 @@ public final class Interval { ...@@ -340,7 +340,7 @@ public final class Interval {
* @return INTERVAL HOUR TO SECOND * @return INTERVAL HOUR TO SECOND
*/ */
public static Interval ofHoursMinutesNanos(long hours, int minutes, long nanos) { public static Interval ofHoursMinutesNanos(long hours, int minutes, long nanos) {
boolean negative = (hours | nanos) < 0 || minutes < 0; boolean negative = (hours | minutes | nanos) < 0;
if (negative) { if (negative) {
if (hours > 0 || minutes > 0 || nanos > 0) { if (hours > 0 || minutes > 0 || nanos > 0) {
throw new IllegalArgumentException(); throw new IllegalArgumentException();
...@@ -348,7 +348,7 @@ public final class Interval { ...@@ -348,7 +348,7 @@ public final class Interval {
hours = -hours; hours = -hours;
minutes = -minutes; minutes = -minutes;
nanos = -nanos; nanos = -nanos;
if (minutes < 0 || nanos < 0) { if ((minutes | nanos) < 0) {
// Integer.MIN_VALUE, Long.MIN_VALUE // Integer.MIN_VALUE, Long.MIN_VALUE
throw new IllegalArgumentException(); throw new IllegalArgumentException();
} }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论