Avoid unnecessary use of Instant.toEpochMilli

Avoid unnecessary use of Instant.toEpochMilli by using Instant.compareTo
to compare Instants direclty
This commit is contained in:
jkmcl 2022-06-27 03:13:58 +08:00 committed by Oleg Kalnichevski
parent 15951d8094
commit 518eb410fe
2 changed files with 3 additions and 3 deletions

View File

@ -59,7 +59,7 @@ public class CookiePriorityComparator implements Comparator<Cookie> {
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;

View File

@ -269,7 +269,7 @@ public final class BasicClientCookie implements SetCookie, Cloneable, Serializab
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 final class BasicClientCookie implements SetCookie, Cloneable, Serializab
public boolean isExpired(final Instant instant) {
Args.notNull(instant, "Instant");
return (cookieExpiryDate != null
&& cookieExpiryDate.toEpochMilli() <= instant.toEpochMilli());
&& cookieExpiryDate.compareTo(instant) <= 0);
}
/**