Clover coverage report - Diasparsoft Toolkit - 0.22
Coverage timestamp: Tue Jun 8 2004 12:41:26 EDT
file stats: LOC: 142   Methods: 24
NCLOC: 110   Classes: 1
30 day Evaluation Version distributed via the Maven Jar Repository. Clover is not free. You have 30 days to evaluate it. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover
 
 Source file Conditionals Statements Methods TOTAL
Money.java 16.7% 31.7% 41.7% 33.8%
coverage coverage
 1   
 package com.diasparsoftware.java.util;
 2   
 
 3   
 import java.io.Serializable;
 4   
 import java.text.*;
 5   
 import java.util.*;
 6   
 
 7   
 public class Money implements Cloneable, Serializable, Comparable {
 8   
     public static Money ZERO = Money.dollars(0);
 9   
 
 10  11
     public static Money cents(int cents) {
 11  11
         return new Money(cents);
 12   
     }
 13   
 
 14  77
     public static Money dollars(int dollars) {
 15  77
         return new Money(dollars, 0);
 16   
     }
 17   
 
 18  22
     public static Money dollars(int dollars, int cents) {
 19  22
         return new Money(dollars, cents);
 20   
     }
 21   
 
 22  0
     public static Money parse(String moneyAsString) {
 23  0
         try {
 24  0
             return new Money(parseToCents(moneyAsString));
 25   
         }
 26   
         catch (ParseException e) {
 27  0
             e.printStackTrace();
 28   
         }
 29  0
         return null;
 30   
     }
 31   
 
 32  0
     private static int parseToCents(String moneyAsString)
 33   
         throws ParseException {
 34   
 
 35  0
         double amountInDollars =
 36   
             NumberFormat
 37   
                 .getCurrencyInstance()
 38   
                 .parse(moneyAsString)
 39   
                 .doubleValue();
 40  0
         return (int) (amountInDollars * 100);
 41   
     }
 42   
 
 43   
     private int cents;
 44   
 
 45  0
     public Money() {
 46  0
         this.cents = 0;
 47   
     }
 48   
 
 49  462
     public Money(int cents) {
 50  462
         this.cents = cents;
 51   
     }
 52   
 
 53  451
     public Money(int dollars, int cents) {
 54  451
         this(100 * dollars + cents);
 55   
     }
 56   
 
 57  0
     public Money(String moneyAsString) throws ParseException {
 58  0
         this(parseToCents(moneyAsString));
 59   
     }
 60   
 
 61  0
     public Money add(Money augend) {
 62  0
         return new Money(this.cents + augend.cents);
 63   
     }
 64   
 
 65  0
     public Object clone() {
 66  0
         return new Money(cents);
 67   
     }
 68   
 
 69  3707
     public boolean equals(Object other) {
 70  3707
         if (other != null && getClass() == other.getClass()) {
 71  3707
             Money that = (Money) other;
 72  3707
             return this.cents == that.cents;
 73   
         }
 74  0
         return false;
 75   
     }
 76   
 
 77  990
     public int hashCode() {
 78  990
         return cents;
 79   
     }
 80   
 
 81  77
     public int inCents() {
 82  77
         return cents;
 83   
     }
 84   
 
 85  0
     private double inDollars() {
 86  0
         return ((double) inCents()) / 100.0d;
 87   
     }
 88   
 
 89  0
     public boolean isValid() {
 90  0
         return true;
 91   
     }
 92   
 
 93  11
     public Money multipliedBy(int times) {
 94  11
         return Money.cents(this.inCents() * times);
 95   
     }
 96   
 
 97  0
     public Money multipliedBy(float times) {
 98  0
         return Money.cents(Math.round(this.inCents() * times));
 99   
     }
 100   
 
 101  0
     public Money negate() {
 102  0
         return null;
 103   
     }
 104   
 
 105  0
     public Money roundToNearestDollar() {
 106  0
         return null;
 107   
     }
 108   
 
 109  0
     public List split(int nWays) {
 110  0
         List result = new ArrayList();
 111  0
         int baseSplitInCents = inCents() / nWays;
 112  0
         int centsLeftOver = inCents() - baseSplitInCents * nWays;
 113   
 
 114  0
         for (int i = 0; i < nWays; i++) {
 115  0
             int eachSplitInCents;
 116  0
             if (i < centsLeftOver) {
 117  0
                 eachSplitInCents = baseSplitInCents + 1;
 118   
             }
 119   
             else {
 120  0
                 eachSplitInCents = baseSplitInCents;
 121   
             }
 122   
 
 123  0
             result.add(new Money(eachSplitInCents));
 124   
         }
 125   
 
 126  0
         return result;
 127   
     }
 128   
 
 129  0
     public String toString() {
 130  0
         return NumberFormat.getCurrencyInstance().format(inDollars());
 131   
     }
 132   
 
 133  0
     public boolean valueInCentsIs(int expected) {
 134  0
         return this.cents == expected;
 135   
     }
 136   
 
 137  22
     public int compareTo(Object other) {
 138  22
         Money that = (Money) other;
 139  22
         return this.inCents() - that.inCents();
 140   
     }
 141   
 }
 142