/src/loadmaprenderer/BMPHoldingPond.java

https://github.com/davebenradford/LoadMapRenderer · Java · 231 lines · 187 code · 32 blank · 12 comment · 19 complexity · bffe92cea87ce57e3dc05239228107cb MD5 · raw file

  1. /*
  2. * To change this license header, choose License Headers in Project Properties.
  3. * To change this template file, choose Tools | Templates
  4. * and open the template in the editor.
  5. */
  6. package loadmaprenderer;
  7. import java.sql.ResultSet;
  8. import java.sql.SQLException;
  9. import java.util.logging.Level;
  10. import java.util.logging.Logger;
  11. /**
  12. *
  13. * @author Shao
  14. */
  15. public class BMPHoldingPond extends BMPItem
  16. {
  17. private String _name;
  18. private int _hru; //hru index in SWAT, used to find corresponding hru file
  19. private int _cattles;
  20. private int _clay_liner;
  21. private int _plastic_liner;
  22. private int _wire_fence;
  23. private double _distance;
  24. private double _trenching;
  25. private int _pond_year;
  26. public BMPHoldingPond(ResultSet row, int feaIndex, Project project, Scenario scenario) throws SQLException{
  27. super(row, feaIndex, BMPType.Holding_Ponds, project, scenario);
  28. }
  29. //public BMPHoldingPond(System.Data.DataRow row, Project project, Scenario scenario) : base(row, BMPType.Hoding_Pond, project, scenario) { }
  30. public int getLifeTime() throws CloneNotSupportedException{
  31. if (getDesignItem() == null)
  32. return _pond_year;
  33. else {
  34. BMPHoldingPond hd = (BMPHoldingPond) getDesignItem();
  35. return hd.getLifeTime();
  36. }
  37. }
  38. public void setLifeTime(int value) throws CloneNotSupportedException{
  39. if (getDesignItem() == null)
  40. _pond_year = value;
  41. else {
  42. BMPHoldingPond hd = (BMPHoldingPond) getDesignItem();
  43. hd.setLifeTime(value);
  44. }
  45. }
  46. public int getCattles() throws CloneNotSupportedException{
  47. if (getDesignItem() == null)
  48. return _cattles;
  49. else {
  50. BMPHoldingPond hd = (BMPHoldingPond) getDesignItem();
  51. return hd.getCattles();
  52. }
  53. }
  54. public void setCattles(int value) throws CloneNotSupportedException{
  55. if (getDesignItem() == null)
  56. _cattles = value;
  57. else {
  58. BMPHoldingPond hd = (BMPHoldingPond) getDesignItem();
  59. hd.setCattles(value);
  60. }
  61. }
  62. public double getDistance() throws CloneNotSupportedException{
  63. if (getDesignItem() == null)
  64. return _distance;
  65. else {
  66. BMPHoldingPond hd = (BMPHoldingPond) getDesignItem();
  67. return hd.getDistance();
  68. }
  69. }
  70. public void setDistance(double value) throws CloneNotSupportedException{
  71. if (getDesignItem() == null)
  72. _distance = value;
  73. else {
  74. BMPHoldingPond hd = (BMPHoldingPond) getDesignItem();
  75. hd.setDistance(value);
  76. }
  77. }
  78. @Override
  79. public double getCost(){
  80. try{
  81. double sqrtCattles = Math.sqrt(getCattles());
  82. double temp3 = 2.232 * getCattles()+ 11.338 * sqrtCattles;
  83. double temp = 3.72 * getCattles()+ _trenching * 7.94 * sqrtCattles + 0.844 * getDistance() +
  84. _clay_liner * temp3;
  85. double temp2 = (0.5 * 9.5 + 7.47) * temp3;
  86. double max = 1.38e-10 * Math.pow(temp,2.0)
  87. - 5.027e-5 * temp
  88. + 6.736 + _clay_liner * temp2
  89. + _plastic_liner / 0.7 * temp2
  90. + _wire_fence * (189.0 + Math.sqrt(820.0 * getCattles()))
  91. + 10000.0;
  92. max *= 1.1483;
  93. temp3 = 1.512 * getCattles()+ 9.332 * sqrtCattles;
  94. temp = 2.52 * getCattles()+ _trenching * 6.54 * sqrtCattles + 0.844 * getDistance() +
  95. _clay_liner * temp3;
  96. temp2 = (0.5 * 9.5 + 7.47) * temp3;
  97. double min = 1.38e-10 * Math.pow(temp, 2.0)
  98. - 5.027e-5 * temp
  99. + 6.736 + _clay_liner * temp2
  100. + _plastic_liner / 0.7 * temp2
  101. + _wire_fence * (189.0 + Math.sqrt(556.0 * getCattles()))
  102. + 10000.0;
  103. min *= 1.1483;
  104. return min / 2.0 + max / 2.0;
  105. }
  106. catch (Exception e){
  107. }
  108. return 0.0;
  109. }
  110. @Override
  111. public double getAnnualCost(){
  112. try {
  113. if (getLifeTime() > 0)
  114. return getCost() / getLifeTime();
  115. else
  116. return getCost();
  117. } catch (CloneNotSupportedException ex) {
  118. Logger.getLogger(BMPHoldingPond.class.getName()).log(Level.SEVERE, null, ex);
  119. }
  120. return 0.0;
  121. }
  122. public double getMaintenance(){
  123. try{
  124. double temp = 0.03048 * Math.pow(Math.sqrt(1.68 * getCattles()) - 6,2.0);
  125. double min = 1.38e-10 * Math.pow(temp, 2.0)
  126. - 5.027e-5 * temp
  127. + 6.737
  128. + _wire_fence * (24.48 + 3.05 * Math.sqrt(getCattles()))
  129. + 1.25 * getCattles();
  130. temp = 0.03048 * Math.pow(Math.sqrt(2.48 * getCattles()) - 6, 2.0);
  131. double max = 1.38e-10 * Math.pow(temp, 2.0)
  132. - 5.027e-5 * temp
  133. + 6.737
  134. + _wire_fence * (24.48 + 3.71 * Math.sqrt(getCattles()))
  135. + 1.85 * getCattles();
  136. return min / 2.0 + max / 2.0;
  137. }
  138. catch (Exception e){
  139. }
  140. return 0.0;
  141. }
  142. public String getMaintenance_String(){
  143. return String.valueOf(getMaintenance());
  144. }
  145. public double getTotalAnnualCost(){
  146. return getAnnualCost() + getMaintenance();
  147. }
  148. public String getTotalAnnualCost_String() {
  149. return String.valueOf(getTotalAnnualCost());
  150. }
  151. @Override
  152. public String toString(){
  153. return String.valueOf(getID());
  154. //return String.Format("{0}:{1}", ID, _name);
  155. //return String.Format("{0}:{1}:{2}:{3}", ID, _name, Cattles, getDistance());
  156. }
  157. @Override
  158. public String InsertSQL_Economic(int year){
  159. return String.valueOf(getID()) + ","
  160. + String.valueOf(year) + ","
  161. + String.valueOf(getTotalAnnualCost()) + ");";
  162. }
  163. @Override
  164. public String InsertSQL(){
  165. try {
  166. return String.valueOf(getID()) + ","
  167. + String.valueOf(_hru) + ","
  168. + String.valueOf(getCattles()) + ","
  169. + String.valueOf(_clay_liner) + ","
  170. + String.valueOf(_plastic_liner) + ","
  171. + String.valueOf(_wire_fence) + ","
  172. + String.valueOf(_distance) + ","
  173. + String.valueOf(_trenching) + ","
  174. + String.valueOf(getLifeTime()) + ","
  175. + String.valueOf(getCost()) + ","
  176. + String.valueOf(getAnnualCost()) + ","
  177. + String.valueOf(getMaintenance()) + ","
  178. + String.valueOf(getTotalAnnualCost()) + ");";
  179. } catch (CloneNotSupportedException ex) {
  180. Logger.getLogger(BMPHoldingPond.class.getName()).log(Level.SEVERE, null, ex);
  181. }
  182. return null;
  183. }
  184. private static String _column_name_name = "MAP_NUMBER";
  185. @Override
  186. protected void readData() throws SQLException
  187. {
  188. super.readData();
  189. _name = getColumnValue_String(_column_name_name);
  190. _hru = getColumnValue_Int(ScenarioDatabaseStructure.columnNameHoldingPondHRU);
  191. _cattles = getColumnValue_Int(ScenarioDatabaseStructure.columnNameHoldingPondCattles);
  192. _clay_liner = getColumnValue_Int(ScenarioDatabaseStructure.columnNameHoldingPondClayLiner);
  193. _plastic_liner = getColumnValue_Int(ScenarioDatabaseStructure.columnNameHoldingPondPlasticLn);
  194. _wire_fence = getColumnValue_Int(ScenarioDatabaseStructure.columnNameHoldingPondWireFence);
  195. _distance = getColumnValue_Double(ScenarioDatabaseStructure.columnNameHoldingPondDistance);
  196. _trenching = getColumnValue_Double(ScenarioDatabaseStructure.columnNameHoldingPondTrenching);
  197. _pond_year = getColumnValue_Int(ScenarioDatabaseStructure.columnNameHoldingPondPondYrs);
  198. }
  199. }