@Override public void apply(String key) { V firstValue = a.getAnnotation(start, key); int firstStart; firstStart = a.lastAnnotationChange(0, start, key, firstValue); if (firstStart == -1) { firstStart = 0; } int firstEnd; firstEnd = a.firstAnnotationChange(start, a.size(), key, firstValue); if (firstEnd == -1) { firstEnd = a.size(); } entries.add(new KeyEntry<V>(key, firstStart, firstEnd, firstValue)); } });
@Override public RangedAnnotation<V> next() { if (!hasNext()) { throw new NoSuchElementException("No more ranged annotations"); } KeyEntry<V> entry = entries.remove(); if (rangedAnnotation == null) { rangedAnnotation = new RangedAnnotationImpl<V>(entry.key, entry.value, entry.start, entry.end); } else { rangedAnnotation.set(entry.key, entry.value, entry.start, entry.end); } entry.start = entry.end; if (entry.start < end) { entry.value = a.getAnnotation(entry.start, entry.key); entry.end = a.firstAnnotationChange(entry.start, a.size(), entry.key, entry.value); if (entry.end == -1) { entry.end = a.size(); } entries.add(entry); } return rangedAnnotation; }
public GenericRangedAnnotationIterator(final ReadableAnnotationSet<V> a, final int start, int end, ReadableStringSet keys) { Preconditions.checkPositionIndexes(start, end, a.size()); Preconditions.checkNotNull(keys, "GenericRangedAnnotationIterator: Key set must not be null"); this.a = a; this.end = end; if (start >= end) { // entries remains empty. return; } keys.each(new Proc() { @Override public void apply(String key) { V firstValue = a.getAnnotation(start, key); int firstStart; firstStart = a.lastAnnotationChange(0, start, key, firstValue); if (firstStart == -1) { firstStart = 0; } int firstEnd; firstEnd = a.firstAnnotationChange(start, a.size(), key, firstValue); if (firstEnd == -1) { firstEnd = a.size(); } entries.add(new KeyEntry<V>(key, firstStart, firstEnd, firstValue)); } }); }
/** * The range values have the same meaning as the annotation set interfaces. * * @param annotations annotation set * @param start start of the range * @param end end of the range * @param keys key set for which to search for changes */ public GenericAnnotationCursor(ReadableAnnotationSet<V> annotations, final int start, int end, ReadableStringSet keys) { Preconditions.checkPositionIndexes(start, end, annotations.size()); Preconditions.checkNotNull(keys, "GenericAnnotationCursor: Key set must not be null"); this.annotations = annotations; this.end = end; keys.each(new Proc() { @Override public void apply(String key) { advance(new KeyLocation(key, start)); } }); this.currentLocation = hasNext() ? start : -1; }
void performRandomQuery(ReadableAnnotationSet<Object> a, String[] keys, Random random) { if (a.size() > 0) { int start = random.nextInt(a.size()); int end = 1 + random.nextInt(a.size()); if (start > end) { int swap = start; start = end; end = swap; } for (String key : keys) { a.firstAnnotationChange(start, end, key, "foo"); a.lastAnnotationChange(start, end, key, "foo"); Object value = a.getAnnotation(start, key); a.firstAnnotationChange(start, end, key, value); a.lastAnnotationChange(start, end, key, value); value = a.getAnnotation(end - 1, key); a.firstAnnotationChange(start, end, key, value); a.lastAnnotationChange(start, end, key, value); } } }
void performRandomQuery(ReadableAnnotationSet<Object> a, String[] keys, Random random) { if (a.size() > 0) { int start = random.nextInt(a.size()); int end = 1 + random.nextInt(a.size()); if (start > end) { int swap = start; start = end; end = swap; } for (String key : keys) { a.firstAnnotationChange(start, end, key, "foo"); a.lastAnnotationChange(start, end, key, "foo"); Object value = a.getAnnotation(start, key); a.firstAnnotationChange(start, end, key, value); a.lastAnnotationChange(start, end, key, value); value = a.getAnnotation(end - 1, key); a.firstAnnotationChange(start, end, key, value); a.lastAnnotationChange(start, end, key, value); } } }
public GenericAnnotationIntervalIterator(final ReadableAnnotationSet<V> set, final int start, final int end, ReadableStringSet keys) { Preconditions.checkPositionIndexes(start, end, set.size()); Preconditions.checkNotNull(keys, "GenericAnnotationIntervalIterator: Key set must not be null");