JMapViewer, einfache Komponenten für OpenStreepMap Karte

Siehe http://wiki.openstreetmap.org/wiki/JMapViewer.

  • Provides integrated zoom controls (slider and buttons) in the left upper corner (can be hidden)
  • Switch between different tile sources: Mapnik, Tiles@Home, Cyclemap, … (other tiled maps can be used, too)
  • Configurable in-memory and file-based caching of loaded map tiles
  • A list of map markers (the yellow circles in the screenshot) can be added. Map markers of different shape can be easily added by implementing the MapMarker interface.
  • Configurable/Extentable/Replaceable controller (code part that manages mouse interaction and how the map reacts to it)
  • Requirement: Java 1.6
  • License: GPL

 

JMapViewer demo app screenshot

Apache ODF Toolkit in Release 0.6

Aus dem Changelog https://www.apache.org/dist/incubator/odftoolkit/CHANGES-0.6-incubating.txt:

* Added document encryption support

* Added metadata support

* Support for OpenDocument-v1.2

* Additional APIs for Simple API

Zum Projekt selbst sagt die Homepage:

The Apache ODF Toolkit is a set of Java modules that allow programmatic creation, scanning and manipulation of Open Document Format (ISO/IEC 26300 == ODF) documents. Unlike other approaches which rely on runtime manipulation of heavy-weight editors via an automation interface, the ODF Toolkit is lightweight and ideal for server use.

Dokumente sind leicht erstellt, siehe https://incubator.apache.org/odftoolkit/simple/gettingstartguide.html:

import java.net.URI;

import org.odftoolkit.simple.TextDocument;
import org.odftoolkit.simple.table.Cell;
import org.odftoolkit.simple.table.Table;
import org.odftoolkit.simple.text.list.List;

public class HelloWorld {
    public static void main(String[] args) {
        TextDocument outputOdt;
        try {
            outputOdt = TextDocument.newTextDocument();

            // add image
            outputOdt.newImage(new URI("odf-logo.png"));

            // add paragraph
            outputOdt.addParagraph("Hello World, Hello Simple ODF!");

            // add list
            outputOdt.addParagraph("The following is a list.");
            List list = outputOdt.addList();
            String[] items = {"item1", "item2", "item3"};
            list.addItems(items);

            // add table
            Table table = outputOdt.addTable(2, 2);
            Cell cell = table.getCellByPosition(0, 0);
            cell.setStringValue("Hello World!");

            outputOdt.save("HelloWorld.odt");
        } catch (Exception e) {
            System.err.println("ERROR: unable to create output file.");
        }
    }
}

UML-Diagramme mit ObjectAid für Eclipse

Von http://www.objectaid.com/:

The ObjectAid UML Explorer is an agile and lightweight code visualization tool for the Eclipse IDE. It shows your Java source code and libraries in live UML class and sequence diagrams that automatically update as your code changes. The image below is a class diagram of actual source code; click on it to see the editor in the Eclipse Java Perspective

Ein kleines HOWTO unter http://fuzz-box.blogspot.de/2012/09/how-to-generate-uml-diagrams-from-java.html?m=1.

http://download.java.net/jdk8/docs/api/java/util/concurrent/locks/StampedLock.html

Neue Klasse in Java 8. Implementiert jedoch nicht Lock, wie es ReentrantLock tut. Aus der API:

A capability-based lock with three modes for controlling read/write access. The state of a StampedLock consists of a version and mode. Lock acquisition methods return a stamp that represents and controls access with respect to a lock state; "try" versions of these methods may instead return the special value zero to represent failure to acquire access. Lock release and conversion methods require stamps as arguments, and fail if they do not match the state of the lock. The three modes are:

  • Writing. Method writeLock() possibly blocks waiting for exclusive access, returning a stamp that can be used in method unlockWrite(long) to release the lock. Untimed and timed versions of tryWriteLock are also provided. When the lock is held in write mode, no read locks may be obtained, and all optimistic read validations will fail.
  • Reading. Method readLock() possibly blocks waiting for non-exclusive access, returning a stamp that can be used in method unlockRead(long) to release the lock. Untimed and timed versions of tryReadLock are also provided.
  • Optimistic Reading. Method tryOptimisticRead() returns a non-zero stamp only if the lock is not currently held in write mode. Method validate(long) returns true if the lock has not been acquired in write mode since obtaining a given stamp. This mode can be thought of as an extremely weak version of a read-lock, that can be broken by a writer at any time. The use of optimistic mode for short read-only code segments often reduces contention and improves throughput. However, its use is inherently fragile. Optimistic read sections should only read fields and hold them in local variables for later use after validation. Fields read while in optimistic mode may be wildly inconsistent, so usage applies only when you are familiar enough with data representations to check consistency and/or repeatedly invoke method validate(). For example, such steps are typically required when first reading an object or array reference, and then accessing one of its fields, elements or methods.

This class also supports methods that conditionally provide conversions across the three modes. For example, method tryConvertToWriteLock(long) attempts to "upgrade" a mode, returning a valid write stamp if (1) already in writing mode (2) in reading mode and there are no other readers or (3) in optimistic mode and the lock is available. The forms of these methods are designed to help reduce some of the code bloat that otherwise occurs in retry-based designs.

StampedLocks are designed for use as internal utilities in the development of thread-safe components. Their use relies on knowledge of the internal properties of the data, objects, and methods they are protecting. They are not reentrant, so locked bodies should not call other unknown methods that may try to re-acquire locks (although you may pass a stamp to other methods that can use or convert it). The use of read lock modes relies on the associated code sections being side-effect-free. Unvalidated optimistic read sections cannot call methods that are not known to tolerate potential inconsistencies. Stamps use finite representations, and are not cryptographically secure (i.e., a valid stamp may be guessable). Stamp values may recycle after (no sooner than) one year of continuous operation. A stamp held without use or validation for longer than this period may fail to validate correctly. StampedLocks are serializable, but always deserialize into initial unlocked state, so they are not useful for remote locking.

The scheduling policy of StampedLock does not consistently prefer readers over writers or vice versa. All "try" methods are best-effort and do not necessarily conform to any scheduling or fairness policy. A zero return from any "try" method for acquiring or converting locks does not carry any information about the state of the lock; a subsequent invocation may succeed.

Because it supports coordinated usage across multiple lock modes, this class does not directly implement the Lock or ReadWriteLock interfaces. However, a StampedLock may be viewedasReadLock(), asWriteLock(), or asReadWriteLock() in applications requiring only the associated set of functionality.

Google Guava: EvictingQueue in Version 15

Google Guava hat Folgendes ursprünglich geteilt:

EvictingQueue: a non-blocking, bounded queue
In Guava 15, we are introducing EvictingQueue [1], which is a non-blocking, bounded queue that automatically evicts (removes) elements from the head of the queue when attempting to add elements to a full queue. This is different from conventional bounded queues, which either block or reject new elements when full.
Java provides several Queue implementations, depending on what features you need. For example:
Unbounded, non-blocking: ArrayDeque, LinkedList, PriorityQueue
Unbounded, blocking: LinkedBlockingDeque, LinkedBlockingQueue, SynchronousQueue
Bounded, blocking: ArrayBlockingQueue, LinkedBlockingDeque, LinkedBlockingQueue
However, a bounded, non-blocking implementation is noticeably missing from the JDK. Like many of the JDK implementations, EvictingQueue is not thread-safe and does not permit null elements. If you need thread safety, you must wrap it in a synchronized wrapper (Queues#synchronizedQueue). If you need null elements, please give this wiki page [2] a read.
An EvictingQueue can be used to keep track of recent items in a bounded buffer, or even as a simple FIFO cache. Hopefully you’ll find it useful!
Cheers,
-+Kurt Alfred Kluever, Guavian
[1] http://docs.guava-libraries.googlecode.com/git/javadoc/com/google/common/collect/EvictingQueue.html
[2] https://code.google.com/p/guava-libraries/wiki/LivingWithNullHostileCollections

Lambda-Ausdrücke in C++ und ausgezeichnetstes Folien-Set für C(++) Besserwisser

Selbst C++ (aktueller Standard) hat Lambda-Ausdrücke. So wie sich Java weiter entwickelt, tut es auch C++ (was gerne vergessen wird), das “frühere” C++, hat wenig mehr mit dem heutigen zu tun.

Was sich noch so alles in C++11 getan hat: http://www2.research.att.com/~bs/C++0xFAQ.html

Und für alle C(++) Entwickler, die glauben, sie wüssten schon alles: sehr sehr nett gemachter Folienset http://www.slideshare.net/olvemaudal/deep-c, als PDF unter http://this-download-would-be-faster-with-a-premium-account-at-good.net/dl/1998998/0/0/1318327568/4ea245e7a2f9ea9dbfab51cca1915f9c710c8928/anonroot/0/6/1/061c/deepcslidesoct2012-111010033910-phpapp01.pdf.

Buchkritik: Die Java-Syntax, Michael Kofler

Der Autor ist jedem ein Begriff, der in der Unix-Welt einmal unterwegs war: Wo die Java-Insel das Standard-Werk für Java ist, ist Koflers Linux-Buch (jetzt auch bei Galileo) DAS Buch für das Open-Source Betriebssystem. Nicht vielen bekannt ist, dass Kofler neben Linux auch noch weitere Bücher verfasst hat, insbesondere als eBook. Eines davon handelt über Java und trägt den kurzen Titel „Die Java-Syntax“. Hier kommen Assoziationen zur Java Language Specification auf, doch mit einer formalen Beschreibung der Sprache hat dieses eBook überhaupt nichts gemeinsam — es ist eher eine allgemeine Einführung in Java und einigen Bibliotheken, wie Date/Time, Threading und Collection. Die Beschreibung ist dabei nicht sonderlich tief und einige Begrifflichkeiten sind doch sehr ungewöhnlich, die Collection-Klassen heißen etwas Aufzählungsklassen, der Autor schreibt oft „Klasse“, wenn er „Typ“ meint, die Sprachst ist im Allgemeinen etwas ungenau und könnte präziser sein, teils irreführend wie bei „Normalerweise können Methoden nur genutzt werden, wenn vorher ein Objekt der betreffenden Klasse erzeugt wird“ klingt, als ob statische Methoden un-normal seien und abartig. Einige Aussagen zeugen von nicht sehr tiefem Java-Verständnis, etwas bei den Überschreibungsregeln der throws-Klausel, wenn Kofler über die Implementierung der Schnittstelle AutoCloseable schreibt „Sie müssen nur darauf achten, dass Sie Ihre close-Methode mit throws Exception deklarieren“. Oder wenn der Autor den Minus-Strich im Paketnamen wählt (de.meine-firma) und ein ganzes Beispiel mit Pakten, und Jar-Archiven darum aufbaut, was aber nie compilieren würde, da „-“ in Bezeichnern überhaupt nicht erlaubt ist. Zusammenfassend lässt sich festhalten, dass Kofler eine Einführung in Java gelungen ist, die aber weit hinter seinen anderen Büchern zurückbleibt. Im dem Segment der Einführungsbücher wird „Die Java-Syntax“ es daher schwer haben. Eine Kurzvorstellung vom Autor gibt es in einem Video, eine Leseprobe auf seiner Webseite. Ein Buch-Update ist geplant.

Die Java-Syntax; Variablen Operatoren Klassen Exceptions Multi-Threading Generics und Collections Lambda-Ausdrücke. Für Java 6, 7 und 8

Michael Kofler. Verlag ebooks.kofler. ISBN 978-3-902643-09-4. 216 Seiten