# Class OverlapDetector<T>

java.lang.Object
htsjdk.samtools.util.OverlapDetector<T>

public class OverlapDetector<T> extends Object
Utility class to efficiently do in memory overlap detection between a large set of mapping like objects, and one or more candidate mappings. You can use it for example to detect all locatables overlapping a given set of locatables:

       OverlapDetector<Locatable> detector = OverlapDetector.create(locatables);
       Set<Locatable> overlaps = detector.getOverlaps(query);

       boolean anyOverlap = detector.overlapsAny(query); //faster API for checking presence of any overlap

## Constructor Summary

Constructors
Constructor
Description
`OverlapDetector(int lhsBuffer, int rhsBuffer)`
Constructs an overlap detector.

## Method Summary

Modifier and Type
Method
Description
`void`
`addAll(List<T> objects, List<? extends Locatable> intervals)`
Adds all items to the overlap detector.
`void`
`addLhs(T object, Locatable interval)`
Adds a Locatable to the set of Locatables against which to match candidates.
`static <T extends Locatable>
OverlapDetector<T>`
`create(List<T> intervals)`
Creates a new OverlapDetector with no trim and the given set of intervals.
`Set<T>`
`getAll()`
Gets all the objects that could be returned by the overlap detector.
`Set<T>`
`getOverlaps(Locatable locatable)`
Gets the Set of objects that overlap the provided locatable.
`boolean`
`overlapsAny(Locatable locatable)`
Returns true iff the given locatable overlaps any locatable in this detector.

### Methods inherited from class Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Constructor Details

### OverlapDetector

public OverlapDetector(int lhsBuffer, int rhsBuffer)
Constructs an overlap detector.

Parameters:
  `lhsBuffer` - the amount by which to "trim" coordinates of mappings on the left hand side when calculating overlaps
  `rhsBuffer` - the amount by which to "trim" coordinates of mappings on the right hand side when calculating overlaps

## Method Details

### create

public static <T extends Locatable> OverlapDetector<T> create(List<T> intervals)
Creates a new OverlapDetector with no trim and the given set of intervals.

### addLhs

public void addLhs(T object, Locatable interval)
Adds a Locatable to the set of Locatables against which to match candidates.

### addAll

public void addAll(List<T> objects, List<? extends Locatable> intervals)
Adds all items to the overlap detector. The order of the lists matters only in the sense that it needs to be the same for the intervals and the corresponding objects.

### getAll

public Set<T> getAll()
Gets all the objects that could be returned by the overlap detector.

### overlapsAny

public boolean overlapsAny(Locatable locatable)
Returns true iff the given locatable overlaps any locatable in this detector. This is a performance shortcut API functionally equivalent to:

         ! getOverlaps(locatable).isEmpty()

### getOverlaps

public Set<T> getOverlaps(Locatable locatable)
Gets the Set of objects that overlap the provided locatable. The returned set may not be modifiable.