Clover coverage report - Diasparsoft Toolkit - 0.22
Coverage timestamp: Mon Jun 7 2004 22:02:31 EDT
file stats: LOC: 72   Methods: 8
NCLOC: 53   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
Quantity.java 83.3% 88.9% 87.5% 87.5%
coverage coverage
 1   
 package com.diasparsoftware.java.util;
 2   
 
 3   
 import java.io.Serializable;
 4   
 import java.math.BigDecimal;
 5   
 
 6   
 public class Quantity implements Serializable, Cloneable {
 7   
     private static Object NULL_UNIT_OF_MEASURE = new Object();
 8   
     public static Quantity ZERO = new Quantity(new BigDecimal(0), null);
 9   
 
 10   
     protected BigDecimal magnitude;
 11   
     protected Object unitOfMeasure;
 12   
 
 13  48
     public Quantity(Integer magnitude, Object unitOfMeasure) {
 14  48
         this(new BigDecimal(magnitude.toString()), unitOfMeasure);
 15   
     }
 16   
 
 17  112
     public Quantity(BigDecimal magnitude, Object unitOfMeasure) {
 18  112
         if (unitOfMeasure == null) {
 19  8
             this.unitOfMeasure = NULL_UNIT_OF_MEASURE;
 20   
         }
 21  112
         this.magnitude = magnitude;
 22  112
         this.unitOfMeasure = unitOfMeasure;
 23   
     }
 24   
 
 25   
     /**
 26   
      * If you do not override clone(), then the add() operation
 27   
      * will fail for subclasses of Quantity, returning a Quantity
 28   
      * object rather than one of the specific subclass type.
 29   
      */
 30  8
     public Object clone() {
 31  8
         return new Quantity(magnitude, unitOfMeasure);
 32   
     }
 33   
     
 34  24
     public Quantity add(Quantity that) {
 35  24
         if (this.unitOfMeasure.equals(that.unitOfMeasure) == false)
 36  8
             throw new ClassCastException(
 37   
                 "Cannot add a ["
 38   
                     + unitOfMeasure
 39   
                     + "] and a ["
 40   
                     + that.unitOfMeasure
 41   
                     + "]");
 42   
 
 43  16
         Quantity sum = (Quantity) this.clone();
 44  16
         sum.magnitude = sum.magnitude.add(that.magnitude);
 45   
         
 46  16
         return sum;
 47   
     }
 48   
 
 49  32
     public boolean equals(Object other) {
 50  32
         if (other instanceof Quantity) {
 51  32
             Quantity that = (Quantity) other;
 52  32
             return this.magnitude.equals(that.magnitude)
 53   
                 && this.unitOfMeasure.equals(that.unitOfMeasure);
 54   
         }
 55   
         else {
 56  0
             return false;
 57   
         }
 58   
     }
 59   
     
 60  16
     public int hashCode() {
 61  16
         return magnitude.hashCode();
 62   
     }
 63   
 
 64  0
     public String toString() {
 65  0
         return "<" + magnitude + ", " + unitOfMeasure + ">";
 66   
     }
 67   
 
 68  8
     public static Quantity zeroOf(Object unitOfMeasure) {
 69  8
         return new Quantity(new BigDecimal(0), unitOfMeasure);
 70   
     }
 71   
 }
 72