/** * Indicates if this text has at least one annotation. * @return true if there is at least one annotation, false otherwise. */ public boolean hasAnnotation () { if ( !hasCode() ) return false; for ( Code code : codes ) { if ( code.hasAnnotation() ) return true; } return false; }
/** * Indicates if this text has at least one annotation of a given type. * @param type the type of annotation to look for. * @return true if there is at least one annotation of the given type, false otherwise. */ public boolean hasAnnotation (String type) { if ( !hasCode() ) return false; for ( Code code : codes ) { if ( code.hasAnnotation(type) ) return true; } return false; }
/** * Removes all codes both in the Codes list and the markers. * @return this {@link TextFragment}, with the codes removed */ public TextFragment cleanCodes() { // We cannot use hasCode() because it may be wrong at this point. Code code; for ( int i=0; i<text.length(); i++ ) { switch ( text.charAt(i) ) { case MARKER_OPENING: case MARKER_CLOSING: case MARKER_ISOLATED: code = codes.get(toIndex(text.charAt(++i))); if (( !code.hasData() ) && ( !code.hasAnnotation() )) { text = text.delete(i-1, i+1); i--; // Correct for loop } break; } } // remove all listed codes setCodes(null); return this; }
case MARKER_ISOLATED: code = codes.get(toIndex(text.charAt(++i))); if (( !code.hasData() ) && ( !code.hasAnnotation() )) { text = text.delete(i-1, i+1);
/** * Gets the list of all spans of text annotated with a given type of annotation. * @param type the type of annotation to look for. * @return a list of annotated spans for the given type (it may be empty). */ public List<AnnotatedSpan> getAnnotatedSpans (String type) { // Always return a list, never null. ArrayList<AnnotatedSpan> list = new ArrayList<AnnotatedSpan>(); if ( codes == null ) return list; for ( int i=0; i<codes.size(); i++ ) { if (( codes.get(i).tagType == TagType.OPENING ) && ( codes.get(i).hasAnnotation(type) )) { int start = getCodePosition(i)+2; // Span starts just after the marker int end = findClosingCodePosition(codes.get(i).id, i); if (( start == -1 ) || ( end == -1 )) continue; // Something is wrong list.add(new AnnotatedSpan(type, codes.get(i).getAnnotation(type), subSequence(start, end), start, end)); } } return list; }
if ( code.hasAnnotation("protected") ) { tmp.append("<mrk mtype=\"protected\">"); else if ( includeIts && code.hasAnnotation(GenericAnnotationType.GENERIC) ) { tmp.append("<mrk"); outputITSAttributes(code.getGenericAnnotations(), quoteMode, escapeGT, tmp, true, true, trgLocId); if ( includeIts && code.hasAnnotation(GenericAnnotationType.GENERIC) ) { tmp.append("</mrk>"); else if ( code.hasAnnotation("protected") ) { tmp.append("</mrk>"); if ( includeIts && code.hasAnnotation(GenericAnnotationType.GENERIC) ) { outputITSAttributes(code.getGenericAnnotations(), quoteMode, escapeGT, tmp, true, false, null); if ( includeIts && code.hasAnnotation(GenericAnnotationType.GENERIC) ) { outputITSAttributes(code.getGenericAnnotations(), quoteMode, escapeGT, tmp, true, false, trgLocId);
return false; if (code1.hasAnnotation() != code2.hasAnnotation()) { LOGGER.warn("compareTextFragment warning: TextFragment Code hasAnnotation difference."); return false; if (code1.hasAnnotation() != code2.hasAnnotation()) { LOGGER.warn("compareTextFragment warning: TextFragment Code hasAnnotation difference."); return false;
index = TextFragment.toIndex(codedText.charAt(++i)); code = codes.get(index); if ( code.hasAnnotation("protected") ) { tmp.append("<hi type=\"protected\">"); } else { if ( code.hasAnnotation("protected") ) { tmp.append("</hi>");