提交 23242cab 编写于 作者: S StefanSpieker 提交者: Oleg Nenashev

Replace compare() implementations with call to Integer.compare or Long.compare (#4371)

* replaced implementation with call to Integer.compare or Long.compare

* Update core/src/main/java/hudson/model/HealthReport.java
Co-Authored-By: NZbynek Konecny <zbynek1729@gmail.com>

* mark compare methods as deprecated
Co-authored-by: NZbynek Konecny <zbynek1729@gmail.com>
上级 37d07766
......@@ -1203,9 +1203,7 @@ public class Fingerprint implements ModelObject, Saveable {
public int compare(FingerprintFacet o1, FingerprintFacet o2) {
long a = o1.getTimestamp();
long b = o2.getTimestamp();
if (a < b) return -1;
if (a == b) return 0;
return 1;
return Long.compare(a, b);
}
});
return r;
......
......@@ -326,7 +326,7 @@ public class HealthReport implements Serializable, Comparable<HealthReport> {
@Override
public int compareTo(HealthReport o) {
return (this.score < o.score ? -1 : (this.score == o.score ? 0 : 1));
return Integer.compare(this.score, o.score);
}
/**
......
......@@ -2492,13 +2492,7 @@ public class Queue extends ResourceController implements Saveable {
int r = this.timestamp.getTime().compareTo(that.timestamp.getTime());
if (r != 0) return r;
if (this.getId() < that.getId()) {
return -1;
} else if (this.getId() == that.getId()) {
return 0;
} else {
return 1;
}
return Long.compare(this.getId(), that.getId());
}
public CauseOfBlockage getCauseOfBlockage() {
......
......@@ -2496,9 +2496,7 @@ public abstract class Run <JobT extends Job<JobT,RunT>,RunT extends Run<JobT,Run
public int compare(@Nonnull Run lhs, @Nonnull Run rhs) {
long lt = lhs.getTimeInMillis();
long rt = rhs.getTimeInMillis();
if(lt>rt) return -1;
if(lt<rt) return 1;
return 0;
return Long.compare(rt, lt);
}
};
......
......@@ -672,9 +672,7 @@ public abstract class View extends AbstractModelObject implements AccessControll
public int compareTo(UserInfo that) {
long rhs = that.ordinal();
long lhs = this.ordinal();
if(rhs>lhs) return 1;
if(rhs<lhs) return -1;
return 0;
return Long.compare(rhs, lhs);
}
private long ordinal() {
......
package hudson.model.queue;
import hudson.RestrictedSince;
import hudson.model.Queue.BuildableItem;
import org.kohsuke.accmod.Restricted;
import org.kohsuke.accmod.restrictions.NoExternalUse;
import java.util.Comparator;
import java.util.List;
......@@ -28,24 +31,28 @@ public abstract class AbstractQueueSorterImpl extends QueueSorter implements Com
* The default implementation does FIFO.
*/
public int compare(BuildableItem lhs, BuildableItem rhs) {
return compare(lhs.buildableStartMilliseconds,rhs.buildableStartMilliseconds);
return Long.compare(lhs.buildableStartMilliseconds,rhs.buildableStartMilliseconds);
}
/**
* @deprecated Use Long.compare instead.
* sign(a-b).
*/
@Deprecated
@Restricted(NoExternalUse.class)
@RestrictedSince("TODO")
protected static int compare(long a, long b) {
if (a>b) return 1;
if (a<b) return -1;
return 0;
return Long.compare(a, b);
}
/**
* @deprecated Use Integer.compare instead.
* sign(a-b).
*/
@Deprecated
@Restricted(NoExternalUse.class)
@RestrictedSince("TODO")
protected static int compare(int a, int b) {
if (a>b) return 1;
if (a<b) return -1;
return 0;
return Integer.compare(a, b);
}
}
......@@ -83,9 +83,7 @@ public class ConsistentHash<T> {
}
public int compareTo(Point that) {
if(this.hash<that.hash) return -1;
if(this.hash==that.hash) return 0;
return 1;
return Integer.compare(this.hash, that.hash);
}
}
......
......@@ -97,9 +97,7 @@ public class RunList<R extends Run> extends AbstractList<R> {
public int compare(R o1, R o2) {
long lhs = o1.getTimeInMillis();
long rhs = o2.getTimeInMillis();
if (lhs > rhs) return -1;
if (lhs < rhs) return 1;
return 0;
return Long.compare(rhs, lhs);
}
});
}
......
......@@ -240,13 +240,7 @@ public class HistoryPageFilter<T> {
long o1QID = HistoryPageEntry.getEntryId(o1);
long o2QID = HistoryPageEntry.getEntryId(o2);
if (o1QID < o2QID) {
return 1;
} else if (o1QID == o2QID) {
return 0;
} else {
return -1;
}
return Long.compare(o2QID, o1QID);
}
});
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册