Integer/Long.compare(x, y) can be used to compare primitive values

上级 07a0b62b
...@@ -42,7 +42,7 @@ public class SpatialDataType implements DataType { ...@@ -42,7 +42,7 @@ public class SpatialDataType implements DataType {
} }
long la = ((SpatialKey) a).getId(); long la = ((SpatialKey) a).getId();
long lb = ((SpatialKey) b).getId(); long lb = ((SpatialKey) b).getId();
return la < lb ? -1 : la > lb ? 1 : 0; return Long.compare(la, lb);
} }
/** /**
......
...@@ -1323,7 +1323,7 @@ public class ObjectDataType implements DataType { ...@@ -1323,7 +1323,7 @@ public class ObjectDataType implements DataType {
} else if (type == int.class) { } else if (type == int.class) {
int a = ((int[]) aObj)[i]; int a = ((int[]) aObj)[i];
int b = ((int[]) bObj)[i]; int b = ((int[]) bObj)[i];
x = a == b ? 0 : a < b ? -1 : 1; x = Integer.compare(a, b);
} else if (type == float.class) { } else if (type == float.class) {
x = Float.compare(((float[]) aObj)[i], x = Float.compare(((float[]) aObj)[i],
((float[]) bObj)[i]); ((float[]) bObj)[i]);
...@@ -1333,7 +1333,7 @@ public class ObjectDataType implements DataType { ...@@ -1333,7 +1333,7 @@ public class ObjectDataType implements DataType {
} else { } else {
long a = ((long[]) aObj)[i]; long a = ((long[]) aObj)[i];
long b = ((long[]) bObj)[i]; long b = ((long[]) bObj)[i];
x = a == b ? 0 : a < b ? -1 : 1; x = Long.compare(a, b);
} }
if (x != 0) { if (x != 0) {
return x; return x;
...@@ -1349,7 +1349,7 @@ public class ObjectDataType implements DataType { ...@@ -1349,7 +1349,7 @@ public class ObjectDataType implements DataType {
} }
} }
} }
return aLen == bLen ? 0 : aLen < bLen ? -1 : 1; return Integer.compare(aLen, bLen);
} }
@Override @Override
......
...@@ -116,7 +116,7 @@ public class ValueArray extends Value { ...@@ -116,7 +116,7 @@ public class ValueArray extends Value {
return comp; return comp;
} }
} }
return l > ol ? 1 : l == ol ? 0 : -1; return Integer.compare(l, ol);
} }
@Override @Override
......
...@@ -189,7 +189,7 @@ public class FreeSpaceTree { ...@@ -189,7 +189,7 @@ public class FreeSpaceTree {
@Override @Override
public int compareTo(BlockRange o) { public int compareTo(BlockRange o) {
return start < o.start ? -1 : start > o.start ? 1 : 0; return Integer.compare(start, o.start);
} }
@Override @Override
......
...@@ -30,7 +30,7 @@ public class TestSort extends TestBase { ...@@ -30,7 +30,7 @@ public class TestSort extends TestBase {
@Override @Override
public int compare(Long o1, Long o2) { public int compare(Long o1, Long o2) {
compareCount.incrementAndGet(); compareCount.incrementAndGet();
return Long.valueOf(o1 >> 32).compareTo(o2 >> 32); return Long.compare(o1 >> 32, o2 >> 32);
} }
}; };
......
...@@ -265,7 +265,7 @@ public class TestValue extends TestBase { ...@@ -265,7 +265,7 @@ public class TestValue extends TestBase {
values[i] = v; values[i] = v;
assertTrue(values[i].compareTypeSafe(values[i], null) == 0); assertTrue(values[i].compareTypeSafe(values[i], null) == 0);
assertTrue(v.equals(v)); assertTrue(v.equals(v));
assertEquals(i < 2 ? -1 : i > 2 ? 1 : 0, v.getSignum()); assertEquals(Integer.compare(i, 2), v.getSignum());
} }
for (int i = 0; i < d.length - 1; i++) { for (int i = 0; i < d.length - 1; i++) {
assertTrue(values[i].compareTypeSafe(values[i+1], null) < 0); assertTrue(values[i].compareTypeSafe(values[i+1], null) < 0);
......
...@@ -167,7 +167,7 @@ public class Indexer { ...@@ -167,7 +167,7 @@ public class Indexer {
Collections.sort(pages, new Comparator<Page>() { Collections.sort(pages, new Comparator<Page>() {
@Override @Override
public int compare(Page p0, Page p1) { public int compare(Page p0, Page p1) {
return p0.relations == p1.relations ? 0 : p0.relations < p1.relations ? 1 : -1; return Integer.compare(p1.relations, p0.relations);
} }
}); });
for (int i = 0; i < pages.size(); i++) { for (int i = 0; i < pages.size(); i++) {
......
...@@ -73,7 +73,7 @@ public class Word { ...@@ -73,7 +73,7 @@ public class Word {
Collections.sort(weightList, new Comparator<Weight>() { Collections.sort(weightList, new Comparator<Weight>() {
@Override @Override
public int compare(Weight w0, Weight w1) { public int compare(Weight w0, Weight w1) {
return w0.value < w1.value ? 1 : w0.value == w1.value ? 0 : -1; return Integer.compare(w1.value, w0.value);
} }
}); });
} }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论