Comparator magic number removed
This commit is contained in:
1 parent
8beed930f4
commit
6e765a6644
1 file changed
+12
-8
@@ -76,6 +76,10 @@ public final class Date implements Printable, Comparable<Date>
|
|||||||
private final int month;
|
private final int month;
|
||||||
private final int day;
|
private final int day;
|
||||||
|
|
||||||
|
private static final int LESS_THAN = -1;
|
||||||
|
private static final int GREATER_THAN = 1;
|
||||||
|
private static final int EQUALS = 0;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
isLeapYear calculates if a given year is a leap year or not.
|
isLeapYear calculates if a given year is a leap year or not.
|
||||||
|
|
||||||
@@ -354,7 +358,7 @@ public final class Date implements Printable, Comparable<Date>
|
|||||||
} else if (this.year < YEAR_NINETEEN_HUNDREDS) {
|
} else if (this.year < YEAR_NINETEEN_HUNDREDS) {
|
||||||
step0 = CENTURY_CODE_YEAR_EIGHTEEN_HUNDREDS;
|
step0 = CENTURY_CODE_YEAR_EIGHTEEN_HUNDREDS;
|
||||||
} else {
|
} else {
|
||||||
step0 = 0;
|
step0 = EQUALS;
|
||||||
}
|
}
|
||||||
|
|
||||||
step1 = year / DIVISION_BY_TWELVE;
|
step1 = year / DIVISION_BY_TWELVE;
|
||||||
@@ -401,23 +405,23 @@ public final class Date implements Printable, Comparable<Date>
|
|||||||
public int compareTo(final Date other)
|
public int compareTo(final Date other)
|
||||||
{
|
{
|
||||||
if (this.year < other.year) {
|
if (this.year < other.year) {
|
||||||
return -1;
|
return LESS_THAN;
|
||||||
} else if (this.year > other.year) {
|
} else if (this.year > other.year) {
|
||||||
return 1;
|
return GREATER_THAN;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.month < other.month) {
|
if (this.month < other.month) {
|
||||||
return -1;
|
return LESS_THAN;
|
||||||
} else if (this.month > other.month) {
|
} else if (this.month > other.month) {
|
||||||
return 1;
|
return GREATER_THAN;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.day < other.day) {
|
if (this.day < other.day) {
|
||||||
return -1;
|
return LESS_THAN;
|
||||||
} else if (this.day > other.day) {
|
} else if (this.day > other.day) {
|
||||||
return 1;
|
return GREATER_THAN;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0; // years, months, and days are all equal
|
return EQUALS; // years, months, and days are all equal
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user