Clover coverage report - Diasparsoft Toolkit - 0.22
Coverage timestamp: Tue Jun 8 2004 12:41:26 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  66
     public Quantity(Integer magnitude, Object unitOfMeasure) {
 14  66
         this(new BigDecimal(magnitude.toString()), unitOfMeasure);
 15   
     }
 16   
 
 17  154
     public Quantity(BigDecimal magnitude, Object unitOfMeasure) {
 18  154
         if (unitOfMeasure == null) {
 19  11
             this.unitOfMeasure = NULL_UNIT_OF_MEASURE;
 20   
         }
 21  154
         this.magnitude = magnitude;
 22  154
         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  11
     public Object clone() {
 31  11
         return new Quantity(magnitude, unitOfMeasure);
 32   
     }
 33   
     
 34  33
     public Quantity add(Quantity that) {
 35  33
         if (this.unitOfMeasure.equals(that.unitOfMeasure) == false)
 36  11
             throw new ClassCastException(
 37   
                 "Cannot add a ["
 38   
                     + unitOfMeasure
 39   
                     + "] and a ["
 40   
                     + that.unitOfMeasure
 41   
                     + "]");
 42   
 
 43  22
         Quantity sum = (Quantity) this.clone();
 44  22
         sum.magnitude = sum.magnitude.add(that.magnitude);
 45   
         
 46  22
         return sum;
 47   
     }
 48   
 
 49  44
     public boolean equals(Object other) {
 50  44
         if (other instanceof Quantity) {
 51  44
             Quantity that = (Quantity) other;
 52  44
             return this.magnitude.equals(that.magnitude)
 53   
                 && this.unitOfMeasure.equals(that.unitOfMeasure);
 54   
         }
 55   
         else {
 56  0
             return false;
 57   
         }
 58   
     }
 59   
     
 60  22
     public int hashCode() {
 61  22
         return magnitude.hashCode();
 62   
     }
 63   
 
 64  0
     public String toString() {
 65  0
         return "<" + magnitude + ", " + unitOfMeasure + ">";
 66   
     }
 67   
 
 68  11
     public static Quantity zeroOf(Object unitOfMeasure) {
 69  11
         return new Quantity(new BigDecimal(0), unitOfMeasure);
 70   
     }
 71   
 }
 72