Is this actual file position in the current cache?
@param iTargetPosition The logical position to check.
@return true if this position is in the current buffer list.
330505
public boolean inBufferList(int iTargetPosition)
    {
        boolean bInBufferList = ((iTargetPosition >= m_iCurrentRecordStart) && (iTargetPosition < m_iCurrentRecordEnd));
        if (bInBufferList)
            if (m_aCurrentRecord[this.bufferToArrayIndex(iTargetPosition)] == gEmptyCell)
                bInBufferList = false;
        return bInBufferList;
    }
571433
public void position(long p) throws IOException {
        if (p < 0) {
            throw new IOException("Negative seek offset.");
        }
        if (p > size) {
            throw new IOException("Desired position exceeds size.");
        }
        if (p < buffer.length) {
            // Only seek file if necessary
            if (position > buffer.length) {
                diskStream.position(0);
            }
        } else {
            diskStream.position(p - buffer.length);
        }
        this.position = p;
    }
759211
protected boolean computeOffset(final int dataIndex, CacheDataSet cache) {
        float layoutOffset = getLayoutOffset();
        int pos = cache.getPos(dataIndex);
        float startDataOffset = Float.NaN;
        float endDataOffset = Float.NaN;
        if (pos > 0) {
            int id = cache.getId(pos - 1);
            if (id != -1) {
                startDataOffset = cache.getEndDataOffset(id);
                if (!Float.isNaN(startDataOffset)) {
                    endDataOffset = cache.setDataAfter(dataIndex, startDataOffset);
                }
            }
        } else if (pos == 0) {
            int id = cache.getId(pos + 1);
            if (id != -1) {
                endDataOffset = cache.getStartDataOffset(id);
                if (!Float.isNaN(endDataOffset)) {
                    startDataOffset = cache.setDataBefore(dataIndex, endDataOffset);
                }
            } else {
                startDataOffset = getStartingOffset((cache.getTotalSizeWithPadding()));
                endDataOffset = cache.setDataAfter(dataIndex, startDataOffset);
            }
        }

        Log.d(LAYOUT, TAG, "computeOffset [%d, %d]: startDataOffset = %f endDataOffset = %f",
                dataIndex, pos, startDataOffset, endDataOffset);

        boolean inBounds = !Float.isNaN(cache.getDataOffset(dataIndex)) &&
                endDataOffset > layoutOffset &&
                startDataOffset < -layoutOffset;

        return inBounds;
    }
802578
public long getPosition() {
        long file_pos = 0;
        UnifiedDataPageX page = _buffer.getCurrentPage();
        if (page != null) {
            file_pos = page.getFilePosition(_pos);
        }
        return file_pos;
    }
696977
protected boolean isConfigLocation(URI location) {
        String scheme = location.getScheme();
        if (scheme == null) {
            // interpret as place holder
            try {
                String resolvedPlaceholder = getProperty(location.getRawSchemeSpecificPart());
                if (resolvedPlaceholder == null) {
                    return false;
                }
                location = new URI(resolvedPlaceholder);
                scheme = location.getScheme();
            } catch (URISyntaxException e) {
                return false;
            }
        }
        return (scheme != null && SUPPORTED_SCHEMES.contains(scheme.toLowerCase(StringUtil.LOCALE_INTERNAL)));
    }
266129
public boolean setCache(Object objTargetRow, Object data)
    {
        if (objTargetRow != NONE)
        {
            if (m_mapCache != null)
            {
                int iTargetRow = ((Integer)objTargetRow).intValue();
                int iCurrentPhysicalRecord = ((Integer)m_objCurrentPhysicalRecord).intValue();
                if (iTargetRow == iCurrentPhysicalRecord)
                {   // Reset the current record
                    m_objCurrentPhysicalRecord = NONE;
                    m_objCurrentCacheRecord = NONE;
                    m_objCurrentLockedRecord = NONE;
                }
                if (m_iPhysicalLastRecordPlusOne == iTargetRow)
                    m_iPhysicalLastRecordPlusOne++;
                m_mapCache.set(iTargetRow, data); // Make sure the cache matches the actual
                return true;
            }
            if (m_htCache != null)
            {
                if (objTargetRow.equals(m_objCurrentPhysicalRecord))
                {   // Reset the current record.
                    m_objCurrentPhysicalRecord = NONE;
                    m_objCurrentCacheRecord = NONE;
                    m_objCurrentLockedRecord = NONE;
                }
                if (data != null)
                    m_htCache.put(objTargetRow, data);  // Make sure the cache matches the actual
                else
                    m_htCache.remove(objTargetRow);
                return true;
            }
        }
        return false; // nothing updated
    }
1128211
private boolean shouldLoad(Node node, JobDef jd)
    {
        if (!cache.containsKey(jd.getApplicationName()))
        {
            return true;
        }
        // If here: cache exists.
        JobDefLibrary libs = cache.get(jd.getApplicationName());

        // Is cache stale?
        Date lastLoaded = libs.loadTime;
        File jarFile = new File(FilenameUtils.concat(new File(node.getRepo()).getAbsolutePath(), jd.getJarPath()));
        File jarDir = jarFile.getParentFile();
        File libDir = new File(FilenameUtils.concat(jarDir.getAbsolutePath(), "lib"));

        if (lastLoaded.before(new Date(jarFile.lastModified())) || lastLoaded.before(new Date(jarDir.lastModified()))
                || lastLoaded.before(new Date(libDir.lastModified())))
        {
            jqmlogger.info("The cache for application " + jd.getApplicationName() + " will be reloaded");
            return true;
        }

        // If here, the cache is OK
        return false;
    }
151698
public static boolean isCachedContentRequest(final Request request) {

		// Get target id on request
		String targetId = request.getParameter(Environment.TARGET_ID);
		if (targetId == null) {
			return false;
		}

		// Get target
		ComponentWithContext targetWithContext = WebUtilities.getComponentById(targetId, true);
		if (targetWithContext == null) {
			return false;
		}

		// Check for caching key
		WComponent target = targetWithContext.getComponent();
		UIContextHolder.pushContext(targetWithContext.getContext());

		try {
			// TODO Look at implementing CacheableTarget interface
			String key = null;
			if (target instanceof WContent) {
				key = ((WContent) target).getCacheKey();
			} else if (target instanceof WImage) {
				key = ((WImage) target).getCacheKey();
			} else if (target instanceof WVideo) {
				key = ((WVideo) target).getCacheKey();
			} else if (target instanceof WAudio) {
				key = ((WAudio) target).getCacheKey();
			}
			return !Util.empty(key);
		} finally {
			UIContextHolder.popContext();
		}
	}
1104913
public Object elementAt(int iTargetPosition)
    {
        Record record = null;
        Object bookmark = null;
        if (m_iEndOfFileIndex != UNKNOWN_POSITION) if (iTargetPosition >= m_iEndOfFileIndex)
            return null;    // Past/At EOF
        if (!m_gridBuffer.inBufferList(iTargetPosition))
        {
            bookmark = m_gridList.elementAt(iTargetPosition);
            if (bookmark != null)
                return bookmark;    // In grid list, return it!
            // Find the next lower item in the list
            int iLowestNonNullIndex = this.lowestNonNullIndex(iTargetPosition);
            if (iLowestNonNullIndex != -1)
            {
                bookmark = m_gridList.elementAt(iLowestNonNullIndex);
                if (bookmark == null)
                    bookmark = m_gridBuffer.elementAt(iLowestNonNullIndex);
            }
            
            boolean bFindTargetUsingCurrentQuery = false;
            if (bookmark == null)
                bFindTargetUsingCurrentQuery = true;
            else
            {
                if (iTargetPosition == m_iPhysicalFilePosition + 1)
                    if (m_bIsSequentialQueryValid)
                        bFindTargetUsingCurrentQuery = true;
            }

            if (!bFindTargetUsingCurrentQuery)
            { // This record is not in the grid list, because the granularity is too great
                // Read the record before it, and move forward.
                // Move to > bookmark, and move next until you hit this target.
                this.getNextTable().setDataRecord((DataRecord)bookmark);
                record = this.getRecord();
                if (m_behCompare != null)
                    record.removeListener(m_behCompare, true);
                m_behCompare = new SubCurrentFilter(true, false);
                m_behCompare.setMasterSlaveFlag(RecordOwner.MASTER | RecordOwner.SLAVE);    // Should run in either space
                record.addListener(m_behCompare);
                this.getNextTable().close();
                this.getRecord().setOpenMode(this.getRecord().getOpenMode() | DBConstants.OPEN_SUPPRESS_MESSAGES);   // Don't send an "AFTER_REQUERY_TYPE" message
                try   {
                    m_iPhysicalFilePosition = iLowestNonNullIndex - 1;
                    m_bIsSequentialQueryValid = true;
                    record = (Record)this.move(+1);
                    m_iPhysicalFilePosition = iLowestNonNullIndex;
                } catch (DBException e)   {
                    record = null;
                } finally {
                    this.getRecord().setOpenMode(this.getRecord().getOpenMode() & ~DBConstants.OPEN_SUPPRESS_MESSAGES);
                }
                if (record == null) if (m_behCompare != null)
                {
                    this.getRecord().removeListener(m_behCompare, true);
                    m_behCompare = null;
                }
            }

            try   {
                int iCurrentPosition = m_iPhysicalFilePosition;
                if (iCurrentPosition == -1)
                {
                    for (iCurrentPosition = 0; ; iCurrentPosition++)
                    {       // Find the first non-deleted record
                        if ((!m_gridBuffer.inBufferList(iCurrentPosition))
                            || (m_gridBuffer.elementAt(iCurrentPosition) != null))
                                break;
                    }
                    record = (Record)this.move(DBConstants.FIRST_RECORD);
                    if (record != null)
                    {
                        if (iCurrentPosition != 0)
                        {
                            bookmark = m_gridList.elementAt(0);
                            if (bookmark == null)
                                bookmark = m_gridBuffer.elementAt(0);
                            m_gridBuffer.addElement(0, null, m_gridList);   // Set this as deleted again
                            m_gridBuffer.addElement(iCurrentPosition, bookmark, m_gridList);   // Set this in the right logical position
                            m_iPhysicalFilePosition = iCurrentPosition;
                        }
                    }
                    else
                    {
                        iTargetPosition = 0;    // Make sure current position = 0!
                        m_iEndOfFileIndex = 0;  // EOF + 1
                    }
                }
                int iMoveRelative = iTargetPosition - iCurrentPosition;
                if (iMoveRelative < 0)
                    record = (Record)this.move(iMoveRelative);
                else
                {
                    while (iMoveRelative > 0)
                    {
                        if ((m_gridBuffer.inBufferList(m_iPhysicalFilePosition + 1))
                            && (m_gridBuffer.elementAt(m_iPhysicalFilePosition + 1) == null))
                        {
                            m_iPhysicalFilePosition++;  // This record shows deleted, don't fill with a record.
                        }
                        else
                        {
                            record = (Record)this.move(+1);
                            if (record == null)
                                break;
                        }
                        iMoveRelative--;
                    }
                }
                m_bIsSequentialQueryValid = true; // The query is in force, you may use move(+1) next time (instead of starting a new query)
            } catch (DBException ex)    {
                ex.printStackTrace();
                record = null;
            }
            m_iPhysicalFilePosition = iTargetPosition;
            if (m_behCompare != null)
            {
                this.getRecord().removeListener(m_behCompare, true);
                m_behCompare = null;
            }
            if (record == null)
                return null;
        }
        if (m_gridBuffer.inBufferList(iTargetPosition))
            bookmark = m_gridBuffer.elementAt(iTargetPosition);
        else
            bookmark = m_gridList.elementAt(iTargetPosition);
        return bookmark;
    }
1317090
private boolean isCacheValid()
  {
    long now = CurrentTime.currentTime();

    if ((now - _lastTime < 100) && ! CurrentTime.isTest())
      return true;

    long oldLastModified = _lastModified;
    long oldLength = _length;
    
    long newLastModified = getBacking().getLastModified();
    long newLength = getBacking().length();
    
    _lastTime = now;

    if (newLastModified == oldLastModified && newLength == oldLength) {
      _lastTime = now;
      return true;
    }
    else {
      _changeSequence.incrementAndGet();
      
      // If the file has changed, close the old file
      clearCache();
      
      _zipEntryCache.clear();
      
      _lastModified = newLastModified;
      _length = newLength;
      
      _lastTime = now;

      return false;
    }
  }
1127632
public final int compareTo(String fileName, final long position) {
        final int val = this.fileName.compareTo(fileName);

        if (val == 0) {
            return (int) (this.position - position);
        }
        return val;
    }
1156644
public boolean isVisited(int loc) {
    if (checkBounds(loc)) {
      return (ONE == this.registry[loc]);
    }
    else {
      throw new RuntimeException(
          "The location " + loc + " out of bounds [0," + (this.registry.length - 1) + "]");
    }

  }
611208
public boolean isSyncCurrentPosition(int syncmode) throws BitstreamException
	{
		int read = readBytes(syncbuf, 0, 4);
		int headerstring = ((syncbuf[0] << 24) & 0xFF000000) | ((syncbuf[1] << 16) & 0x00FF0000) | ((syncbuf[2] << 8) & 0x0000FF00) | ((syncbuf[3] << 0) & 0x000000FF);

		try
		{
			source.unread(syncbuf, 0, read);
		}
		catch (IOException ex)
		{
		}

		boolean sync = false;
		switch (read)
		{
			case 0:
				sync = true;
				break;
			case 4:
				sync = isSyncMark(headerstring, syncmode, syncword);
				break;
		}

		return sync;
	}
683515
private boolean setPositionByMin() {
		// min always points to a start of a record
		long min = getPosition();
		if (min < 0) {
			return false;
		}
		try {
			long max = reader.length();
			int recSize = reader.readLength();
			if (recSize < 0 || min + recSize + 8 > max) {
				// Even first record is incomplete
				return false;
			}
			DataInputStream input = readRecord(recSize);
			if (LogRecordSerializer.RECORD != formatter.getType(input)) {
				// First record is not a record
				return false;
			}
			RepositoryLogRecordImpl record = formatter.deserializeLogTime(input);
			// First record already satisfies condition
			if (verifyMin(record)) {
				return true;
			}
			reader.seek(max);
			long nextPosition = seekToPrevRecord(formatter);
			max = nextPosition;
			
			do {
				recSize = reader.readLength();
				if (recSize < 0 || nextPosition + recSize + 8 > max) {
					// corrupt record, good records are closer to the start.
					max = nextPosition;
				} else {
					input = readRecord(recSize);
					if (LogRecordSerializer.RECORD != formatter.getType(input)) {
						// Got all the way to the header record.
						max = nextPosition;
					} else {
						record =  formatter.deserializeLogTime(input);
						if (verifyMin(record)) {
							max = nextPosition;
						} else {
							min = nextPosition + recSize + 8;
						}
					}
				}
				reader.seek((min + max)/2);
				nextPosition = seekToNextRecord(formatter);
				// loop until seek to next record returns us back to max.
			} while (nextPosition < max);
			return true;
		} catch (IOException ex) {
			logger.logp(Level.SEVERE, className, "setPositionBySeq", "Error to set position in {0} by min condition: ", new Object[]{file, ex.getMessage()});
			logger.logp(Level.SEVERE, className, "setPositionBySeq", ex.getLocalizedMessage(), ex);
			// Fall through to return false.
		} finally {
			try {
				reader.seek(min);
			} catch (IOException ex) {
				// too late to fix, allow reading logic to work around it.
				// don't use return here it would mask all uncaught exceptions
			}
		}
		
		return false;
	}
568903
public boolean hasCachedValue(Key key) {
		try {
			readLock.lock();
			return content.containsKey(key);
		} finally {
			readLock.unlock();
		}
	}
111628
private boolean clampPosition() {
        if (mPosition < 0) {
            mPosition = -1;
            return false;
        } else if (mPosition > mList.size()) { // TODO should this be >= instead of >
            mPosition = mList.size();
            return false;
        }
        return true;
    }
430414
private boolean goToNextStartPosition() throws IOException {
    int basicStartPositionMin;
    int basicStartPositionMax;
    int basicEndPosition;
    int basicEndPositionMin;
    int basicEndPositionMax;
    if (docId == -1 || docId == NO_MORE_DOCS) {
      throw new IOException("no document");
    } else {
      if (lastCollectedStartPosition < NO_MORE_POSITIONS
          && (collectedPositions.isEmpty()
              || (collectedPositions.firstKey() >= (lastCollectedStartPosition
                  - query.maximumLeft)))) {
        // collect new positions
        while ((lastCollectedStartPosition = subSpans
            .nextStartPosition()) != NO_MORE_POSITIONS) {
          basicEndPosition = subSpans.endPosition();
          basicStartPositionMin = Math.max(minPosition,
              lastCollectedStartPosition - query.maximumLeft);
          basicStartPositionMax = lastCollectedStartPosition
              - query.minimumLeft;
          basicEndPositionMin = basicEndPosition + query.minimumRight;
          basicEndPositionMax = Math.min(maxPosition + 1,
              basicEndPosition + query.maximumRight);
          for (int cLeft = basicStartPositionMin; cLeft <= basicStartPositionMax; cLeft++) {
            for (int cRight = basicEndPositionMin; cRight <= basicEndPositionMax; cRight++) {
              if (!collectedPositions.containsKey(cLeft)) {
                collectedPositions.put(cLeft, new ArrayList<Integer>());
              }
              collectedPositions.get(cLeft).add(cRight);
            }
          }
          if (!collectedPositions.isEmpty() && (collectedPositions
              .firstKey() < (lastCollectedStartPosition - query.maximumLeft))) {
            break;
          }
        }
      }
      if (collectedPositions.isEmpty()) {
        return false;
      } else {
        startPosition = collectedPositions.firstKey();
        endPosition = collectedPositions.get(startPosition).remove(0);
        if (collectedPositions.get(startPosition).isEmpty()) {
          collectedPositions.remove(startPosition);
        }
        return true;
      }
    }
  }