mirror of
https://github.com/eclipse-sailing-analytics/sailing-analytics.git
synced 2026-09-21 21:25:38 +00:00
use exactly one validator in FilteredPartialNavigableSetView
This commit is contained in:
-8
@@ -46,10 +46,8 @@ public class FinishedTimeFinderTest extends PassAwareRaceLogAnalyzerTest<Finishe
|
||||
when(event1.getNextStatus()).thenReturn(RaceLogRaceStatus.FINISHED);
|
||||
RaceLogRaceStatusEvent event2 = createEvent(RaceLogRaceStatusEvent.class, 2);
|
||||
when(event2.getNextStatus()).thenReturn(RaceLogRaceStatus.FINISHED);
|
||||
|
||||
raceLog.add(event1);
|
||||
raceLog.add(event2);
|
||||
|
||||
assertEquals(event2.getLogicalTimePoint(), analyzer.analyze());
|
||||
}
|
||||
|
||||
@@ -59,10 +57,8 @@ public class FinishedTimeFinderTest extends PassAwareRaceLogAnalyzerTest<Finishe
|
||||
when(event1.getNextStatus()).thenReturn(RaceLogRaceStatus.FINISHED);
|
||||
RaceLogRaceStatusEvent event2 = createEvent(RaceLogRaceStatusEvent.class, 2);
|
||||
when(event2.getNextStatus()).thenReturn(RaceLogRaceStatus.FINISHING);
|
||||
|
||||
raceLog.add(event1);
|
||||
raceLog.add(event2);
|
||||
|
||||
assertEquals(event1.getLogicalTimePoint(), analyzer.analyze());
|
||||
}
|
||||
|
||||
@@ -73,10 +69,8 @@ public class FinishedTimeFinderTest extends PassAwareRaceLogAnalyzerTest<Finishe
|
||||
RaceLogRevokeEvent revokeEvent = createEvent(RaceLogRevokeEvent.class,2);
|
||||
final Serializable id = event1.getId();
|
||||
when(revokeEvent.getRevokedEventId()).thenReturn(id);
|
||||
|
||||
raceLog.add(event1);
|
||||
raceLog.add(revokeEvent);
|
||||
|
||||
assertNull(analyzer.analyze());
|
||||
}
|
||||
|
||||
@@ -92,7 +86,6 @@ public class FinishedTimeFinderTest extends PassAwareRaceLogAnalyzerTest<Finishe
|
||||
raceLog.add(event1);
|
||||
raceLog.add(revokeEvent);
|
||||
raceLog.add(event2);
|
||||
|
||||
assertSame(event2.getLogicalTimePoint(), analyzer.analyze());
|
||||
}
|
||||
|
||||
@@ -108,7 +101,6 @@ public class FinishedTimeFinderTest extends PassAwareRaceLogAnalyzerTest<Finishe
|
||||
raceLog.add(event1);
|
||||
raceLog.add(revokeEvent);
|
||||
raceLog.add(event2);
|
||||
|
||||
assertSame(event2, analyzer.findFinishedEvent());
|
||||
}
|
||||
}
|
||||
|
||||
-8
@@ -45,10 +45,8 @@ public class FinishingTimeFinderTest extends PassAwareRaceLogAnalyzerTest<Finish
|
||||
when(event1.getNextStatus()).thenReturn(RaceLogRaceStatus.FINISHING);
|
||||
RaceLogRaceStatusEvent event2 = createEvent(RaceLogRaceStatusEvent.class, 2);
|
||||
when(event2.getNextStatus()).thenReturn(RaceLogRaceStatus.FINISHING);
|
||||
|
||||
raceLog.add(event1);
|
||||
raceLog.add(event2);
|
||||
|
||||
assertSame(event2.getLogicalTimePoint(), analyzer.analyze());
|
||||
}
|
||||
|
||||
@@ -58,10 +56,8 @@ public class FinishingTimeFinderTest extends PassAwareRaceLogAnalyzerTest<Finish
|
||||
when(event1.getNextStatus()).thenReturn(RaceLogRaceStatus.FINISHING);
|
||||
RaceLogRaceStatusEvent event2 = createEvent(RaceLogRaceStatusEvent.class, 2);
|
||||
when(event2.getNextStatus()).thenReturn(RaceLogRaceStatus.FINISHED);
|
||||
|
||||
raceLog.add(event1);
|
||||
raceLog.add(event2);
|
||||
|
||||
assertSame(event1.getLogicalTimePoint(), analyzer.analyze());
|
||||
}
|
||||
|
||||
@@ -72,10 +68,8 @@ public class FinishingTimeFinderTest extends PassAwareRaceLogAnalyzerTest<Finish
|
||||
RaceLogRevokeEvent revokeEvent = createEvent(RaceLogRevokeEvent.class,2);
|
||||
final Serializable id = event1.getId();
|
||||
when(revokeEvent.getRevokedEventId()).thenReturn(id);
|
||||
|
||||
raceLog.add(event1);
|
||||
raceLog.add(revokeEvent);
|
||||
|
||||
assertNull(analyzer.analyze());
|
||||
}
|
||||
|
||||
@@ -91,7 +85,6 @@ public class FinishingTimeFinderTest extends PassAwareRaceLogAnalyzerTest<Finish
|
||||
raceLog.add(event1);
|
||||
raceLog.add(revokeEvent);
|
||||
raceLog.add(event2);
|
||||
|
||||
assertSame(event2.getLogicalTimePoint(), analyzer.analyze());
|
||||
}
|
||||
|
||||
@@ -107,7 +100,6 @@ public class FinishingTimeFinderTest extends PassAwareRaceLogAnalyzerTest<Finish
|
||||
raceLog.add(event1);
|
||||
raceLog.add(revokeEvent);
|
||||
raceLog.add(event2);
|
||||
|
||||
assertSame(event2, analyzer.findFinishingEvent());
|
||||
}
|
||||
|
||||
|
||||
+10
-17
@@ -3,13 +3,11 @@ package com.sap.sailing.domain.abstractlog.impl;
|
||||
import java.io.IOException;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.NavigableSet;
|
||||
import java.util.Set;
|
||||
@@ -316,16 +314,12 @@ extends TrackImpl<EventT> implements AbstractLog<EventT, VisitorT> {
|
||||
|
||||
@Override
|
||||
public NavigableSet<EventT> getUnrevokedEvents() {
|
||||
final List<NavigableSetViewValidator<EventT>> validators = new ArrayList<>();
|
||||
validators.add(new RevokedValidator<>(revokedEventIds));
|
||||
return new FilteredPartialNavigableSetView<>(super.getInternalFixes(), validators);
|
||||
return new FilteredPartialNavigableSetView<>(super.getInternalFixes(), new RevokedValidator<>(revokedEventIds));
|
||||
}
|
||||
|
||||
@Override
|
||||
public NavigableSet<EventT> getUnrevokedEventsDescending() {
|
||||
final List<NavigableSetViewValidator<EventT>> validators = new ArrayList<>();
|
||||
validators.add(new RevokedValidator<>(revokedEventIds));
|
||||
return new FilteredPartialNavigableSetView<EventT>(super.getInternalFixes().descendingSet(), validators);
|
||||
return new FilteredPartialNavigableSetView<EventT>(super.getInternalFixes().descendingSet(), new RevokedValidator<>(revokedEventIds));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -389,6 +383,7 @@ extends TrackImpl<EventT> implements AbstractLog<EventT, VisitorT> {
|
||||
add(revokeEvent);
|
||||
}
|
||||
|
||||
@FunctionalInterface
|
||||
public interface NavigableSetViewValidator<T> {
|
||||
boolean isValid(T item);
|
||||
}
|
||||
@@ -407,21 +402,19 @@ extends TrackImpl<EventT> implements AbstractLog<EventT, VisitorT> {
|
||||
}
|
||||
|
||||
public static class FilteredPartialNavigableSetView<T> extends PartialNavigableSetView<T> {
|
||||
private final List<NavigableSetViewValidator<T>> validators;
|
||||
private final NavigableSetViewValidator<T> validator;
|
||||
|
||||
public FilteredPartialNavigableSetView(NavigableSet<T> set, final List<NavigableSetViewValidator<T>> validators) {
|
||||
public FilteredPartialNavigableSetView(NavigableSet<T> set, final NavigableSetViewValidator<T> validator) {
|
||||
super(set);
|
||||
this.validators = validators;
|
||||
if (validator == null) {
|
||||
throw new NullPointerException();
|
||||
}
|
||||
this.validator = validator;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isValid(T t) {
|
||||
for (NavigableSetViewValidator<T> validator : validators) {
|
||||
if (!validator.isValid(t)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
return validator.isValid(t);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+4
-10
@@ -1,5 +1,7 @@
|
||||
package com.sap.sailing.domain.abstractlog.race.analyzing.impl;
|
||||
|
||||
import java.util.ConcurrentModificationException;
|
||||
|
||||
import com.sap.sailing.domain.abstractlog.BaseLogAnalyzer;
|
||||
import com.sap.sailing.domain.abstractlog.impl.AbstractLogImpl;
|
||||
import com.sap.sailing.domain.abstractlog.race.RaceLog;
|
||||
@@ -7,10 +9,6 @@ import com.sap.sailing.domain.abstractlog.race.RaceLogEvent;
|
||||
import com.sap.sailing.domain.abstractlog.race.RaceLogEventVisitor;
|
||||
import com.sap.sailing.domain.tracking.Track;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.ConcurrentModificationException;
|
||||
import java.util.List;
|
||||
|
||||
public abstract class RaceLogAnalyzer<ResultType> extends BaseLogAnalyzer
|
||||
<RaceLog, RaceLogEvent, RaceLogEventVisitor, ResultType> {
|
||||
|
||||
@@ -42,9 +40,7 @@ public abstract class RaceLogAnalyzer<ResultType> extends BaseLogAnalyzer
|
||||
* {@link ConcurrentModificationException}s.
|
||||
*/
|
||||
protected Iterable<RaceLogEvent> getPassUnrevokedEvents() {
|
||||
final List<AbstractLogImpl.NavigableSetViewValidator<RaceLogEvent>> validators = new ArrayList<>();
|
||||
validators.add(new RaceLog.PassValidator(log.getCurrentPassId()));
|
||||
return new AbstractLogImpl.FilteredPartialNavigableSetView<>(log.getUnrevokedEvents(), validators);
|
||||
return new AbstractLogImpl.FilteredPartialNavigableSetView<>(log.getUnrevokedEvents(), new RaceLog.PassValidator(log.getCurrentPassId()));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -53,8 +49,6 @@ public abstract class RaceLogAnalyzer<ResultType> extends BaseLogAnalyzer
|
||||
* {@link ConcurrentModificationException}s.
|
||||
*/
|
||||
protected Iterable<RaceLogEvent> getPassUnrevokedEventsDescending() {
|
||||
final List<AbstractLogImpl.NavigableSetViewValidator<RaceLogEvent>> validators = new ArrayList<>();
|
||||
validators.add(new RaceLog.PassValidator(log.getCurrentPassId()));
|
||||
return new AbstractLogImpl.FilteredPartialNavigableSetView<>(log.getUnrevokedEventsDescending(), validators);
|
||||
return new AbstractLogImpl.FilteredPartialNavigableSetView<>(log.getUnrevokedEventsDescending(), new RaceLog.PassValidator(log.getCurrentPassId()));
|
||||
}
|
||||
}
|
||||
|
||||
+1
-12
@@ -1,8 +1,6 @@
|
||||
package com.sap.sailing.domain.abstractlog.race.impl;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.NavigableSet;
|
||||
|
||||
import com.sap.sailing.domain.abstractlog.AbstractLogEventAuthor;
|
||||
@@ -53,11 +51,6 @@ public class RaceLogImpl extends AbstractLogImpl<RaceLogEvent, RaceLogEventVisit
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onSuccessfulAdd(RaceLogEvent event, boolean notifyListeners) {
|
||||
super.onSuccessfulAdd(event, notifyListeners);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected RaceLogEvent createRevokeEvent(AbstractLogEventAuthor author, RaceLogEvent toRevoke, String reason) {
|
||||
return new RaceLogRevokeEventImpl(author, getCurrentPassId(), toRevoke, reason);
|
||||
@@ -65,10 +58,6 @@ public class RaceLogImpl extends AbstractLogImpl<RaceLogEvent, RaceLogEventVisit
|
||||
|
||||
@Override
|
||||
protected NavigableSet<RaceLogEvent> getInternalFixes() {
|
||||
final List<NavigableSetViewValidator<RaceLogEvent>> validators = new ArrayList<>();
|
||||
validators.add(new PassValidator(getCurrentPassId()));
|
||||
return new FilteredPartialNavigableSetView<>(super.getInternalFixes(), validators);
|
||||
return new FilteredPartialNavigableSetView<>(super.getInternalFixes(), new PassValidator(getCurrentPassId()));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user