code: private Double scale(Double value, Double min, Double max) {
          if(min.equals(max)) {
              if(value>max) {
                  return 1.0;
              }
              else if(value==max && value!=0.0) {
                  return 1.0;
              }
              else {
                  return 0.0;
              }
          }
          else {
              return (value-min)/(max-min);
          }
      }
docs: Performs the actual rescaling handling corner cases.
  
  @param value
  @param min
  @param max
  @return