long lockEnd = lock.position() + lock.size();
for (Iterator<FileLock> keyItr = locks.iterator(); keyItr.hasNext();) {
FileLock existingLock = keyItr.next();
if (existingLock.position() > lockEnd) {
// This, and all remaining locks, start beyond our end (so
// cannot overlap).
break;
}
if (existingLock.overlaps(lock.position(), lock.size())) {
throw new OverlappingFileLockException();
}
}
locks.add(lock);