fc.util
Class ThreadLocalNumberFormat
java.lang.Object
fc.util.ThreadLocalNumberFormat
public final class ThreadLocalNumberFormat
- extends java.lang.Object
Useful to store thread-local number format instances. This class is
intended for servlets/molly pages. Instead of static get/set methods,
this class must be instantiated and the instance methods used to get/set
the calendar object. This allows multiple instances of this class in the
webapp, with each instance being able to get/set a separate calendar. [If
the methods in this class were static, then only 1 calendar could be
get/set per thread].
Each thread must remember to individually create a
separate calendar instance and store it via the set method. The
usage idiom is:
//WebApp has a map of ThreadLocalNumberFormat's and also a instance variable
//pointing to a default ThreadLocalNumberFormat
ThreadLocalNumberFormat mynf = WebApp.getThreadLocalNumberFormat("foo");
if (mynf.isNull()) {
mynf.set(NumberFormat.getInstance());
}
NumberFormat nf = mynf.get();
Note, the lines in red are always needed anywhere/anytime this class is used.
(note, it just so happens that the NumberFormat.getInstance()
returns (at
least for now) a new object every time it is called, which is why it is
being used in the example above, else we would have to manually create a new
NumberFormat instance instead).
Method Summary |
java.text.NumberFormat |
get()
|
boolean |
isNull()
|
static void |
main(java.lang.String[] args)
|
void |
set(java.text.NumberFormat nf)
|
Methods inherited from class java.lang.Object |
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
ThreadLocalNumberFormat
public ThreadLocalNumberFormat()
get
public java.text.NumberFormat get()
set
public void set(java.text.NumberFormat nf)
isNull
public boolean isNull()
main
public static void main(java.lang.String[] args)
throws java.lang.Exception
- Throws:
java.lang.Exception