cleaning up the mess with inclusive/exclusive time interval ends

Change-Id: Ie7753c053d96b0a2c66a98d7e0e983bba38cfd20
This commit is contained in:
Axel Uhl committed 2016-12-23 23:43:29 +01:00
1 parent d4479a3bc1
commit 2aba829548
11 files changed
+51 -34

No files matched your search

@@ -13,18 +13,18 @@ public class RegattaLogCloseOpenEndedDeviceMappingEventImpl extends AbstractLogE
private static final long serialVersionUID = -5114645637316367845L;
private final Serializable deviceMappingEventId;
private final TimePoint closingTimePoint;
private final TimePoint closingTimePointInclusive;
public RegattaLogCloseOpenEndedDeviceMappingEventImpl(TimePoint createdAt, AbstractLogEventAuthor author, TimePoint logicalTimePoint,
Serializable pId, Serializable deviceMappingEventId, TimePoint closingTimePoint) {
Serializable pId, Serializable deviceMappingEventId, TimePoint closingTimePointInclusive) {
super(createdAt, logicalTimePoint, author, pId);
this.deviceMappingEventId = deviceMappingEventId;
this.closingTimePoint = closingTimePoint;
this.closingTimePointInclusive = closingTimePointInclusive;
}
public RegattaLogCloseOpenEndedDeviceMappingEventImpl(TimePoint logicalTimePoint, AbstractLogEventAuthor author,
Serializable deviceMappingEventId, TimePoint closingTimePoint) {
this( now(), author, logicalTimePoint, randId(), deviceMappingEventId, closingTimePoint);
Serializable deviceMappingEventId, TimePoint closingTimePointInclusive) {
this(now(), author, logicalTimePoint, randId(), deviceMappingEventId, closingTimePointInclusive);
}
@Override
@@ -34,12 +34,12 @@ public class RegattaLogCloseOpenEndedDeviceMappingEventImpl extends AbstractLogE
@Override
public TimePoint getClosingTimePointInclusive() {
return closingTimePoint;
return closingTimePointInclusive;
}
@Override
public String getShortInfo() {
return "closing mapping (id: " + deviceMappingEventId + ") at " + closingTimePoint;
return "closing mapping (id: " + deviceMappingEventId + ") at " + closingTimePointInclusive;
}
@Override
@@ -52,7 +52,7 @@ public abstract class BaseRegattaLogDeviceMappingFinder<ItemT extends WithID>
final TimePoint from = event.getFrom();
final RegattaLogCloseOpenEndedDeviceMappingEvent closingEvent = closingEvents.get(event.getId());
final TimePoint toInclusive = closingEvent != null ? closingEvent.getClosingTimePointInclusive() : event.getToInclusive();
final TimeRange mappingTimeRange = new TimeRangeImpl(from, toInclusive.plus(1) /* convert from inclusive to exclusive end */);
final TimeRange mappingTimeRange = new TimeRangeImpl(from, toInclusive, /* inclusive */ true);
if (mappingTimeRange.includes(fixTimePoint)) {
if (closingEvent != null) {
log.revokeEvent(closingEvent.getAuthor(), closingEvent,
@@ -49,7 +49,7 @@ public class RegattaLogDeviceMappingFinder<ItemT extends WithID>
protected DeviceMappingWithRegattaLogEvent<ItemT> createMapping(DeviceIdentifier device, ItemT item,
TimePoint from, TimePoint toInclusive, Serializable originalEventId, RegattaLogDeviceMappingEvent<ItemT> event) {
return new DeviceMappingWithRegattaLogEventImpl<ItemT>(item, device, new TimeRangeImpl(from, toInclusive.plus(1) /* TimeRange uses exclusive end */),
return new DeviceMappingWithRegattaLogEventImpl<ItemT>(item, device, new TimeRangeImpl(from, toInclusive, /* inclusive */ true),
Collections.singletonList(originalEventId), event);
}
@@ -96,13 +96,13 @@ public class RegattaLogDeviceMappingFinder<ItemT extends WithID>
for (final RegattaLogDeviceMappingEvent<ItemT> event : events) {
TimePoint from = event.getFrom();
TimePoint toInclusive = event.getToInclusive();
TimePoint closingTimePoint = closingEvents.containsKey(event.getId()) ? closingEvents.get(event.getId())
TimePoint closingTimePointInclusive = closingEvents.containsKey(event.getId()) ? closingEvents.get(event.getId())
.getClosingTimePointInclusive() : null;
if (from == null) {
logger.severe("No start time set for DeviceMappingEvent with ID: " + event.getId());
}
if (toInclusive == null) {
toInclusive = closingTimePoint;
toInclusive = closingTimePointInclusive;
}
result.add(createMapping(event.getDevice(), item, from, toInclusive, event.getId(), event));
}
@@ -24,20 +24,20 @@ public class RegattaLogOpenEndedDeviceMappingCloser extends
RegattaLogAnalyzer<List<RegattaLogCloseOpenEndedDeviceMappingEvent>> {
private final DeviceMapping<?> mapping;
protected final AbstractLogEventAuthor author;
protected final TimePoint closingTimePoint;
protected final TimePoint closingTimePointInclusive;
public RegattaLogOpenEndedDeviceMappingCloser(RegattaLog log, DeviceMapping<?> mapping,
AbstractLogEventAuthor author, TimePoint closingTimePoint) {
AbstractLogEventAuthor author, TimePoint closingTimePointInclusive) {
super(log);
this.mapping = mapping;
this.author = author;
this.closingTimePoint = closingTimePoint;
this.closingTimePointInclusive = closingTimePointInclusive;
}
protected RegattaLogCloseOpenEndedDeviceMappingEvent createCloseEvent(TimePoint logicalTimePoint,
Serializable eventToCloseId) {
return new RegattaLogCloseOpenEndedDeviceMappingEventImpl(logicalTimePoint, author, eventToCloseId,
closingTimePoint);
closingTimePointInclusive);
}
@Override
@@ -67,7 +67,7 @@ public class DeviceMappingImpl<ItemType extends WithID> implements DeviceMapping
public static <T extends WithID> DeviceMapping<T> convertToDeviceMapping(RegattaLogDeviceMappingEvent<T> event) {
return new DeviceMappingImpl<T>(event.getMappedTo(), event.getDevice(),
new TimeRangeImpl(event.getFrom(), event.getToInclusive().plus(1) /* TimeRange uses exclusive end */),
new TimeRangeImpl(event.getFrom(), event.getToInclusive(), /* inclusive */ true),
event.getId(), event.getClass());
}