Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: javatools/util/FormattedNumber.java


1   /*
2    * FormattedNumber.java
3    *
4    * Created on 11 maggio 2002, 15.06
5       Javatools (modified version) - Some useful general classes.
6       Copyright (C) 2002-2003  Chris Bitmead (original) Antonio Petrelli (modified)
7   
8       This program is free software; you can redistribute it and/or modify
9       it under the terms of the GNU General Public License as published by
10      the Free Software Foundation; either version 2 of the License, or
11      (at your option) any later version.
12  
13      This program is distributed in the hope that it will be useful,
14      but WITHOUT ANY WARRANTY; without even the implied warranty of
15      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16      GNU General Public License for more details.
17  
18      You should have received a copy of the GNU General Public License
19      along with this program; if not, write to the Free Software
20      Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21  
22      Contact me at: brenmcguire@users.sourceforge.net
23   */
24  
25  package javatools.util;
26  
27  import java.text.DecimalFormat;
28  
29  /**
30   * It's a java.lang.Number, except in the fact it returns its "toString" value in
31   * a formatted way.
32   * @author Antonio Petrelli
33   * @version 0.0.1
34   */
35  public abstract class FormattedNumber extends java.lang.Number {
36  
37      /** The number to use.
38       */    
39      protected Number num;
40      
41      /** The formatter.
42       */    
43      protected DecimalFormat formatter;
44      
45      /** Creates new FormattedNumber */
46      public FormattedNumber() {
47          num = null;
48          formatter = null;
49      }
50  
51      /** Returns the hash code for the num object.
52       * @return The requested hash code.
53       */    
54      public int hashCode() {
55          return num.hashCode();
56      }
57      
58      /** Returns a formatted string representing the contained number.
59       * @return The formatted string.
60       */    
61      public java.lang.String toString() {
62          return formatter.format(num);
63      }
64      
65      /** Checks if an object is equal to our num object.
66       * @param obj The object to check.
67       * @return <CODE>true</CODE>: the objects are equal;
68       * <CODE>false</CODE>: the objects are NOT equal.
69       */    
70      public boolean equals(java.lang.Object obj) {
71          return num.equals(obj);
72      }
73      
74      /** Returns the byte value for out num object.
75       * @return The requested value.
76       */    
77      public byte byteValue() {
78          return num.byteValue();
79      }
80      
81      /** Returns the double value for out num object.
82       * @return The requested value.
83       */    
84      public double doubleValue() {
85          return num.doubleValue();
86      }
87      
88      /** Returns the float value for out num object.
89       * @return The requested value.
90       */    
91      public float floatValue() {
92          return num.floatValue();
93      }
94      
95      /** Returns the int value for out num object.
96       * @return The requested value.
97       */    
98      public int intValue() {
99          return num.intValue();
100     }
101     
102     /** Returns the long value for out num object.
103      * @return The requested value.
104      */    
105     public long longValue() {
106         return num.longValue();
107     }
108     
109     /** Returns the short value for out num object.
110      * @return The requested value.
111      */    
112     public short shortValue() {
113         return num.shortValue();
114     }
115     
116     /** Sets the formatter to use.
117      * @param pFormatter The formatter to use.
118      */    
119     public void setFormatter(DecimalFormat pFormatter) {
120         formatter = pFormatter;
121     }
122     
123     /** Returns the currently using formatter.
124      * @return The formatter.
125      */    
126     public DecimalFormat getFormatter() {
127         return formatter;
128     }
129 }