/** * Search all the stars that has all the condition of the string * * @param _searchText The string that will be analyze by the function decryptText * @param _date It's the date that will be use to search the stars * @param _dLat It's the latitude of the star's pointer * @param _dLon It's the longitude of the star's pointer * @throws SQLException * @return Return an arraylist of CelestialObject. */ public ArrayList<CelestialObject> starsForText( String _searchText, Calendar _date, double _dLat, double _dLon) throws SQLException { ArrayList<CelestialObject> al_stars = new ArrayList<CelestialObject>(); int l_id; int l_HIP; int l_HD; int l_HR; String l_ProperName; double l_dRA; double l_Dec; double l_dDistance; double l_dMag; double l_dColorIndex; boolean secured = false; HashMap<String, String> hm_sWhere = decryptText(_searchText); Iterator<String> l_it = hm_sWhere.keySet().iterator(); String[] table = {this.sTable}; String[] field = {"*"}; String[][] where = new String[hm_sWhere.size()][3]; String[] orderby = {"id"}; int[] limit = {}; secured = true; int i = 0; while (l_it.hasNext()) { String l_sTemp = l_it.next().toString(); where[i][0] = l_sTemp; where[i][1] = "LIKE"; where[i][2] = "%" + hm_sWhere.get(l_sTemp).toString().trim() + "%"; i++; } ResultSet result = selectQuery(field, table, where, orderby, limit, secured); try { if (!isDouble(Double.toString(_dLon)) || !isDouble(Double.toString(_dLat))) throw new IllegalArgumentException( "Error : Illegal latitude/longitude. Please check the coordinates !"); } catch (IllegalArgumentException e) { log.warning(e.getMessage()); _dLat = _dLon = 0; } Mathematics l_calc = new Mathematics(_date, _dLat, _dLon); try { while (result.next()) { int l_Bayer = 0; l_id = result.getInt("id"); l_HIP = result.getInt("HIP"); l_HD = result.getInt("HD"); l_HR = result.getInt("HR"); l_ProperName = result.getString("ProperName"); l_dRA = result.getDouble("RA"); l_Dec = result.getDouble("Dec"); l_dDistance = result.getDouble("Distance"); l_dMag = result.getDouble("Mag"); l_dColorIndex = result.getDouble("ColorIndex"); CelestialObject l_star = new CelestialObject( l_id, l_HIP, l_HD, l_HR, l_ProperName, l_dRA, l_Dec, l_dDistance, l_dMag, l_dColorIndex, l_Bayer); if (l_id == 1) { l_calc.calculatePositionSun(); l_star.setDec(l_calc.getDeclination()); l_star.setRA(l_calc.getAscension()); } else if (l_id == 2) { l_calc.calculatePositionMoon(); l_star.setDec(l_calc.getDeclination()); l_star.setRA(l_calc.getAscension()); double l_now = l_calc.getMoonBrightness(false); double l_yes = l_calc.getMoonBrightness(true); if (l_yes > l_now) l_now *= -1; l_star.setMag(l_now); } else l_calc.calculateAll(l_star.getDec(), l_star.getRA()); if (l_calc.getHeight() > 0) { l_star.setXReal(l_calc.getX()); l_star.setYReal(l_calc.getY()); l_star.SetAzimuth(l_calc.getAzimuth()); l_star.SetHeight(l_calc.getHeight()); al_stars.add(l_star); } l_star = null; } } catch (SQLException e) { log.warning("Problem with the query's result !"); } result.close(); return al_stars; }
/** * Search all the stars that could be in the hemisphere * * @param _date It's the date that will be use to search the stars * @param _dLat It's the latitude of the star's pointer * @param _dLon It's the longitude of the star's pointer * @throws SQLException * @return Return an arraylist that contains all the stars could be possible to see */ public ArrayList<CelestialObject> starsForCoordinates(Calendar _date, double _dLat, double _dLon) throws SQLException { ArrayList<CelestialObject> al_stars = new ArrayList<CelestialObject>(); int l_Bayer = 0; int l_id; int l_HIP; int l_HD; int l_HR; String l_ProperName; double l_dRA; double l_Dec; double l_dDistance; double l_dMag; double l_dColorIndex; try { if (!isDouble(Double.toString(_dLon)) || !isDouble(Double.toString(_dLat))) throw new IllegalArgumentException( "Error : Illegal latitude/longitude. Please check the coordinates !"); } catch (IllegalArgumentException e) { log.warning(e.getMessage()); _dLat = _dLon = 0; } Mathematics l_calc = new Mathematics(_date, _dLat, _dLon); for (CelestialObject star : this.allStars) { l_id = star.getId(); l_HIP = star.getHIP(); l_HD = star.getHD(); l_HR = star.getHR(); l_ProperName = star.getProperName(); l_dRA = star.getRA(); l_Dec = star.getDec(); l_dDistance = star.getDistance(); l_dMag = star.getMag(); l_dColorIndex = star.getColorIndex(); CelestialObject l_star = new CelestialObject( l_id, l_HIP, l_HD, l_HR, l_ProperName, l_dRA, l_Dec, l_dDistance, l_dMag, l_dColorIndex, l_Bayer); if (l_id == 1) // Sun { l_calc.calculatePositionSun(); l_star.setDec(l_calc.getDeclination()); l_star.setRA(l_calc.getAscension()); } else if (l_id == 2) // Moon { l_calc.calculatePositionMoon(); l_star.setDec(l_calc.getDeclination()); l_star.setRA(l_calc.getAscension()); double l_now = l_calc.getMoonBrightness(false); double l_yes = l_calc.getMoonBrightness(true); if (l_yes > l_now) l_now *= -1; l_star.setMag(l_now); } else l_calc.calculateAll(l_star.getDec(), l_star.getRA()); if (l_calc.getHeight() >= 0) { l_star.setXReal(l_calc.getX()); l_star.setYReal(l_calc.getY()); l_star.SetAzimuth(l_calc.getAzimuth()); l_star.SetHeight(l_calc.getHeight()); al_stars.add(l_star); } l_star = null; } return al_stars; }