未验证 提交 c8151668 编写于 作者: B Benedict Jin 提交者: GitHub

Use min or max method of Math to improve readability (#2103)

上级 93b367df
......@@ -316,7 +316,7 @@ public class MaxFileMergeFileSelector implements IMergeFileSelector {
long singleSeriesCost = calculateTightFileMemoryCost(seqFile, this::calculateMetadataSize);
long multiSeriesCost = concurrentMergeNum * singleSeriesCost;
long maxCost = calculateMetadataSize(seqFile);
return multiSeriesCost > maxCost ? maxCost : multiSeriesCost;
return Math.min(multiSeriesCost, maxCost);
}
// this method traverses all ChunkMetadata to find out which series has the most chunks and uses
......@@ -325,7 +325,7 @@ public class MaxFileMergeFileSelector implements IMergeFileSelector {
long singleSeriesCost = calculateTightFileMemoryCost(unseqFile, TsFileResource::getTsFileSize);
long multiSeriesCost = concurrentMergeNum * singleSeriesCost;
long maxCost = unseqFile.getTsFileSize();
return multiSeriesCost > maxCost ? maxCost : multiSeriesCost;
return Math.min(multiSeriesCost, maxCost);
}
@Override
......
......@@ -223,7 +223,7 @@ class MergeFileTask {
if (metaData.getStartTime() == startTime) {
Chunk chunk = reader.readMemChunk(metaData);
fileWriter.writeChunk(chunk, metaData);
maxVersion = metaData.getVersion() > maxVersion ? metaData.getVersion() : maxVersion;
maxVersion = Math.max(metaData.getVersion(), maxVersion);
context.incTotalPointWritten(metaData.getNumOfPoints());
break;
}
......
......@@ -47,7 +47,7 @@ public class BinaryTVList extends TVList {
checkExpansion();
int arrayIndex = size / ARRAY_SIZE;
int elementIndex = size % ARRAY_SIZE;
minTime = minTime <= timestamp ? minTime : timestamp;
minTime = Math.min(minTime, timestamp);
timestamps.get(arrayIndex)[elementIndex] = timestamp;
values.get(arrayIndex)[elementIndex] = value;
size++;
......
......@@ -46,7 +46,7 @@ public class BooleanTVList extends TVList {
checkExpansion();
int arrayIndex = size / ARRAY_SIZE;
int elementIndex = size % ARRAY_SIZE;
minTime = minTime <= timestamp ? minTime : timestamp;
minTime = Math.min(minTime, timestamp);
timestamps.get(arrayIndex)[elementIndex] = timestamp;
values.get(arrayIndex)[elementIndex] = value;
size++;
......
......@@ -47,7 +47,7 @@ public class DoubleTVList extends TVList {
checkExpansion();
int arrayIndex = size / ARRAY_SIZE;
int elementIndex = size % ARRAY_SIZE;
minTime = minTime <= timestamp ? minTime : timestamp;
minTime = Math.min(minTime, timestamp);
timestamps.get(arrayIndex)[elementIndex] = timestamp;
values.get(arrayIndex)[elementIndex] = value;
size++;
......
......@@ -48,7 +48,7 @@ public class FloatTVList extends TVList {
checkExpansion();
int arrayIndex = size / ARRAY_SIZE;
int elementIndex = size % ARRAY_SIZE;
minTime = minTime <= timestamp ? minTime : timestamp;
minTime = Math.min(minTime, timestamp);
timestamps.get(arrayIndex)[elementIndex] = timestamp;
values.get(arrayIndex)[elementIndex] = value;
size++;
......
......@@ -46,7 +46,7 @@ public class IntTVList extends TVList {
checkExpansion();
int arrayIndex = size / ARRAY_SIZE;
int elementIndex = size % ARRAY_SIZE;
minTime = minTime <= timestamp ? minTime : timestamp;
minTime = Math.min(minTime, timestamp);
timestamps.get(arrayIndex)[elementIndex] = timestamp;
values.get(arrayIndex)[elementIndex] = value;
size++;
......
......@@ -46,7 +46,7 @@ public class LongTVList extends TVList {
checkExpansion();
int arrayIndex = size / ARRAY_SIZE;
int elementIndex = size % ARRAY_SIZE;
minTime = minTime <= timestamp ? minTime : timestamp;
minTime = Math.min(minTime, timestamp);
timestamps.get(arrayIndex)[elementIndex] = timestamp;
values.get(arrayIndex)[elementIndex] = value;
size++;
......
......@@ -187,7 +187,7 @@ public abstract class TVList {
long time = getTime(i);
if (time < lowerBound || time > upperBound) {
set(i, newSize++);
minTime = time < minTime ? time : minTime;
minTime = Math.min(time, minTime);
}
}
int deletedNumber = size - newSize;
......@@ -245,7 +245,7 @@ public abstract class TVList {
abstract void clearValue();
/**
* The arrays for sorting are not including in write memory now,
* The arrays for sorting are not including in write memory now,
* the memory usage is considered as temporary memory.
*/
abstract void clearSortedValue();
......@@ -452,12 +452,12 @@ public abstract class TVList {
long inPutMinTime = Long.MAX_VALUE;
boolean inputSorted = true;
for (int i = start; i < end; i++) {
inPutMinTime = inPutMinTime <= time[i] ? inPutMinTime : time[i];
inPutMinTime = Math.min(inPutMinTime, time[i]);
if (inputSorted && i < length - 1 && time[i] > time[i + 1]) {
inputSorted = false;
}
}
minTime = inPutMinTime < minTime ? inPutMinTime : minTime;
minTime = Math.min(inPutMinTime, minTime);
sorted = sorted && inputSorted && (size == 0 || inPutMinTime >= getTime(size - 1));
}
......
......@@ -44,7 +44,7 @@ public class ReadWriteForEncodingUtils {
int max = 1;
for (int num : list) {
int bitWidth = 32 - Integer.numberOfLeadingZeros(num);
max = bitWidth > max ? bitWidth : max;
max = Math.max(bitWidth, max);
}
return max;
}
......@@ -59,7 +59,7 @@ public class ReadWriteForEncodingUtils {
int max = 1;
for (long num : list) {
int bitWidth = 64 - Long.numberOfLeadingZeros(num);
max = bitWidth > max ? bitWidth : max;
max = Math.max(bitWidth, max);
}
return max;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册