Created
November 15, 2021 10:10
-
-
Save 330132662/064d760a2107d4aef01c25ffc148cc83 to your computer and use it in GitHub Desktop.
动态步长的for循环
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* if batch> 当天的数据条数,则全部取出来 | |
* else if batch=1 ,则取当天的最后一条数据。 | |
* else 将每一天的数据按照batch均匀条数间隔取出来: 有100条 取batch条,即第49和 99 条(索引起始为0 ) , | |
*/ | |
for (int i = 0; i < everyDayData.size(); i++) { | |
if (currentBatch == 1) { | |
/*根据日期 拿到对应日期的数据 */ //还需要区分不同的测点! | |
List<PointData.DataBean.RowsBean> datas = everyDayData.get(pointDataDateList.get(i)); | |
/*遍历多个测点 */ | |
int size = datas.size(); | |
PointData.DataBean.RowsBean lastPoint = null; | |
for (int point = 0; point < size; point++) { | |
PointData.DataBean.RowsBean pointBean = datas.get(point); | |
if (lastPoint == null) { | |
mPointDataList.add(pointBean); | |
} | |
if (lastPoint != null && lastPoint.getPoint_id() != pointBean.getPoint_id()) { | |
mPointDataList.add(pointBean); | |
} | |
lastPoint = pointBean; | |
} | |
} else if (currentBatch > dayDateList.size()) { | |
mPointDataList.addAll(everyDayData.get(pointDataDateList.get(i))); | |
} else { | |
// 取batch条,即第49和 99 条(索引起始为0 ) , | |
int dayDateListSize = dayDateList.size(); | |
int step = dayDateListSize / currentBatch;// 间隔 | |
int start = 0; | |
if (step > 0) { | |
start = step - 1; | |
} | |
for (int s = start; s < dayDateListSize; s += step) { | |
mPointDataList.add(everyDayData.get(pointDataDateList.get(i)).get(s)); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment