/** * Gets the constituent chunks stored in this span. * @return An unmodifiable list of chunks. */ public List<GATKChunk> getGATKChunks() { List<GATKChunk> gatkChunks = new ArrayList<GATKChunk>(); for(Chunk chunk: getChunks()) gatkChunks.add(new GATKChunk(chunk)); return gatkChunks; }
@Override public boolean equals(final Object other) { if(!(other instanceof BAMFileSpan)) return false; List<Chunk> theseChunks = getChunks(); List<Chunk> otherChunks = ((BAMFileSpan)other).getChunks(); if(theseChunks.size() != otherChunks.size()) return false; for(int i = 0; i < theseChunks.size(); i++) { if(!theseChunks.get(i).equals(otherChunks.get(i))) return false; } return true; }
/** * Validates the list of chunks to ensure that they appear in sorted order. */ private void validateSorted() { List<Chunk> chunks = getChunks(); for ( int i = 1; i < chunks.size(); i++ ) { if ( chunks.get(i).getChunkStart() < chunks.get(i-1).getChunkEnd() ) { throw new ReviewedGATKException(String.format("Chunk list is unsorted; chunk %s is before chunk %s", chunks.get(i-1), chunks.get(i))); } } }
/** * Get a GATKChunk representing the "extent" of this file span, from the start of the first * chunk to the end of the last chunk.The chunks list must be sorted in order to use this method. * * @return a GATKChunk representing the extent of this file span, or a GATKChunk representing * a span of size 0 if there are no chunks */ public GATKChunk getExtent() { validateSorted(); // TODO: defensive measure: may be unnecessary List<Chunk> chunks = getChunks(); if ( chunks.isEmpty() ) { return new GATKChunk(0L, 0L); } return new GATKChunk(chunks.get(0).getChunkStart(), chunks.get(chunks.size() - 1).getChunkEnd()); }