@Override public List<PurgeableAnalysisDto> filter(List<PurgeableAnalysisDto> history) { List<PurgeableAnalysisDto> result = Lists.newArrayList(); for (PurgeableAnalysisDto snapshot : history) { if (snapshot.getDate().before(before)) { result.add(snapshot); } } return result; }
@Override public List<PurgeableAnalysisDto> filter(List<PurgeableAnalysisDto> history) { return history.stream() .filter(analysis -> analysis.getDate().before(before)) .filter(KeepWithVersionFilter::isDeletable) .collect(MoreCollectors.toList()); }
static List<Interval> group(List<PurgeableAnalysisDto> snapshots, Date start, Date end, int calendarField) { List<Interval> intervals = Lists.newArrayList(); GregorianCalendar calendar = new GregorianCalendar(); int lastYear = -1; int lastFieldValue = -1; Interval currentInterval = null; for (PurgeableAnalysisDto snapshot : snapshots) { if (!DateUtils.isSameDay(start, snapshot.getDate()) && snapshot.getDate().after(start) && (snapshot.getDate().before(end) || DateUtils.isSameDay(end, snapshot.getDate()))) { calendar.setTime(snapshot.getDate()); int currentFieldValue = calendar.get(calendarField); int currentYear = calendar.get(Calendar.YEAR); if (lastYear != currentYear || lastFieldValue != currentFieldValue) { currentInterval = new Interval(); intervals.add(currentInterval); } lastFieldValue = currentFieldValue; lastYear = currentYear; if (currentInterval != null) { currentInterval.add(snapshot); } } } return intervals; } }
private List<PurgeableAnalysisDto> delete(String rootUuid, List<PurgeableAnalysisDto> snapshots, DbSession session) { if (LOG.isDebugEnabled()) { LOG.debug("<- Delete analyses of component {}: {}", rootUuid, Joiner.on(", ").join( snapshots.stream() .map(snapshot -> snapshot.getAnalysisUuid() + "@" + DateUtils.formatDateTime(snapshot.getDate())) .collect(MoreCollectors.toArrayList(snapshots.size())))); } purgeDao.deleteAnalyses( session, profiler, snapshots.stream().map(DefaultPeriodCleaner::toIdUuidPair).collect(MoreCollectors.toList(snapshots.size()))); return snapshots; }
static int calendarField(Interval interval, int field) { if (interval.count() == 0) { return -1; } PurgeableAnalysisDto first = interval.get().iterator().next(); GregorianCalendar cal = new GregorianCalendar(); cal.setTime(first.getDate()); return cal.get(field); }
@Override public List<PurgeableAnalysisDto> filter(List<PurgeableAnalysisDto> history) { List<PurgeableAnalysisDto> result = Lists.newArrayList(); for (PurgeableAnalysisDto snapshot : history) { if (snapshot.getDate().before(before)) { result.add(snapshot); } } return result; }
static List<Interval> group(List<PurgeableAnalysisDto> snapshots, Date start, Date end, int calendarField) { List<Interval> intervals = Lists.newArrayList(); GregorianCalendar calendar = new GregorianCalendar(); int lastYear = -1; int lastFieldValue = -1; Interval currentInterval = null; for (PurgeableAnalysisDto snapshot : snapshots) { if (!DateUtils.isSameDay(start, snapshot.getDate()) && snapshot.getDate().after(start) && (snapshot.getDate().before(end) || DateUtils.isSameDay(end, snapshot.getDate()))) { calendar.setTime(snapshot.getDate()); int currentFieldValue = calendar.get(calendarField); int currentYear = calendar.get(Calendar.YEAR); if (lastYear != currentYear || lastFieldValue != currentFieldValue) { currentInterval = new Interval(); intervals.add(currentInterval); } lastFieldValue = currentFieldValue; lastYear = currentYear; if (currentInterval != null) { currentInterval.add(snapshot); } } } return intervals; } }
private List<PurgeableAnalysisDto> delete(String rootUuid, List<PurgeableAnalysisDto> snapshots, DbSession session) { if (LOG.isDebugEnabled()) { LOG.debug("<- Delete analyses of component {}: {}", rootUuid, Joiner.on(", ").join( snapshots.stream() .map(snapshot -> snapshot.getAnalysisUuid() + "@" + DateUtils.formatDateTime(snapshot.getDate())) .collect(Collectors.toArrayList(snapshots.size())))); } purgeDao.deleteAnalyses( session, profiler, snapshots.stream().map(DefaultPeriodCleaner::toIdUuidPair).collect(Collectors.toList(snapshots.size()))); return snapshots; }