Clover coverage report - JBind Project
Coverage timestamp: Fr Mai 28 2004 11:17:36 CEST
file stats: LOC: 76   Methods: 8
NCLOC: 51   Classes: 1
This license of Clover is provided to support the development of JBind only. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover.
 
 Source file Conditionals Statements Methods TOTAL
DecimalData.java 50% 65% 75% 65,6%
 1   
 /*
 2   
  * JBind
 3   
  *
 4   
  * Copyright (c) by Stefan Wachter. All rights reserved.
 5   
  *
 6   
  * Usage, modification, and redistribution is subject to license terms that are
 7   
  * available at 'http://www.jbind.org'. The JBind license is like the
 8   
  * 'Apache Software License V 1.1'.
 9   
  */
 10   
 package org.jbind.xml.instance.data;
 11   
 
 12   
 import java.math.BigDecimal;
 13   
 
 14   
 import org.jbind.xml.core.data.IDecimalData;
 15   
 import org.jbind.xml.msg.IConstraintViolations;
 16   
 import org.jbind.xml.msg.XmlException;
 17   
 import org.jbind.xml.msg.XmlMessages;
 18   
 
 19   
 public class DecimalData extends AbstractDecimalData {
 20   
 
 21   
   private BigDecimal myValue = null;
 22   
 
 23  144
   private static BigDecimal normalize(BigDecimal aDecimal) {
 24  144
     BigDecimal res = aDecimal;
 25  144
     try {
 26  144
       while (res.scale() > 0) {
 27  3
         res = res.setScale(res.scale() - 1);
 28   
       }
 29   
     } catch (ArithmeticException e) {
 30   
       //
 31   
     }
 32  144
     return res;
 33   
   }
 34   
 
 35  164
   public void doAccept(String aString) throws XmlException {
 36  164
     super.doAccept(aString);
 37  164
     try {
 38  164
       myValue = normalize(new BigDecimal(aString));
 39   
     } catch (NumberFormatException e) {
 40  20
       throw new XmlException(XmlMessages.simpleDataConversionException(aString, e, getImpl_()));
 41   
     }
 42   
   }
 43   
 
 44  193
   public BigDecimal getBigDecimal() {
 45  193
     return myValue;
 46   
   }
 47   
 
 48  0
   public void setBigDecimal(BigDecimal aNewValue) throws XmlException {
 49  0
     BigDecimal oldValue = myValue;
 50  0
     myValue = normalize(aNewValue);
 51  0
     IConstraintViolations violations = completeSimpleStorageAssignment_();
 52  0
     if (!violations.isEmpty()) {
 53  0
       myValue = oldValue;
 54  0
       throw new XmlException(violations);
 55   
     }
 56   
   }
 57   
 
 58  95
   public int compareSubTypeData_(IDecimalData aData) {
 59  95
     return getBigDecimal().compareTo(aData.getBigDecimal());
 60   
   }
 61   
 
 62  14
   public String getCanonicalForm_() {
 63  14
     return String.valueOf(myValue);
 64   
   }
 65   
 
 66  1
   public Object getSimpleStorageObject() {
 67  1
     return myValue;
 68   
   }
 69   
 
 70  0
   public void setSimpleStorageObject(Object aValue) {
 71  0
     myValue = (BigDecimal)aValue;
 72   
   }
 73   
 
 74   
 
 75   
 }
 76