Mindsilver entwickelt eine neuen Gui-Builder für Swing-Anwendungen, der irgendwie an Matisse erinnert, aber doch mit automatischen Controllern weit über Matisse herausragt. Unter http://www.mindsilver.com/ gibt es ein Demo. Hervorragend ist der konsequente Einsatz von Drag & Drop.
Monat: September 2009
Erste Sprachänderung in Java 7
Die Diamand-Schreibweise zur Abkürzung von generischen Instanziierungen ist in Java 7 Build 72 eingegangen.
- http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6840638
- http://download.java.net/jdk7/changes/jdk7-b72.html
- http://download.java.net/jdk7/
Update von Findbugs auf 1.3.9
Findbugs http://findbugs.sourceforge.net/ hat die Versionsnummer erhöht und unter anderem neue Detektoren aufgenommen. Von der Webseite:
- New bug patterns; in some cases, bugs previous reported as other bug patterns are reported as instances of these new bug patterns in order to make it easier for developers to understand the bug reports
- BC_IMPOSSIBLE_DOWNCAST
- BC_IMPOSSIBLE_DOWNCAST_OF_TOARRAY
- EC_INCOMPATIBLE_ARRAY_COMPARE
- JLM_JSR166_UTILCONCURRENT_MONITORENTER
- LG_LOST_LOGGER_DUE_TO_WEAK_REFERENCE
- NP_CLOSING_NULL
- RC_REF_COMPARISON_BAD_PRACTICE
- RC_REF_COMPARISON_BAD_PRACTICE_BOOLEAN
- RV_RETURN_VALUE_OF_PUTIFABSENT_IGNORED
- SIC_THREADLOCAL_DEADLY_EMBRACE
- UR_UNINIT_READ_CALLED_FROM_SUPER_CONSTRUCTOR
- VA_FORMAT_STRING_EXPECTED_MESSAGE_FORMAT_SUPPLIED
- Providing a bug rank (1-20), and the ability to filter by bug rank. Eventually, it will be possible to specify your own rules for ranking bugs, but the procedure for doing so hasn’t been specified yet.
- Fixed about 45 bugs filed through SourceForge
- Various reclassifications and priority tweaks
- Added more bug annotations to a variety of bug reports. This provides more context for understanding bug reports (e.g., if the value in question was is the return value of a method, the method is described as the source of the value in a bug annotation). This also provide more accurate tracking of issues across versions of the code being analyzed, but has the downside that when comparing results from FindBugs 1.3.8 and FindBugs 1.3.9 on the same version of code being analyzed, FindBugs may think that mistakenly believe that the issue reported by 1.3.8 was fixed and a new issue was introduced that was reported by FindBugs 1.3.9. While annoying, it would be unusual for more than a dozen issues per million lines of codes to be mistracked.
Thema der Woche: Programmieren mit einem bisschen Geo
Schreibe eine Klasse Location, die longitude und latitude speichert. Die Attribute sind vom Type double. Gib Setter/Getter an und einen Standard- und parametrisieren Konstruktor. Die Klasse Location soll die Abstands-Utility-Funktionen aus http://www.tutego.de/blog/javainsel/2009/09/latitudelongitude-distance-in-java/ bekommen.
Die Klasse Locations soll beliebig viele Location-Objekte speichern können. Dazu ist eine addLocation()-Methode nötig, die einen Ort als String mit einer Location annimmt und in eine intern Datenstruktur übernimmt. addLocation() soll überladen sein, dass man einmal den Ort über ein Location-Objekt bestimmt und einmal über Longitude und Latitude. Eine toString()-Methode soll angeben, wie viele Orte enthalten sind. Eine Methode Location findLocation(String location) soll die Location für einen Ort zurückgeben. Schreibe eine Methode List within(Location loc, double radius) Methode, die alle Orte liefert, die nicht weiter als radius von dem Ort entfernt sind. Nutzt die passende statische Funktionen aus Location für den Abstand! Nimm eine überladene Methode within() hinzu, die eine maximale Anzahl Elemente in der Rückgabeliste bestimmt.
Schreibe eine Klasse LocationApplication mit einem main(). Füge einige Location-Objekte ein und teste die Bereichsabfrage.
Eine Klasse LocationRepository soll zwei statische Methoden enthalten: Locations loadLocations() und void saveLocations(Locations locations). Die Methoden sollen Locations aus einer Text-Datei lesen und schreiben können. Nutze dazu beliebige Geokoordinaten. Das Dateiformat kann frei bestimmt werden.
Passe die Methode within() an, so dass die Liste sortiert ist nach dem Abstand zum Anfrageort. Schreibe dazu einen DistanceComparator und nutze die Collections.sort()-Methode.
Modelliere mit NetBeans eine grafische Oberfläche, mit zwei Reitern (JTabbedPane). In dem ersten Reiter soll man drei Textboxen haben für Ort, Longitude, Latitude und einen „Hinzufügen“ Button. Damit sollen neue Orte dem Locations hinzugefügt werden. Auf dem zweiten Reiter soll der Anwender Abfragen vornehmen können. Eine Eingabezeile für ein Ort (oder Longitude, Latitude) und Radius soll zu max. 10 Ergebnissen führen.
Installiere Google Earth. Bei einer Bereichsabfrage erzeugte eine KML-Datei mit allen Ergebnissen. Diese Datei soll beim Start von Google Eath als Startparameter mitgegeben werden. Externe Programme startet man mit dem ProcessBuilder. Die Insel gibt ein Beispiel für diese Klasse. Überlegen, wie am einfachsten und effektivsten XML geschrieben werden kann.
Latitude/Longitude distance in Java
public class LongLatUtils
{
/**
* Calculates the great circle distance between two points on the Earth. Uses the Haversine Formula.
*
* @param latitude1 Latitude of first location in decimal degrees.
* @param longitude1 Longitude of first location in decimal degrees.
* @param latitude2 Latitude of second location in decimal degrees.
* @param longitude2 Longitude of second location in decimal degrees.
* @return Distance in meter.
*/
public static double distance( double latitude1, double longitude1, double latitude2, double longitude2 )
{
double latitudeSin = Math.sin( Math.toRadians(latitude2 - latitude1) / 2 );
double longitudeSin = Math.sin( Math.toRadians(longitude2 - longitude1) / 2 );
double a = latitudeSin * latitudeSin
+ Math.cos( Math.toRadians(latitude1)) * Math.cos(Math.toRadians(latitude2) ) * longitudeSin * longitudeSin;
double c = 2 * Math.atan2( Math.sqrt(a), Math.sqrt(1 - a) );
return 6378137 * c;
}
/**
* Converts latitude and longitude from degrees, minutes, and seconds in decimal degrees.
*
* @param degrees
* @param minutes
* @param seconds
* @return Latitude and longitude in decimal degrees.
*/
public static double convertDegreesMinutesSecondsToDecimalDegrees( int degrees, int minutes, int seconds )
{
return degrees + minutes/60. + seconds/3600.;
}
// public static void main(String[] args)
// {
// System.out.println( convertDegreesMinutesSecondsToDecimalDegrees(38, 53, 23 ));
// System.out.println( distance(38.898556, -77.037852, 38.897147, -77.043934));
// }
}