use of de.invesdwin.util.collections.iterable.buffer.BufferingIterator in project invesdwin-context-persistence by subes.
the class HeapLiveSegment method rangeReverseValues.
@Override
public ICloseableIterable<V> rangeReverseValues(final FDate from, final FDate to, final Lock readLock, final ISkipFileFunction skipFileFunction) {
// we expect the read lock to be already locked from the outside
if (values == null || from != null && to != null && from.isBeforeNotNullSafe(to)) {
return EmptyCloseableIterable.getInstance();
}
if (from != null && !firstValue.isEmpty() && from.isBeforeOrEqualToNotNullSafe(firstValueKey)) {
if (from.isBeforeNotNullSafe(firstValueKey)) {
return EmptyCloseableIterable.getInstance();
} else {
return firstValue.snapshot();
}
}
if (to != null && !lastValue.isEmpty() && to.isAfterOrEqualToNotNullSafe(lastValueKey)) {
if (to.isAfterNotNullSafe(lastValueKey)) {
return EmptyCloseableIterable.getInstance();
} else {
return lastValue.snapshot();
}
}
final SortedMap<Long, V> headMap;
if (from == null) {
headMap = values.descendingMap();
} else {
headMap = values.descendingMap().tailMap(from.millisValue(), true);
}
final ICloseableIterable<Entry<Long, V>> tail = WrapperCloseableIterable.maybeWrap(headMap.entrySet());
final ICloseableIterable<Entry<Long, V>> skipping;
if (to == null) {
skipping = tail;
} else {
skipping = new ASkippingIterable<Entry<Long, V>>(tail) {
@Override
protected boolean skip(final Entry<Long, V> element) {
if (element.getKey() < to.millisValue()) {
throw new FastNoSuchElementException("LiveSegment rangeReverseValues end reached");
}
return false;
}
};
}
final ATransformingIterable<Entry<Long, V>, V> transforming = new ATransformingIterable<Entry<Long, V>, V>(skipping) {
@Override
protected V transform(final Entry<Long, V> value) {
return value.getValue();
}
};
if (readLock == DisabledLock.INSTANCE) {
return transforming;
} else {
// we expect the read lock to be already locked from the outside
return new BufferingIterator<>(transforming);
}
}
use of de.invesdwin.util.collections.iterable.buffer.BufferingIterator in project invesdwin-context-persistence by subes.
the class HeapLiveSegment method rangeValues.
@Override
public ICloseableIterable<V> rangeValues(final FDate from, final FDate to, final Lock readLock, final ISkipFileFunction skipFileFunction) {
// we expect the read lock to be already locked from the outside
if (values == null || from != null && to != null && from.isAfterNotNullSafe(to)) {
return EmptyCloseableIterable.getInstance();
}
if (from != null && !lastValue.isEmpty() && from.isAfterOrEqualToNotNullSafe(lastValueKey)) {
if (from.isAfterNotNullSafe(lastValueKey)) {
return EmptyCloseableIterable.getInstance();
} else {
return lastValue.snapshot();
}
}
if (to != null && !firstValue.isEmpty() && to.isBeforeOrEqualToNotNullSafe(firstValueKey)) {
if (to.isBeforeNotNullSafe(firstValueKey)) {
return EmptyCloseableIterable.getInstance();
} else {
return firstValue.snapshot();
}
}
final SortedMap<Long, V> tailMap;
if (from == null) {
tailMap = values;
} else {
tailMap = values.tailMap(from.millisValue(), true);
}
final ICloseableIterable<Entry<Long, V>> tail = WrapperCloseableIterable.maybeWrap(tailMap.entrySet());
final ICloseableIterable<Entry<Long, V>> skipping;
if (to == null) {
skipping = tail;
} else {
skipping = new ASkippingIterable<Entry<Long, V>>(tail) {
@Override
protected boolean skip(final Entry<Long, V> element) {
if (element.getKey() > to.millisValue()) {
throw new FastNoSuchElementException("LiveSegment rangeValues end reached");
}
return false;
}
};
}
final ATransformingIterable<Entry<Long, V>, V> transforming = new ATransformingIterable<Entry<Long, V>, V>(skipping) {
@Override
protected V transform(final Entry<Long, V> value) {
return value.getValue();
}
};
if (readLock == DisabledLock.INSTANCE) {
return transforming;
} else {
// we expect the read lock to be already locked from the outside
return new BufferingIterator<>(transforming);
}
}
Aggregations