Example usage for com.google.common.collect RangeMap span

List of usage examples for com.google.common.collect RangeMap span

Introduction

In this page you can find the example usage for com.google.common.collect RangeMap span.

Prototype

Range<K> span();

Source Link

Document

Returns the minimal range Range#encloses(Range) enclosing the ranges in this RangeMap .

Usage

From source file:org.mskcc.shenkers.data.interval.DiscreteRangeMap.java

public void testGetGraphic() {
    RangeMap<Integer, Double> ram = TreeRangeMap.create();
    //        ram.put(Range.closed(0, 4), 0.);
    System.out.println("adding");
    ram = add(ram, Range.closed(1, 3), 1.);
    ram.asMapOfRanges().forEach((r, d) -> System.out.println(String.format("%s %f", r, d)));
    System.out.println("adding");
    ram = add(ram, Range.closed(-1, 4), 1.);
    ram.asMapOfRanges().forEach((r, d) -> System.out.println(String.format("%s %f", r, d)));
    System.out.println("adding");
    ram = add(ram, Range.closed(3, 5), 2.);
    ram.asMapOfRanges().forEach((r, d) -> System.out.println(String.format("%s %f", r, d)));
    System.out.println("asReal");
    ram.asMapOfRanges().forEach((r, d) -> System.out.println(String.format("%s %f", r, d)));
    toReal(ram).asMapOfRanges().forEach((r, d) -> System.out.println(String.format("%s %f", r, d)));

    RangeMap<Double, Double> toReal = toReal(ram);
    System.out.println("span " + toReal.span());
    double length = length(toReal.span());
    System.out.println("length " + length);
    int k = 7;//  w w w.j av  a 2 s  .  com
    double binSize = length / k;
    Double lb = toReal.span().lowerEndpoint();
    for (int i = 0; i < k; i++) {
        Range<Double> closedOpen = Range.closedOpen(lb + (i * 1. / k * length), lb + ((i + 1.) / k * length));
        System.out.println("bin " + i);
        System.out.println(closedOpen);
        Double max = Collections.max(toReal.subRangeMap(closedOpen).asMapOfRanges().values());
        Double mean = toReal.subRangeMap(closedOpen).asMapOfRanges().values().stream()
                .mapToDouble(Double::doubleValue).average().orElse(0.);

        //            StreamSupport.doubleStream(new Spliterator.OfDouble()
        //                    false);
        System.out.println("max " + max);
        System.out.println("mean " + mean);
    }

}