Java 类org.apache.commons.lang.math.DoubleRange 实例源码

项目:gatk-protected    文件:ParamUtilsUnitTest.java   
@Test
public void testInRangeSuccess(){
    Assert.assertTrue(4 == ParamUtils.inRange(4L, 3, 6, "Range calculation did not work properly"), "Did not return proper value");
    Assert.assertTrue(4 == ParamUtils.inRange(4, 3, 6, "Range calculation did not work properly"), "Did not return proper value");
    Assert.assertTrue(4 == ParamUtils.inRange(new IntRange(3, 6), 4, "error"));
    Assert.assertTrue(4.1 == ParamUtils.inRange(4.1, 3, 6, "Range calculation did not work properly"), "Did not return proper value");
    Assert.assertTrue(4.1 == ParamUtils.inRange(4.1, -3, 6, "Range calculation did not work properly"), "Did not return proper value");
    Assert.assertTrue(4.1 == ParamUtils.inRange(new DoubleRange(-3, 6), 4.1, "error"));
    Assert.assertTrue(0 == ParamUtils.inRange(0L, -3, 6, "Range calculation did not work properly"), "Did not return proper value");
    Assert.assertTrue(0 == ParamUtils.inRange(0, -3, 6, "Range calculation did not work properly"), "Did not return proper value");
    Assert.assertTrue(0 == ParamUtils.inRange(new IntRange(-3, 6), 0, "error"));
    Assert.assertTrue(0.0 == ParamUtils.inRange(0.0, -3, 6, "Range calculation did not work properly"), "Did not return proper value");
    Assert.assertTrue(0.0 == ParamUtils.inRange(new DoubleRange(-3, 6), 0.0, "error"));
    Assert.assertTrue(0 == ParamUtils.inRange(0L, -3, 6, "Range calculation did not work properly"), "Did not return proper value");
    Assert.assertTrue(0 == ParamUtils.inRange(0, -3, 6, "Range calculation did not work properly"), "Did not return proper value");
    Assert.assertTrue(0 == ParamUtils.inRange(new IntRange(-3, 6), 0, "error"));
    Assert.assertTrue(-1 == ParamUtils.inRange(-1L, -3, 6, "Range calculation did not work properly"), "Did not return proper value");
    Assert.assertTrue(-1 == ParamUtils.inRange(-1, -3, 6, "Range calculation did not work properly"), "Did not return proper value");
    Assert.assertTrue(-1 == ParamUtils.inRange(new IntRange(-3, 6), -1, "error"));
    Assert.assertTrue(-1.5 == ParamUtils.inRange(-1.5, -3, 6, "Range calculation did not work properly"), "Did not return proper value");
    Assert.assertTrue(-1.5 == ParamUtils.inRange(new DoubleRange(-3, 6), -1.5, "error"));
}
项目:gatk    文件:ParamUtilsUnitTest.java   
@Test
public void testInRangeSuccess(){
    Assert.assertTrue(4 == ParamUtils.inRange(4L, 3, 6, "Range calculation did not work properly"), "Did not return proper value");
    Assert.assertTrue(4 == ParamUtils.inRange(4, 3, 6, "Range calculation did not work properly"), "Did not return proper value");
    Assert.assertTrue(4 == ParamUtils.inRange(new IntRange(3, 6), 4, "error"));
    Assert.assertTrue(4.1 == ParamUtils.inRange(4.1, 3, 6, "Range calculation did not work properly"), "Did not return proper value");
    Assert.assertTrue(4.1 == ParamUtils.inRange(4.1, -3, 6, "Range calculation did not work properly"), "Did not return proper value");
    Assert.assertTrue(4.1 == ParamUtils.inRange(new DoubleRange(-3, 6), 4.1, "error"));
    Assert.assertTrue(0 == ParamUtils.inRange(0L, -3, 6, "Range calculation did not work properly"), "Did not return proper value");
    Assert.assertTrue(0 == ParamUtils.inRange(0, -3, 6, "Range calculation did not work properly"), "Did not return proper value");
    Assert.assertTrue(0 == ParamUtils.inRange(new IntRange(-3, 6), 0, "error"));
    Assert.assertTrue(0.0 == ParamUtils.inRange(0.0, -3, 6, "Range calculation did not work properly"), "Did not return proper value");
    Assert.assertTrue(0.0 == ParamUtils.inRange(new DoubleRange(-3, 6), 0.0, "error"));
    Assert.assertTrue(0 == ParamUtils.inRange(0L, -3, 6, "Range calculation did not work properly"), "Did not return proper value");
    Assert.assertTrue(0 == ParamUtils.inRange(0, -3, 6, "Range calculation did not work properly"), "Did not return proper value");
    Assert.assertTrue(0 == ParamUtils.inRange(new IntRange(-3, 6), 0, "error"));
    Assert.assertTrue(-1 == ParamUtils.inRange(-1L, -3, 6, "Range calculation did not work properly"), "Did not return proper value");
    Assert.assertTrue(-1 == ParamUtils.inRange(-1, -3, 6, "Range calculation did not work properly"), "Did not return proper value");
    Assert.assertTrue(-1 == ParamUtils.inRange(new IntRange(-3, 6), -1, "error"));
    Assert.assertTrue(-1.5 == ParamUtils.inRange(-1.5, -3, 6, "Range calculation did not work properly"), "Did not return proper value");
    Assert.assertTrue(-1.5 == ParamUtils.inRange(new DoubleRange(-3, 6), -1.5, "error"));
}
项目:ABRAID-MP    文件:BinningRasterSummaryCollator.java   
public BinningRasterSummaryCollator(List<DoubleRange> bins) {
    this.bins = new HashMap<>();
    List<DoubleRange> unsortedKeys = new ArrayList<>();
    for (DoubleRange bin : bins) {
        this.bins.put(bin, 0);
        unsortedKeys.add(bin);
    }

    Collections.sort(unsortedKeys, new Comparator<DoubleRange>() {
        @Override
        public int compare(DoubleRange o1, DoubleRange o2) {
            return Double.compare(o1.getMinimumDouble(), o2.getMinimumDouble());
        }
    });
    this.keys = unsortedKeys;
}
项目:ABRAID-MP    文件:RangeRasterSummaryCollatorTest.java   
@Test
public void collatorGetsCorrectResult() throws IOException {
    // Arrange
    RangeRasterSummaryCollator target = new RangeRasterSummaryCollator();

    // Act
    target.addValue(7);
    target.addValue(7);
    target.addValue(5);
    target.addValue(9);
    target.addValue(2);
    target.addValue(3);
    DoubleRange result = target.getSummary();

    // Assert
    assertThat(result.getMaximumDouble()).isEqualTo(9);
    assertThat(result.getMinimumDouble()).isEqualTo(2);
}
项目:ABRAID-MP    文件:BinningRasterSummaryCollatorTest.java   
@Test
public void collatorGetsCorrectResult() throws IOException {
    // Arrange
    DoubleRange lowBin = new DoubleRange(0, 3.5);
    DoubleRange middleBin = new DoubleRange(3.5, 7);
    DoubleRange highBin = new DoubleRange(7, 10);
    BinningRasterSummaryCollator target = new BinningRasterSummaryCollator(Arrays.asList(
            lowBin, middleBin, highBin
    ));

    // Act
    target.addValue(7);
    target.addValue(7);
    target.addValue(5);
    target.addValue(9);
    target.addValue(2);
    target.addValue(3);
    Map<DoubleRange, Integer> result = target.getSummary();

    // Assert
    assertThat(result.get(lowBin)).isEqualTo(2);
    assertThat(result.get(middleBin)).isEqualTo(3);
    assertThat(result.get(highBin)).isEqualTo(1);
    assertThat(result).hasSize(3);
}
项目:ABRAID-MP    文件:CovariatesControllerHelperImpl.java   
/**
 * Persist a single new covariate file to the filesystem and database.
 * @param name The display name for the covariate (null if a sub file).
 * @param qualifier The qualifier name for the covariate sub file (ie the year/month).
 * @param parentId The ID of the parent covariate for this file (or null if this is the first file).
 * @param isDiscrete True if this covariate contains discrete values
 * @param path The location to store the covariate.
 * @param file The covariate.
 * @throws IOException Thrown if the covariate director can not be writen to.
 */
@Override
public void saveNewCovariateFile(String name, String qualifier, Integer parentId, boolean isDiscrete,
                                 String path, MultipartFile file)
        throws IOException {
    File rasterFile = writeCovariateFileToDisk(file, path);

    CovariateFile covariateFile = null;

    if (parentId == null) {
        // Create top level covariate - Histogram is always taken from first uploaded
        Map<DoubleRange, Integer> binnedCovariateValueData =
                generateCovariateValuesHistogram(rasterFile, isDiscrete);
        covariateFile = createDatabaseCovariate(name, isDiscrete, binnedCovariateValueData);
    } else {
        // Find top level covariate
        covariateFile = covariateService.getCovariateFileById(parentId);
    }

    CovariateSubFile subFile = new CovariateSubFile(covariateFile, qualifier, extractRelativePath(path));
    addSubFileToCovariate(covariateFile, subFile);

    covariateService.saveCovariateFile(covariateFile);
}
项目:ABRAID-MP    文件:CovariatesControllerHelperImpl.java   
private CovariateFile createDatabaseCovariate(String name, boolean isDiscrete,
                                    Map<DoubleRange, Integer> binnedCovariateValueData) throws IOException {

    CovariateFile covariateFile = new CovariateFile(
            name,
            false,
            isDiscrete,
            ""
    );

    List<CovariateValueBin> bins = new ArrayList<>();
    for (Map.Entry<DoubleRange, Integer> bin : binnedCovariateValueData.entrySet()) {
        bins.add(new CovariateValueBin(covariateFile,
                bin.getKey().getMinimumDouble(), bin.getKey().getMaximumDouble(), bin.getValue()));
    }
    covariateFile.setCovariateValueHistogramData(bins);
    covariateFile.setFiles(new ArrayList<CovariateSubFile>());

    return covariateFile;
}
项目:ABRAID-MP    文件:BinningRasterSummaryCollator.java   
@Override
public void addValue(double value) throws IOException {
    for (int i = 0; i < this.keys.size(); i++) {
        DoubleRange range = this.keys.get(i);
        if (range.containsDouble(value)) {
            this.bins.put(range, this.bins.get(range) + 1);
            return;
        }
    }
    throw new IOException();
}
项目:ABRAID-MP    文件:BinningRasterSummaryCollatorTest.java   
@Test
public void collatorGetsCorrectResultForZeroWidthBins() throws IOException {
    // Arrange
    DoubleRange bin7 = new DoubleRange(7, 7);
    DoubleRange bin5 = new DoubleRange(5, 5);
    DoubleRange bin9 = new DoubleRange(9, 9);
    DoubleRange bin3 = new DoubleRange(3, 3);
    DoubleRange bin2 = new DoubleRange(2, 2);
    BinningRasterSummaryCollator target = new BinningRasterSummaryCollator(Arrays.asList(
            bin7, bin5, bin9, bin3, bin2
    ));

    // Act
    target.addValue(7);
    target.addValue(7);
    target.addValue(5);
    target.addValue(9);
    target.addValue(2);
    target.addValue(3);
    Map<DoubleRange, Integer> result = target.getSummary();

    // Assert
    assertThat(result.get(bin7)).isEqualTo(2);
    assertThat(result.get(bin5)).isEqualTo(1);
    assertThat(result.get(bin9)).isEqualTo(1);
    assertThat(result.get(bin3)).isEqualTo(1);
    assertThat(result.get(bin2)).isEqualTo(1);
    assertThat(result).hasSize(5);
}
项目:ABRAID-MP    文件:BinningRasterSummaryCollatorTest.java   
@Test
public void collatorThrowsIfValueOutsideAllBins() throws IOException {
    // Arrange
    BinningRasterSummaryCollator target = new BinningRasterSummaryCollator(Arrays.asList(
            new DoubleRange(0, 10)
    ));

    // Act
    catchException(target).addValue(11);

    // Assert
    assertThat(caughtException()).isInstanceOf(IOException.class);
}
项目:ABRAID-MP    文件:CovariatesControllerHelperImpl.java   
private Map<DoubleRange, Integer> generateCovariateValuesHistogram(File rasterFile, boolean isDiscrete)
        throws IOException {
    // Find bins
    List<DoubleRange> histogramBins = new ArrayList<>();
    if (isDiscrete) {
        Collection<Double> values = RasterUtils.summarizeRaster(rasterFile, new ValuesRasterSummaryCollator());

        for (Double value : values)  {
            histogramBins.add(new DoubleRange(value, value));
        }
    } else {
        DoubleRange range = RasterUtils.summarizeRaster(rasterFile, new RangeRasterSummaryCollator());

        double min = range.getMinimumDouble();
        double max = range.getMaximumDouble();
        double size = (max - min) / ((double) NUMBER_OF_HISTOGRAM_BINS);
        for (int i = 1; i <= NUMBER_OF_HISTOGRAM_BINS; i++) {
            histogramBins.add(new DoubleRange(
                    min + ((i - 1) * size),
                    (i == NUMBER_OF_HISTOGRAM_BINS) ? max : (min + (i * size)))
            );
        }
    }

    // Count
    return RasterUtils.summarizeRaster(rasterFile, new BinningRasterSummaryCollator(histogramBins));
}
项目:gatk-protected    文件:ParamUtilsUnitTest.java   
@Test(expectedExceptions = IllegalArgumentException.class)
public void testInRangeFailureAllPositiveDoubleRange(){
    ParamUtils.inRange(new DoubleRange(7, 10), 4, "Range calculation did not work properly");
}
项目:gatk-protected    文件:ParamUtilsUnitTest.java   
@Test(expectedExceptions = IllegalArgumentException.class)
public void testInRangeFailureNaNDoubleRange(){
    ParamUtils.inRange(new DoubleRange(7, 10), Double.NaN, "Range calculation did not work properly");
}
项目:gatk    文件:ParamUtilsUnitTest.java   
@Test(expectedExceptions = IllegalArgumentException.class)
public void testInRangeFailureAllPositiveDoubleRange(){
    ParamUtils.inRange(new DoubleRange(7, 10), 4, "Range calculation did not work properly");
}
项目:gatk    文件:ParamUtilsUnitTest.java   
@Test(expectedExceptions = IllegalArgumentException.class)
public void testInRangeFailureNaNDoubleRange(){
    ParamUtils.inRange(new DoubleRange(7, 10), Double.NaN, "Range calculation did not work properly");
}
项目:ABRAID-MP    文件:BinningRasterSummaryCollator.java   
@Override
public Map<DoubleRange, Integer> getSummary() {
    return this.bins;
}
项目:ABRAID-MP    文件:RangeRasterSummaryCollator.java   
@Override
public DoubleRange getSummary() {
    return new DoubleRange(min, max);
}
项目:gatk-protected    文件:ParamUtils.java   
/**
 * Validates the value of a parameter.
 * <p>
 * An invalid value will result in an {@link IllegalArgumentException}.
 * </p>
 * <p>
 *   Notice that {@link Double#NaN nan} are always considered invalid whereas negative or infinity values
 *   will depends on the declared input range extreme values.
 * </p>
 *
 * @param validRange the valid range for the parameter value.
 * @param value the parameter value itself.
 * @param definition a human friendly description of the parameter to be used in an explanatory exception.
 * @return the input value.
 * @throws IllegalArgumentException if the value provided is in-valid.
 */
public static double inRange(final DoubleRange validRange, final double value, final String definition) {
    Utils.nonNull(validRange);
    Utils.validateArg(validRange.containsDouble(value), String.format("invalid value for %s: %g is not in [%g, %g]",
            definition, value, validRange.getMinimumDouble(), validRange.getMaximumDouble()));
    return value;
}
项目:gatk    文件:ParamUtils.java   
/**
 * Validates the value of a parameter.
 * <p>
 * An invalid value will result in an {@link IllegalArgumentException}.
 * </p>
 * <p>
 *   Notice that {@link Double#NaN nan} are always considered invalid whereas negative or infinity values
 *   will depends on the declared input range extreme values.
 * </p>
 *
 * @param validRange the valid range for the parameter value.
 * @param value the parameter value itself.
 * @param definition a human friendly description of the parameter to be used in an explanatory exception.
 * @return the input value.
 * @throws IllegalArgumentException if the value provided is in-valid.
 */
public static double inRange(final DoubleRange validRange, final double value, final String definition) {
    Utils.nonNull(validRange);
    Utils.validateArg(validRange.containsDouble(value), String.format("invalid value for %s: %g is not in [%g, %g]",
            definition, value, validRange.getMinimumDouble(), validRange.getMaximumDouble()));
    return value;
}