ErrorRange.java [src/soils/utils] Revision: default Date:
/*
* $Id$
*
* This file is part of the Cloud Services Integration Platform (CSIP),
* a Model-as-a-Service framework, API, and application suite.
*
* 2012-2017, OMSLab, Colorado State University.
*
* OMSLab licenses this file to you under the MIT license.
* See the LICENSE file in the project root for more information.
*/
package soils.utils;
/**
*
* @author maxerdwien
* @author <a href="mailto:shaun.case@colostate.edu">Shaun Case</a>
*/
public class ErrorRange {
String title;
double loValue;
double hiValue;
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public double getLoValue() {
return loValue;
}
public double getHiValue() {
return hiValue;
}
/**
* wjr
* @param lo
*/
public void setLowValue(double lo) {
loValue = lo;
}
/**
* wjr
* @param high
*/
public void setHighValue(double high) {
hiValue = high;
}
/********************************************************************* wjr */
/**
* wjr
* @param ti
* @param lo
* @param hi
*/
/* entry for integer or double */
public ErrorRange(String ti, double lo, double hi) {
title = ti;
loValue = lo;
hiValue = hi;
}
/**
* wjr
* @param ti
*/
/* entry for string */
public ErrorRange(String ti) {
title = ti;
loValue = 0;
hiValue = -1;
}
/**
* wjr
* @param label
* @return
*/
/**
*
* @param value
* @return
*/
// 06-04-2019: Commented out this funciton. This can/most likely will cause an endless loop condition!!
// public final int errorBox(double value) {
// int rtnval = checkRange(value);
// return errorBox(rtnval);
// }
/**
* wjr *
* @param label
* @return
*/
public int checkRange(String label) {
double range = 0.0;
if (loValue == 0 && hiValue == -1) { // it's a string
if (label == null) {
return -3;
}
if (label.trim().length() > 0) {
return 0;
}
return -3;
}
////System.out.println("checkRange: " + title + " " + label + " " + loValue + " " + hiValue);
if (label == null) {
return -2;
}
try { // it's a number
range = Double.valueOf(label).doubleValue();
if (range < loValue || range > hiValue) {
return (range < loValue) ? -1 : 1;
}
} catch (NumberFormatException e) {
return -2;
}
return 0;
}
/**
*
* @param value
* @return
*/
public int checkRange(double value) {
if (Double.isNaN(value)) {
return -1;
}
if (value < loValue || value > hiValue) {
return (value < loValue) ? -1 : 1;
}
return 0;
}
/**
* wjr *
* @param idx
* @return
*/
public String adjValue(int idx) {
if (idx == -3) {
return "no value given";
}
double rtn = 0;
switch (idx) {
case -1:
rtn = loValue;
break;
case 1:
rtn = hiValue;
break;
case -2:
rtn = (loValue + hiValue) / 2;
break;
}
int numdigits = (int) -(Math.log(rtn) / Math.log(10.0)) + 4;
if (numdigits < 0) {
numdigits = 0;
}
return SoilUtils.formatDouble(rtn, numdigits);
}
/**
* wjr *
* @param inpval
* @return
*/
public double adjValue(double inpval) {
if (inpval < loValue) {
return loValue;
}
if (inpval > hiValue) {
return hiValue;
}
return inpval;
}
/**
* wjr *
* @return
*/
public String getToolTipText() {
if (loValue > hiValue) {
return title;
} else {
return title + " " + loValue + " - " + hiValue;
}
}
/************************************************************************ wjr **/
}