mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-27 23:04:50 +02:00
8277868: Use Comparable.compare() instead of surrogate code
Reviewed-by: rriggs, aivanov
This commit is contained in:
parent
937126b140
commit
20db7800a6
12 changed files with 23 additions and 75 deletions
|
@ -3416,8 +3416,7 @@ public abstract class Calendar implements Serializable, Cloneable, Comparable<Ca
|
|||
}
|
||||
|
||||
private int compareTo(long t) {
|
||||
long thisTime = getMillisOf(this);
|
||||
return (thisTime > t) ? 1 : (thisTime == t) ? 0 : -1;
|
||||
return Long.compare(getMillisOf(this), t);
|
||||
}
|
||||
|
||||
private static long getMillisOf(Calendar calendar) {
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2003, 2020, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2003, 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
|
||||
|
@ -512,10 +512,7 @@ public final class UUID implements java.io.Serializable, Comparable<UUID> {
|
|||
public int compareTo(UUID val) {
|
||||
// The ordering is intentionally set up so that the UUIDs
|
||||
// can simply be numerically compared as two numbers
|
||||
return (this.mostSigBits < val.mostSigBits ? -1 :
|
||||
(this.mostSigBits > val.mostSigBits ? 1 :
|
||||
(this.leastSigBits < val.leastSigBits ? -1 :
|
||||
(this.leastSigBits > val.leastSigBits ? 1 :
|
||||
0))));
|
||||
int mostSigBits = Long.compare(this.mostSigBits, val.mostSigBits);
|
||||
return mostSigBits != 0 ? mostSigBits : Long.compare(this.leastSigBits, val.leastSigBits);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue