8277868: Use Comparable.compare() instead of surrogate code
Reviewed-by: rriggs, aivanov
This commit is contained in:
parent
937126b140
commit
20db7800a6
@ -4405,7 +4405,7 @@ public class BigDecimal extends Number implements Comparable<BigDecimal> {
|
||||
x = -x;
|
||||
if (y < 0)
|
||||
y = -y;
|
||||
return (x < y) ? -1 : ((x == y) ? 0 : 1);
|
||||
return Long.compare(x, y);
|
||||
}
|
||||
|
||||
private static int saturateLong(long s) {
|
||||
|
@ -447,13 +447,7 @@ public class CookieManager extends CookieHandler
|
||||
// Check creation time. Sort older first
|
||||
long creation1 = c1.getCreationTime();
|
||||
long creation2 = c2.getCreationTime();
|
||||
if (creation1 < creation2) {
|
||||
return -1;
|
||||
}
|
||||
if (creation1 > creation2) {
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
return Long.compare(creation1, creation2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -1533,12 +1533,7 @@ public final class NumericShaper implements java.io.Serializable {
|
||||
rangeArray = rangeSet.toArray(new Range[rangeSet.size()]);
|
||||
if (rangeArray.length > BSEARCH_THRESHOLD) {
|
||||
// sort rangeArray for binary search
|
||||
Arrays.sort(rangeArray,
|
||||
new Comparator<Range>() {
|
||||
public int compare(Range s1, Range s2) {
|
||||
return s1.base > s2.base ? 1 : s1.base == s2.base ? 0 : -1;
|
||||
}
|
||||
});
|
||||
Arrays.sort(rangeArray, Comparator.comparingInt(s -> s.base));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -532,7 +532,7 @@ public abstract class Line2D implements Shape, Cloneable {
|
||||
}
|
||||
}
|
||||
}
|
||||
return (ccw < 0.0) ? -1 : ((ccw > 0.0) ? 1 : 0);
|
||||
return java.lang.Double.compare(ccw, 0.0);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -27,16 +27,11 @@ package javax.swing.plaf.basic;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.datatransfer.*;
|
||||
import java.awt.dnd.*;
|
||||
import java.awt.event.*;
|
||||
import java.util.Enumeration;
|
||||
import java.util.EventObject;
|
||||
import java.util.Hashtable;
|
||||
import java.util.TooManyListenersException;
|
||||
import javax.swing.*;
|
||||
import javax.swing.event.*;
|
||||
import javax.swing.plaf.*;
|
||||
import javax.swing.text.*;
|
||||
import javax.swing.table.*;
|
||||
import javax.swing.plaf.basic.DragRecognitionSupport.BeforeDrag;
|
||||
import sun.swing.SwingUtilities2;
|
||||
@ -221,8 +216,8 @@ public class BasicTableUI extends TableUI
|
||||
this.inSelection = true;
|
||||
|
||||
// look at the sign of dx and dy only
|
||||
dx = sign(dx);
|
||||
dy = sign(dy);
|
||||
dx = Integer.signum(dx);
|
||||
dy = Integer.signum(dy);
|
||||
|
||||
// make sure one is zero, but not both
|
||||
assert (dx == 0 || dy == 0) && !(dx == 0 && dy == 0);
|
||||
@ -250,10 +245,6 @@ public class BasicTableUI extends TableUI
|
||||
leadColumn = clipToRange(leadColumn+dx, 0, table.getColumnCount());
|
||||
}
|
||||
|
||||
private static int sign(int num) {
|
||||
return (num < 0) ? -1 : ((num == 0) ? 0 : 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Called to move within the selected range of the given JTable.
|
||||
* This method uses the table's notion of selection, which is
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 1998, 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1998, 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
|
||||
@ -504,13 +504,7 @@ public class GapContent extends GapVector implements AbstractDocument.Content, S
|
||||
* @return < 0 if o1 < o2, 0 if the same, > 0 if o1 > o2
|
||||
*/
|
||||
final int compare(MarkData o1, MarkData o2) {
|
||||
if (o1.index < o2.index) {
|
||||
return -1;
|
||||
} else if (o1.index > o2.index) {
|
||||
return 1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
return Integer.compare(o1.index, o2.index);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 1998, 2018, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1998, 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
|
||||
@ -730,13 +730,7 @@ public abstract class Curve {
|
||||
}
|
||||
|
||||
public static int orderof(double x1, double x2) {
|
||||
if (x1 < x2) {
|
||||
return -1;
|
||||
}
|
||||
if (x1 > x2) {
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
return Double.compare(x1, x2);
|
||||
}
|
||||
|
||||
public static long signeddiffbits(double y1, double y2) {
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 1998, 2000, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1998, 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
|
||||
@ -315,19 +315,9 @@ public class Spans {
|
||||
* position. The end position is ignored
|
||||
* in this ranking.
|
||||
*/
|
||||
@Override
|
||||
public int compareTo(Span otherSpan) {
|
||||
float otherStart = otherSpan.getStart();
|
||||
int result;
|
||||
|
||||
if (mStart < otherStart) {
|
||||
result = -1;
|
||||
} else if (mStart > otherStart) {
|
||||
result = 1;
|
||||
} else {
|
||||
result = 0;
|
||||
}
|
||||
|
||||
return result;
|
||||
return Float.compare(mStart, otherSpan.getStart());
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2018, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1997, 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
|
||||
@ -79,7 +79,7 @@ public final class GraphicsPrimitiveMgr {
|
||||
int id1 = o1.getUniqueID();
|
||||
int id2 = o2.getUniqueID();
|
||||
|
||||
return (id1 == id2 ? 0 : (id1 < id2 ? -1 : 1));
|
||||
return Integer.compare(id1, id2);
|
||||
}
|
||||
};
|
||||
|
||||
@ -88,7 +88,7 @@ public final class GraphicsPrimitiveMgr {
|
||||
int id1 = ((GraphicsPrimitive) o1).getUniqueID();
|
||||
int id2 = ((PrimitiveSpec) o2).uniqueID;
|
||||
|
||||
return (id1 == id2 ? 0 : (id1 < id2 ? -1 : 1));
|
||||
return Integer.compare(id1, id2);
|
||||
}
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user