ubiware.core.visualizer
Class Formatter

java.lang.Object
  extended by ubiware.core.visualizer.Formatter

final class Formatter
extends java.lang.Object

Default formatter used by the package in order to avoid creating many instances.

Warning: Methods making use of this class/instance should synchronize it, using the singletong instance as a monitor, for example:

 ...
 Formatter f = Formatter.getSingleton();
 synchronized(f) {
 // do stuff...
 // ...
 }
 

Also this class provides a convenience method, format(java.lang.String, java.lang.Object...).

Author:
Nikos Mouchtaris

Method Summary
static java.lang.String format(java.lang.String format, java.lang.Object... args)
           Convenience method to produce a formatted string on the fly.
 java.util.Formatter getFormatter()
           Provided access to the actual Formatter.
 java.io.CharArrayWriter getOut()
           Provides access to the destination CharArrayWriter so that it can be reset.
(package private) static Formatter getSingleton()
           Provides access to the only instance allowed to be of this class.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

format

public static java.lang.String format(java.lang.String format,
                                      java.lang.Object... args)

Convenience method to produce a formatted string on the fly.

This method will delegate format and args to the underlying Formatter.format(String,Object...) method. It will also do that in the adviced synchronized manner.

This method is completely independent from the rest of the class, it's build as a layer above it, and its effects can be reproduced by the following code:

 final Formatter F = getSingleton();
 synchronized (F) {
        F.getOut().reset();
        return F.getFormatter().format(format, args).toString();
 }
 

Parameters:
format - delegated to Formatter.format(String,Object...)
args -
Returns:

getSingleton

static Formatter getSingleton()

Provides access to the only instance allowed to be of this class.

Warning:Methods making use of this class/instance should synchronize it, using the singletong instance as a monitor, for example:

 ...
 Formatter f = Formatter.getSingleton();
 synchronized(f) {
 // do stuff...
 // ...
 }
 

Returns:
the only and only instance allowed to be of this class.

getFormatter

public java.util.Formatter getFormatter()

Provided access to the actual Formatter.

The destination to which the formatter writes is a CharArrayWriter and should be cleared by invoking CharArrayWriter.reset(). It is not done automatically but it is not ensured that the contents of the array will remain untouched between invokations.

To obtain the destination char array without the need to cast anything, one can use getOut().

Returns:
a shared instace of a Formatter..

getOut

public java.io.CharArrayWriter getOut()

Provides access to the destination CharArrayWriter so that it can be reset.

Returns:
the destination CharArrayWriter