8277868: Use Comparable.compare() instead of surrogate code

Reviewed-by: rriggs, aivanov
This commit is contained in:
Sergey Tsypanov 2021-12-16 21:39:08 +00:00 committed by Roger Riggs
parent 937126b140
commit 20db7800a6
12 changed files with 23 additions and 75 deletions

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 1994, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1994, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -26,18 +26,13 @@
package java.util;
import java.text.DateFormat;
import java.time.LocalDate;
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.io.ObjectInputStream;
import java.lang.ref.SoftReference;
import java.time.Instant;
import sun.util.calendar.BaseCalendar;
import sun.util.calendar.CalendarDate;
import sun.util.calendar.CalendarSystem;
import sun.util.calendar.CalendarUtils;
import sun.util.calendar.Era;
import sun.util.calendar.Gregorian;
import sun.util.calendar.ZoneInfo;
/**
@ -975,10 +970,9 @@ public class Date
* @since 1.2
* @throws NullPointerException if {@code anotherDate} is null.
*/
@Override
public int compareTo(Date anotherDate) {
long thisTime = getMillisOf(this);
long anotherTime = getMillisOf(anotherDate);
return (thisTime<anotherTime ? -1 : (thisTime==anotherTime ? 0 : 1));
return Long.compare(getMillisOf(this), getMillisOf(anotherDate));
}
/**