connection = DAO.getDataSource().getConnection();
pstmt = connection.prepareStatement(query);
ResultSet rs = pstmt.executeQuery();
while (rs.next()) {
PlantType plant = new PlantType(rs.getInt("plant_type_id"));
plant.setSpeciesName(rs.getString("species_name"));
plant.setCost(rs.getInt("cost"));
plant.setDescription(rs.getString("description"));
plant.setCategory(rs.getString("category"));
plant.setAvgBiomass(rs.getInt("max_biomass"));
plant.setWaterNeedFrequency(rs.getInt("water_need_frequency"));
plant.setLightNeedFrequency(rs.getInt("light_need_frequency"));
plant.setGrowRadius(rs.getFloat("grow_radius"));
plant.setCarryingCapacity(rs.getFloat("carrying_capacity"));
String[] nodeList = rs.getString("node_list").split(",");
int[] newNodeList = new int[nodeList.length];
HashMap<Integer, Integer> nodeAmountList = new HashMap<Integer, Integer>();
for (int i = 0; i < nodeList.length; i++) {
String[] nodePair = nodeList[i].split(":");
newNodeList[i] = Integer.parseInt(nodePair[0]);
if (nodePair.length == 1) {
nodeAmountList.put(newNodeList[i], 1);
} else {
nodeAmountList.put(newNodeList[i], Integer.parseInt(nodePair[1]));
}
}
plant.setNodeList(newNodeList);
plant.setNodeAmountList(nodeAmountList);
plant.setTrophicLevel(rs.getFloat("trophic_level"));
plant.setGrowthRate(rs.getFloat("growth_rate"));
plant.setModelID(rs.getInt("model_id"));
plant.setHealChance(rs.getFloat("heal_chance"));
plant.setGroupCapacity(rs.getInt("group_capacity"));
plantList.add(plant);
}
rs.close();
pstmt.close();
HashMap<Integer, List<Integer>> hPredatorMap = HerbivoreDAO.getPreyToPredatorTable();
for (PlantType plant : plantList) {
int plant_id = plant.getID();
if (hPredatorMap.containsKey(plant_id)) {
for (int predator_id : hPredatorMap.get(plant_id)) {
plant.addPredatorID(predator_id, Constants.ORGANISM_TYPE_ANIMAL);
}
}
}
} finally {
if (connection != null) {