com.faunos.util.dim.line
Class Ranges

java.lang.Object
  extended by com.faunos.util.dim.line.Ranges

public class Ranges
extends Object

Utility for sorting and searching through Ranges.

Author:
Babak Farhang
See Also:
Range

Method Summary
static int containingIndexOf(long value, List<? extends Range> ranges)
          Returns the index of the given sorted ranges at which the range contains the specified value, if such a range exists; o.w.
static int containingIndexOf(long value, Range[] ranges)
          Returns the index of the given sorted ranges at which the range contains the specified value, if such a range exists; o.w.
static boolean contains(long value, Range range)
          Determines whether the given value falls in the specified range.
static Range createRange(long lo, long hi)
          Creates and returns a new Range instance.
static boolean hasOverlaps(List<? extends Range> ranges)
          Determines whether the given ranges overlap.
static boolean hasOverlaps(Range[] ranges)
          Determines whether the given ranges overlap.
static OutCode outCode(long value, Range range)
          Returns the outcode of the given value relative to the specified range.
static void sort(List<? extends Range> ranges)
          Sorts the given ranges in ascending order of their lo property.
static void sort(Range[] ranges)
          Sorts the given ranges in ascending order of their lo property.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

sort

public static void sort(List<? extends Range> ranges)
Sorts the given ranges in ascending order of their lo property.

See Also:
RangeComparator

sort

public static void sort(Range[] ranges)
Sorts the given ranges in ascending order of their lo property.

See Also:
RangeComparator

hasOverlaps

public static boolean hasOverlaps(List<? extends Range> ranges)
Determines whether the given ranges overlap. The ranges are assumed to be already sorted. The behavior is undefined, if not already sorted.

See Also:
sort(List)

hasOverlaps

public static boolean hasOverlaps(Range[] ranges)
Determines whether the given ranges overlap. The ranges are assumed to be already sorted. The behavior is undefined, if not already sorted.

See Also:
sort(Range[])

contains

public static boolean contains(long value,
                               Range range)
Determines whether the given value falls in the specified range.


outCode

public static OutCode outCode(long value,
                              Range range)
Returns the outcode of the given value relative to the specified range.


containingIndexOf

public static int containingIndexOf(long value,
                                    List<? extends Range> ranges)
Returns the index of the given sorted ranges at which the range contains the specified value, if such a range exists; o.w. it encodes the index of where such a range should have been to satisfy the search as a negative number.

Note the return value has roughly the same semantics as that of Collections.binarySearch(List, Object).

Returns:
index of the range containing the specified value, if it is contained in the list; otherwise, (-(insertion point) - 1). The insertion point is defined as the point at which a Range could be inserted into the sorted list that would satisfy the search. Note that this guarantees that the return value will be ≥ 0 if and only if the key is found.

containingIndexOf

public static int containingIndexOf(long value,
                                    Range[] ranges)
Returns the index of the given sorted ranges at which the range contains the specified value, if such a range exists; o.w. it encodes the index of where such a range should have been to satisfy the search as a negative number.

Note the return value has roughly the same semantics as that of Arrays.binarySearch(long[], long).

Returns:
index of the range containing the specified value, if it is contained in the array; otherwise, (-(insertion point) - 1). The insertion point is defined as the point at which a Range could be inserted into the sorted array (imagining the array's size is somehow increased by 1) that would satisfy the search. Note that this guarantees that the return value will be ≥ 0 if and only if the key is found.

createRange

public static Range createRange(long lo,
                                long hi)
                         throws IllegalArgumentException
Creates and returns a new Range instance. The returned instance implements equality semantics based on the given parameter values.

Throws:
IllegalArgumentException - if hi ≤ lo


SourceForge.net Logo