Coverage Report - jaggregate.internal.number.OperableBigDecimal
 
Classes in this File Line Coverage Branch Coverage Complexity
OperableBigDecimal
100%
22/22
100%
7/7
0
OperableBigDecimal$1
100%
2/2
N/A
0
 
 1  
 /*
 2  
  Copyright 2004-2008 Paul R. Holser, Jr.  All rights reserved.
 3  
  Licensed under the Academic Free License version 3.0
 4  
  */
 5  
 
 6  
 package jaggregate.internal.number;
 7  
 
 8  
 import java.math.BigDecimal;
 9  
 
 10  
 /**
 11  
  * Wrapper for a {@code BigDecimal}.
 12  
  *
 13  
  * @author <a href="mailto:pholser@alumni.rice.edu">Paul Holser</a>
 14  
  * @version $Id: OperableBigDecimal.java,v 1.1 2008/03/26 18:01:28 pholser Exp $
 15  
  */
 16  11041
 public class OperableBigDecimal extends OperableNumber<BigDecimal> {
 17  
     private static final long serialVersionUID = -1L;
 18  
 
 19  1
     private static final OperableBigDecimal ONE =
 20  
         new OperableBigDecimal( BigDecimal.ONE ) {
 21  
             private static final long serialVersionUID = -1L;
 22  
 
 23  
             @Override
 24  204
             public void incrementBy( OperableNumber<BigDecimal> increment ) {
 25  1
                 throw new UnsupportedOperationException();
 26  
             }
 27  
         };
 28  
 
 29  
     /**
 30  
      * Creates a wrapper for the given number.
 31  
      *
 32  
      * @param wrapped the wrapped number
 33  
      */
 34  
     public OperableBigDecimal( BigDecimal wrapped ) {
 35  8629
         super( wrapped );
 36  8629
     }
 37  
 
 38  
     /**
 39  
      * {@inheritDoc}
 40  
      */
 41  
     @Override
 42  
     public boolean isZero() {
 43  809
         return unwrapped().compareTo( BigDecimal.ZERO ) == 0;
 44  
     }
 45  
 
 46  
     /**
 47  
      * {@inheritDoc}
 48  
      */
 49  
     @Override
 50  
     public OperableBigDecimal plus( BigDecimal addend ) {
 51  1595
         return new OperableBigDecimal( unwrapped().add( addend ) );
 52  
     }
 53  
 
 54  
     /**
 55  
      * {@inheritDoc}
 56  
      */
 57  
     @Override
 58  
     public OperableBigDecimal plus( int addend ) {
 59  633
         return new OperableBigDecimal(
 60  
             unwrapped().add( BigDecimal.valueOf( addend ) ) );
 61  
     }
 62  
 
 63  
     /**
 64  
      * {@inheritDoc}
 65  
      */
 66  
     @Override
 67  
     public OperableBigDecimal minus( BigDecimal subtrahend ) {
 68  1266
         return new OperableBigDecimal( unwrapped().subtract( subtrahend ) );
 69  
     }
 70  
 
 71  
     /**
 72  
      * {@inheritDoc}
 73  
      */
 74  
     @Override
 75  
     public OperableBigDecimal times( BigDecimal multiplier ) {
 76  633
         return new OperableBigDecimal( unwrapped().multiply( multiplier ) );
 77  
     }
 78  
 
 79  
     /**
 80  
      * {@inheritDoc}
 81  
      */
 82  
     @Override
 83  
     public OperableBigDecimal times( int multiplier ) {
 84  847
         return new OperableBigDecimal(
 85  
             unwrapped().multiply( BigDecimal.valueOf( multiplier ) ) );
 86  
     }
 87  
 
 88  
     /**
 89  
      * {@inheritDoc}
 90  
      */
 91  
     @Override
 92  
     public OperableBigDecimal dividedBy( BigDecimal divisor ) {
 93  1266
         return new OperableBigDecimal( unwrapped().divideToIntegralValue( divisor ) );
 94  
     }
 95  
 
 96  
     /**
 97  
      * {@inheritDoc}
 98  
      */
 99  
     @Override
 100  
     public OperableBigDecimal modulo( BigDecimal divisor ) {
 101  79
         return new OperableBigDecimal( unwrapped().remainder( divisor ) );
 102  
     }
 103  
 
 104  
     /**
 105  
      * {@inheritDoc}
 106  
      */
 107  
     @Override
 108  
     public boolean isPositive() {
 109  2239
         return unwrapped().signum() > 0;
 110  
     }
 111  
 
 112  
     /**
 113  
      * {@inheritDoc}
 114  
      */
 115  
     @Override
 116  
     public boolean isNegative() {
 117  1078
         return unwrapped().signum() < 0;
 118  
     }
 119  
 
 120  
     /**
 121  
      * {@inheritDoc}
 122  
      */
 123  
     @Override
 124  
     public boolean greaterThan( BigDecimal comparand ) {
 125  2094
         return unwrapped().compareTo( comparand ) > 0;
 126  
     }
 127  
 
 128  
     /**
 129  
      * {@inheritDoc}
 130  
      */
 131  
     @Override
 132  
     public boolean greaterThanOrEqualTo( BigDecimal comparand ) {
 133  385
         return unwrapped().compareTo( comparand ) >= 0;
 134  
     }
 135  
 
 136  
     /**
 137  
      * {@inheritDoc}
 138  
      */
 139  
     @Override
 140  
     public boolean lessThan( BigDecimal comparand ) {
 141  1920
         return unwrapped().compareTo( comparand ) < 0;
 142  
     }
 143  
 
 144  
     /**
 145  
      * {@inheritDoc}
 146  
      */
 147  
     @Override
 148  
     public boolean lessThanOrEqualTo( BigDecimal comparand ) {
 149  429
         return unwrapped().compareTo( comparand ) <= 0;
 150  
     }
 151  
 
 152  
     /**
 153  
      * {@inheritDoc}
 154  
      */
 155  
     @Override
 156  
     public OperableBigDecimal negated() {
 157  97
         return new OperableBigDecimal( unwrapped().negate() );
 158  
     }
 159  
 
 160  
     /**
 161  
      * {@inheritDoc}
 162  
      */
 163  
     @Override
 164  
     public void incrementBy( OperableNumber<BigDecimal> increment ) {
 165  596
         update( unwrapped().add( increment.unwrapped() ) );
 166  596
     }
 167  
 
 168  
     /**
 169  
      * {@inheritDoc}
 170  
      */
 171  
     @Override
 172  
     public OperableNumber<BigDecimal> one() {
 173  181
         return ONE;
 174  
     }
 175  
 }