/** * Constructs a new <code>Source</code> object from the specified text. * @param text the source text. */ public Source(final CharSequence text) { super(text.length()); sourceText=text.toString(); setLogger(newLogger()); cache=new Cache(this); }
public Tag getTagAt(final int pos, final boolean serverTagOnly) { // This must only be called on allTagTypesSubCache (ie tagType==null) if (cache.getSourceLength()==0) return null; if (pos<0 || pos>=cache.getSourceLength()) return null; final int index=getIndexOfPos(pos); final CacheEntry cacheEntry=array[index]; if (cacheEntry.pos==pos) { if (serverTagOnly && !cacheEntry.tag.getTagType().isServerTag()) return null; return cacheEntry.tag; } if (cacheEntry.previousCached) return null; return cache.addTagAt(pos,serverTagOnly); }
/** * Clears the {@linkplain #getCacheDebugInfo() tag cache} of all tags. * <p> * This method may be useful after calling the {@link Segment#ignoreWhenParsing()} method so that any tags previously found within the ignored segments * will no longer be returned by the <a href="Tag.html#TagSearchMethods">tag search methods</a>. */ public void clearCache() { cache.clear(); allTagsArray=null; allTags=null; allStartTags=null; allElements=null; }
if (cache.getTagCount()!=0) { logger.info("Full sequential parse clearing all tags from cache. Consider calling Source.fullSequentialParse() manually immediately after construction of Source."); cache.clear();
public SubCache(final Cache cache, final TagType tagType) { this.cache=cache; this.tagType=tagType; array[0]=bof=new CacheEntry(0,-1,null,false,false); array[1]=eof=new CacheEntry(1,cache.getSourceLength(),null,false,false); }
static final Tag getPreviousTag(final Source source, final int pos) { // returns null if pos is out of range. return source.useAllTypesCache ? source.cache.getPreviousTag(pos) : getPreviousTagUncached(source,pos,ParseText.NO_BREAK); }
static final Tag getNextTag(final Source source, final int pos) { // returns null if pos is out of range. return source.useAllTypesCache ? source.cache.getNextTag(pos) : getNextTagUncached(source,pos,ParseText.NO_BREAK); }
cache.addTagAt(pos,false); // this pos has never been checked before, so add it to all relevant SubCaches (a null or unregistered tag entry is always added to this SubCache) else
/** * Gets a list of all the tags that have been parsed so far. * <p> * This information may be useful for debugging purposes. * Execution of this method collects information from the internal cache and is relatively expensive. * * @return a list of all the tags that have been parsed so far. * @see #getCacheDebugInfo() */ List<Tag> getParsedTags() { final ArrayList<Tag> list=new ArrayList<Tag>(); for (final Iterator<Tag> i=cache.getTagIterator(); i.hasNext();) list.add(i.next()); return list; }
static final Tag getTagAt(final Source source, final int pos, final boolean serverTagOnly) { // returns null if pos is out of range. return source.useAllTypesCache ? source.cache.getTagAt(pos,serverTagOnly) : getTagAtUncached(source,pos,serverTagOnly); }
public Cache(final Source source) { this.source=source; allTagTypesSubCache=new SubCache(this,null); TagType[] separatelyCachedTagTypes=getSeparatelyCachedTagTypes(); subCaches=new SubCache[separatelyCachedTagTypes.length+1]; subCaches[0]=allTagTypesSubCache; for (int i=0; i<separatelyCachedTagTypes.length; i++) subCaches[i+1]=new SubCache(this,separatelyCachedTagTypes[i]); }
public Tag getPreviousTag(final int pos) { // Note that this method never returns tags for which tag.includInSearch() is false, so separate caching of unregistered tags won't work. if (cache.getSourceLength()==0) return null; if (pos<0 || pos>=cache.getSourceLength()) return null; int index=getIndexOfPos(pos); final CacheEntry cacheEntry=array[index]; final Tag tag; if (cacheEntry.pos==pos && cacheEntry.tag!=null && cacheEntry.tag.includeInSearch()) return cacheEntry.tag; tag=getPreviousTag(getPrevious(cacheEntry),pos,cacheEntry); addPreviousTag(pos,tag); return tag; }
static final Tag getPreviousTag(final Source source, final int pos, final TagType tagType) { // returns null if pos is out of range. if (tagType==null) return getPreviousTag(source,pos); if (source.useSpecialTypesCache) return source.cache.getPreviousTag(pos,tagType); return getPreviousTagUncached(source,pos,tagType,ParseText.NO_BREAK); }
static final Tag getNextTag(final Source source, final int pos, final TagType tagType) { // returns null if pos is out of range. if (tagType==null) return getNextTag(source,pos); if (source.useSpecialTypesCache) return source.cache.getNextTag(pos,tagType); return getNextTagUncached(source,pos,tagType,ParseText.NO_BREAK); }
cache.addTagAt(pos,false); // this pos has never been checked before, so add it to all relevant SubCaches (a null or unregistered tag entry is always added to this SubCache) else
public Tag getNextTag(final int pos) { // Note that this method never returns tags for which tag.includInSearch() is false, so separate caching of unregistered tags won't work. if (cache.getSourceLength()==0) return null; if (pos<0 || pos>=cache.getSourceLength()) return null; int index=getIndexOfPos(pos); final CacheEntry cacheEntry=array[index]; final Tag tag; if (cacheEntry.pos==pos) { if (cacheEntry.tag!=null && cacheEntry.tag.includeInSearch()) return cacheEntry.tag; tag=getNextTag(cacheEntry,pos,getNext(cacheEntry)); } else { tag=getNextTag(getPrevious(cacheEntry),pos,cacheEntry); } addNextTag(pos,tag); return tag; }