javaalgorithmguavaintervalsinterval-tree

IntervalTree in Guava


I am working with Guava's Range class for processing intervals. I wanted to know if it is possible to find the closest interval from a set of intervals to a given point/interval by using some of the Guava's collection containers ?

I tried searching for interval trees in Java and here is what I found. I would prefer to do it by using one of the Guava classes if possible.

http://picard.sourceforge.net/javadoc/net/sf/picard/util/IntervalTree.html http://tribble.googlecode.com/svn/trunk/src/org/broad/tribble/index/interval/IntervalTree.java

Thanks


Solution

  • Guava doesn't provide this, though you might be able to build such a thing on top of a RangeSet by finding the first range before and after a given point.

    But generally, Guava Ranges know nothing about distances, metrics, or anything except the comparison ordering of a type. They don't know that 10 is closer to 11 than 15.