@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)); } });
/** * Advance the given key location to its next value change and set its * location. If it has one, place it back in the queue. If not (location == * -1), do not place it back in the queue. * * @param keyLocation */ private void advance(KeyLocation keyLocation) { V val = annotations.getAnnotation(keyLocation.location, keyLocation.key); keyLocation.location = annotations.firstAnnotationChange(keyLocation.location, end, keyLocation.key, val); if (keyLocation.location != -1) { locations.add(keyLocation); } } }
@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 same as {@link ReadableAnnotationSet#lastAnnotationChange(int, int, String, Object)}, * except that it returns {@code start} instead of -1 if there is no change */ public static <V> int lastAnnotationBoundary(ReadableAnnotationSet<V> annotations, int start, int end, String key, V fromValue) { int ret = annotations.lastAnnotationChange(start, end, key, fromValue); return ret != -1 ? ret : start; }
/** * The same as {@link ReadableAnnotationSet#firstAnnotationChange(int, int, String, Object)}, * except that it returns {@code end} instead of -1 if there is no change */ public static <V> int firstAnnotationBoundary(ReadableAnnotationSet<V> annotations, int start, int end, String key, V fromValue) { int ret = annotations.firstAnnotationChange(start, end, key, fromValue); return ret != -1 ? ret : end; }
@Override public void apply(String key) { V startValue = set.getAnnotation(start, key); V valueLeft; if (start == 0) { valueLeft = null; } else { valueLeft = set.getAnnotation(start - 1, key); } if (valuesEqual(valueLeft, startValue)) { // no entry in diffFromLeft } else { diffFromLeft.put(key, startValue); } annotationsHere.put(key, startValue); int nextChange = set.firstAnnotationChange(start, end, key, startValue); if (nextChange == -1) { // don't add } else { entries.add(new KeyEntry(key, nextChange)); } } });
/** * 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); } } }
assert thisIntervalStart == entry.nextChange; String key = entry.key; V value = set.getAnnotation(thisIntervalStart, key); diffFromLeft.put(key, value); annotationsHere.put(key, value); entry.nextChange = set.firstAnnotationChange(thisIntervalStart + 1, end, key, value); if (entry.nextChange != -1) { entries.add(entry);
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");
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); } } }