EMMA Coverage Report (generated Wed Jun 28 19:54:35 CEST 2006)
[all classes][smallsql.database]

COVERAGE SUMMARY FOR SOURCE FILE [Money.java]

nameclass, %method, %block, %line, %
Money.java100% (1/1)83%  (15/18)92%  (248/271)89%  (40,8/46)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class Money100% (1/1)83%  (15/18)92%  (248/271)89%  (40,8/46)
Money (float): void 0%   (0/1)0%   (0/9)0%   (0/3)
hashCode (): int 0%   (0/1)0%   (0/9)0%   (0/1)
unscaledValue (): long 0%   (0/1)0%   (0/3)0%   (0/1)
equals (Object): boolean 100% (1/1)86%  (12/14)85%  (0,8/1)
<static initializer> 100% (1/1)100% (6/6)100% (2/2)
Money (): void 100% (1/1)100% (3/3)100% (2/2)
Money (double): void 100% (1/1)100% (9/9)100% (3/3)
createFromUnscaledValue (int): Money 100% (1/1)100% (10/10)100% (3/3)
createFromUnscaledValue (long): Money 100% (1/1)100% (9/9)100% (3/3)
doubleValue (): double 100% (1/1)100% (6/6)100% (1/1)
floatValue (): float 100% (1/1)100% (6/6)100% (1/1)
getImmutableObject (): Object 100% (1/1)100% (3/3)100% (1/1)
intValue (): int 100% (1/1)100% (7/7)100% (1/1)
longValue (): long 100% (1/1)100% (7/7)100% (1/1)
parseMoney (String): long 100% (1/1)100% (4/4)100% (1/1)
toBigDecimal (): BigDecimal 100% (1/1)100% (17/17)100% (2/2)
toByteArray (): byte [] 100% (1/1)100% (85/85)100% (11/11)
toString (): String 100% (1/1)100% (64/64)100% (8/8)

1/* =============================================================
2 * SmallSQL : a free Java DBMS library for the Java(tm) platform
3 * =============================================================
4 *
5 * (C) Copyright 2004-2006, by Volker Berlin.
6 *
7 * Project Info:  http://www.smallsql.de/
8 *
9 * This library is free software; you can redistribute it and/or modify it 
10 * under the terms of the GNU Lesser General Public License as published by 
11 * the Free Software Foundation; either version 2.1 of the License, or 
12 * (at your option) any later version.
13 *
14 * This library is distributed in the hope that it will be useful, but 
15 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 
16 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 
17 * License for more details.
18 *
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, 
22 * USA.  
23 *
24 * [Java is a trademark or registered trademark of Sun Microsystems, Inc. 
25 * in the United States and other countries.]
26 *
27 * ---------------
28 * Money.java
29 * ---------------
30 * Author: Volker Berlin
31 * 
32 */
33package smallsql.database;
34 
35import java.math.*;
36 
37public class Money extends Number implements Mutable{
38 
39    long value;
40 
41    private Money(){
42    }
43 
44    public Money(double value){
45        this.value = (long)(value * 10000);
46    }
47 
48    public Money(float value){
49        this.value = (long)(value * 10000);
50    }
51 
52    public static Money createFromUnscaledValue(long value){
53        Money money = new Money();
54        money.value = value;
55        return money;
56    }
57 
58    public static Money createFromUnscaledValue(int value){
59        Money money = new Money();
60        money.value = value;
61        return money;
62    }
63 
64    public int intValue() {
65        return (int)(value / 10000.0);
66    }
67    public float floatValue() {
68        return value / 10000.0F;
69    }
70    public double doubleValue() {
71        return value / 10000.0;
72    }
73    public long longValue() {
74        return (long)(value / 10000.0);
75    }
76 
77    public String toString(){
78                StringBuffer buffer = new StringBuffer();
79                buffer.append(longValue()).append('.');
80                final long v = Math.abs(value);
81                buffer.append( (char)((v % 10000) / 1000 + '0') );
82                buffer.append( (char)((v % 1000) / 100 + '0') );
83                buffer.append( (char)((v % 100) / 10 + '0') );
84                buffer.append( (char)((v % 10) + '0') );
85                
86        return buffer.toString();
87    }
88 
89    public boolean equals(Object obj){
90        return (obj instanceof Money && ((Money)obj).value == value);
91    }
92 
93    public int hashCode(){
94        return (int)(value ^ (value >>> 32));
95    }
96 
97    public long unscaledValue(){
98        return value;
99    }
100 
101    public static long parseMoney( String str ){
102        // FIXME ohne Umweg über double implementieren
103        return Utils.doubleToMoney(Double.parseDouble( str ));
104    }
105    
106    private byte[] toByteArray(){
107            byte[] bytes = new byte[8];
108            
109                int offset = 0;
110                bytes[offset++] = (byte)(value >> 56);
111                bytes[offset++] = (byte)(value >> 48);
112                bytes[offset++] = (byte)(value >> 40);
113                bytes[offset++] = (byte)(value >> 32);
114                bytes[offset++] = (byte)(value >> 24);
115                bytes[offset++] = (byte)(value >> 16);
116                bytes[offset++] = (byte)(value >> 8);
117                bytes[offset++] = (byte)(value);
118            return bytes;
119    }
120    
121        public BigDecimal toBigDecimal(){
122                if(value == 0) return ZERO;
123                return new BigDecimal( new BigInteger( toByteArray() ), 4 );
124        }
125 
126 
127        public Object getImmutableObject(){
128                return toBigDecimal();
129        }
130        
131        static private final BigDecimal ZERO = new BigDecimal("0.0000");
132}

[all classes][smallsql.database]
EMMA 2.1.5320 (stable) (C) Vladimir Roubtsov