Skip to content
Permalink
Browse files
Avoid unnecessary use of Instant.toEpochMilli
Avoid unnecessary use of Instant.toEpochMilli by using Instant.compareTo
to compare Instants direclty
  • Loading branch information
jkmcl authored and ok2c committed Jun 26, 2022
1 parent 15951d8 commit 518eb410fe77743ea75be26e12c59a8c78c4717b
Showing 2 changed files with 3 additions and 3 deletions.
@@ -59,7 +59,7 @@ public int compare(final Cookie c1, final Cookie c2) {
final Instant d1 = c1.getCreationInstant();
final Instant d2 = c2.getCreationInstant();
if (d1 != null && d2 != null) {
return (int) (d1.toEpochMilli() - d2.toEpochMilli());
return d1.compareTo(d2);
}
}
return result;
@@ -269,7 +269,7 @@ public void setHttpOnly(final boolean httpOnly) {
public boolean isExpired(final Date date) {
Args.notNull(date, "Date");
return (cookieExpiryDate != null
&& cookieExpiryDate.toEpochMilli() <= DateUtils.toInstant(date).toEpochMilli());
&& cookieExpiryDate.compareTo(DateUtils.toInstant(date)) <= 0);
}

/**
@@ -282,7 +282,7 @@ public boolean isExpired(final Date date) {
public boolean isExpired(final Instant instant) {
Args.notNull(instant, "Instant");
return (cookieExpiryDate != null
&& cookieExpiryDate.toEpochMilli() <= instant.toEpochMilli());
&& cookieExpiryDate.compareTo(instant) <= 0);
}

/**

0 comments on commit 518eb41

Please sign in to comment.