我在使用此代码时遇到问题,我正在尝试使用谓词进行重构并具有更好的可读性。我有两个长度不一的点列表(其中有一个值,一个日期和一个布尔值不可用),长度不一,而缺少点只能在较短列表的开头。我想在较短列表的开头添加与较长日期相同的缺失点。
public class Point{
private int value;
private ZoneDateTime Date;
private boolean unavailability;
}
Point firstPoint = Point (10, "10/10/2019");
Point secondPoint = Point (10, "10/11/2019");
Point thirdPoint = Point (10, "10/12/2019");
Point unavailable = Point(null, null, true);
List<Point> firstCurve = new ArrayList<>();
firstCurve.add(firstPoint);
firstCurve.add(secondPoint);
firstCurve.add(thirdPoint);
List<Point> secondCurve = new ArrayList<>();
secondCurve.add(thirdPoint);
List<Point> completeList = new ArrayList<>();
for (Point p : firstCurve) {
if (p.getDate().compareTo(secondCurve.get(0).getDate()) < 0) {
/* Put the unavailable point at the begining with the flag unavailability */
unavailable.setDate(p.getDate());
unavailable.setPas(p.getPas());
completeList.add(unavailable);
} else {
/* If there is data, copy in the new list */
for (Point ptCourt : secondCurve) {
completeList.add(ptCourt);
}
}
}