/** * Convenience method for adding an annotation to this span, same as * <code>getSpanTree().{@link SpanTree#annotate(SpanNode,Annotation) spanTree.annotate(this,annotation)}</code> * * @param annotation the annotation to add * @return this for chaining * @throws NullPointerException if this span is not attached to a tree */ public SpanNode annotate(Annotation annotation) { getNonNullSpanTree().annotate(this, annotation); return this; }
private void clearIndex() { AnnotationContainer tmpAnnotations = new ListAnnotationContainer(); tmpAnnotations.annotateAll(annotations.annotations()); annotations = tmpAnnotations; }
@Override public void setAnnotationType(AnnotationType type) { super.setName("annotationreference<" + type.getName() + ">"); super.setAnnotationType(type); } }
/** * Creates an AnnotationReferenceDataType with a generated id. * * @param aType the annotation type that AnnotationRefs shall refer to. */ public AnnotationReferenceDataType(AnnotationType aType) { super("annotationreference<" + ((aType == null) ? "" : aType.getName()) + ">", 0); setAnnotationType(aType); }
/** * Adds an Annotation. * Convenience shorthand for <code>annotate(node,new Annotation(type,value)</code> * * @param node the node to annotate * @param type the type of the Annotation to add * @param value the value of the Annotation to add * @return this, for chaining * @see com.yahoo.document.annotation.Annotation */ public SpanTree annotate(SpanNode node, AnnotationType type,FieldValue value) { return annotate(node, new Annotation(type, value)); }
/** * Recursively traverses all children (not only leaf nodes) of this SpanList, in a depth-first fashion. * The ListIterator only supports iteration forwards, and the optional operations that are implemented are * remove() and set(). add() is not supported. * * @return a ListIterator which recursively traverses all children and their children etc. of this SpanList. * @see java.util.ListIterator */ @Override public ListIterator<SpanNode> childIteratorRecursive() { return new InvalidatingIterator(this, new RecursiveNodeIterator(children().listIterator())); }
void setInvalid() { //invalidate ourselves: super.setInvalid(); //invalidate all our children: for (SpanNode node : children()) { node.setInvalid(); } }
@Override void setInvalid() { //invalidate ourselves: super.setInvalid(); //invalidate all child trees for (Children ch : childTrees) { ch.setInvalid(); } }
@Override public boolean isValueCompatible(FieldValue value) { if (!(value instanceof AnnotationReference)) { return false; } AnnotationReference reference = (AnnotationReference) value; if (equals(reference.getDataType())) { return true; } return false; }
/** * This will construct a valid span or throw {@link IllegalArgumentException} * if the span is invalid. * * @param from Start of the span. Must be >= 0. * @param length of the span. Must be >= 0. * @throws IllegalArgumentException if illegal span */ public Span(int from, int length) { setFrom(from); setLength(length); }
void resetCachedFromAndTo() { cachedFrom = Integer.MIN_VALUE; cachedTo = Integer.MIN_VALUE; if (getParent() instanceof SpanList) { ((SpanList) getParent()).resetCachedFromAndTo(); } }
@Override void annotateAll(Collection<Annotation> annotations) { for (Annotation a : annotations) { annotate(a); } }
/** * Convenience method for adding an annotation with no value to this span, same as * <code>getSpanTree().{@link SpanTree#annotate(SpanNode,AnnotationType) spanTree.annotate(this,type)}</code> * * @param type the type of the annotation to add * @return this for chaining * @throws NullPointerException if this span is not attached to a tree */ public SpanNode annotate(AnnotationType type) { getNonNullSpanTree().annotate(this,type); return this; }
/** * Convenience method for adding an annotation to this span, same as * <code>getSpanTree().{@link SpanTree#annotate(SpanNode,AnnotationType,FieldValue) spanTree.annotate(this,type,value)}</code> * * @param type the type of the annotation to add * @param value the value of the annotation to add * @return this for chaining * @throws NullPointerException if this span is not attached to a tree */ public SpanNode annotate(AnnotationType type,FieldValue value) { getNonNullSpanTree().annotate(this,type,value); return this; }