| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
package jaggregate.internal.number; |
| 7 | |
|
| 8 | |
import java.math.BigDecimal; |
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 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 | |
|
| 31 | |
|
| 32 | |
|
| 33 | |
|
| 34 | |
public OperableBigDecimal( BigDecimal wrapped ) { |
| 35 | 8629 | super( wrapped ); |
| 36 | 8629 | } |
| 37 | |
|
| 38 | |
|
| 39 | |
|
| 40 | |
|
| 41 | |
@Override |
| 42 | |
public boolean isZero() { |
| 43 | 809 | return unwrapped().compareTo( BigDecimal.ZERO ) == 0; |
| 44 | |
} |
| 45 | |
|
| 46 | |
|
| 47 | |
|
| 48 | |
|
| 49 | |
@Override |
| 50 | |
public OperableBigDecimal plus( BigDecimal addend ) { |
| 51 | 1595 | return new OperableBigDecimal( unwrapped().add( addend ) ); |
| 52 | |
} |
| 53 | |
|
| 54 | |
|
| 55 | |
|
| 56 | |
|
| 57 | |
@Override |
| 58 | |
public OperableBigDecimal plus( int addend ) { |
| 59 | 633 | return new OperableBigDecimal( |
| 60 | |
unwrapped().add( BigDecimal.valueOf( addend ) ) ); |
| 61 | |
} |
| 62 | |
|
| 63 | |
|
| 64 | |
|
| 65 | |
|
| 66 | |
@Override |
| 67 | |
public OperableBigDecimal minus( BigDecimal subtrahend ) { |
| 68 | 1266 | return new OperableBigDecimal( unwrapped().subtract( subtrahend ) ); |
| 69 | |
} |
| 70 | |
|
| 71 | |
|
| 72 | |
|
| 73 | |
|
| 74 | |
@Override |
| 75 | |
public OperableBigDecimal times( BigDecimal multiplier ) { |
| 76 | 633 | return new OperableBigDecimal( unwrapped().multiply( multiplier ) ); |
| 77 | |
} |
| 78 | |
|
| 79 | |
|
| 80 | |
|
| 81 | |
|
| 82 | |
@Override |
| 83 | |
public OperableBigDecimal times( int multiplier ) { |
| 84 | 847 | return new OperableBigDecimal( |
| 85 | |
unwrapped().multiply( BigDecimal.valueOf( multiplier ) ) ); |
| 86 | |
} |
| 87 | |
|
| 88 | |
|
| 89 | |
|
| 90 | |
|
| 91 | |
@Override |
| 92 | |
public OperableBigDecimal dividedBy( BigDecimal divisor ) { |
| 93 | 1266 | return new OperableBigDecimal( unwrapped().divideToIntegralValue( divisor ) ); |
| 94 | |
} |
| 95 | |
|
| 96 | |
|
| 97 | |
|
| 98 | |
|
| 99 | |
@Override |
| 100 | |
public OperableBigDecimal modulo( BigDecimal divisor ) { |
| 101 | 79 | return new OperableBigDecimal( unwrapped().remainder( divisor ) ); |
| 102 | |
} |
| 103 | |
|
| 104 | |
|
| 105 | |
|
| 106 | |
|
| 107 | |
@Override |
| 108 | |
public boolean isPositive() { |
| 109 | 2239 | return unwrapped().signum() > 0; |
| 110 | |
} |
| 111 | |
|
| 112 | |
|
| 113 | |
|
| 114 | |
|
| 115 | |
@Override |
| 116 | |
public boolean isNegative() { |
| 117 | 1078 | return unwrapped().signum() < 0; |
| 118 | |
} |
| 119 | |
|
| 120 | |
|
| 121 | |
|
| 122 | |
|
| 123 | |
@Override |
| 124 | |
public boolean greaterThan( BigDecimal comparand ) { |
| 125 | 2094 | return unwrapped().compareTo( comparand ) > 0; |
| 126 | |
} |
| 127 | |
|
| 128 | |
|
| 129 | |
|
| 130 | |
|
| 131 | |
@Override |
| 132 | |
public boolean greaterThanOrEqualTo( BigDecimal comparand ) { |
| 133 | 385 | return unwrapped().compareTo( comparand ) >= 0; |
| 134 | |
} |
| 135 | |
|
| 136 | |
|
| 137 | |
|
| 138 | |
|
| 139 | |
@Override |
| 140 | |
public boolean lessThan( BigDecimal comparand ) { |
| 141 | 1920 | return unwrapped().compareTo( comparand ) < 0; |
| 142 | |
} |
| 143 | |
|
| 144 | |
|
| 145 | |
|
| 146 | |
|
| 147 | |
@Override |
| 148 | |
public boolean lessThanOrEqualTo( BigDecimal comparand ) { |
| 149 | 429 | return unwrapped().compareTo( comparand ) <= 0; |
| 150 | |
} |
| 151 | |
|
| 152 | |
|
| 153 | |
|
| 154 | |
|
| 155 | |
@Override |
| 156 | |
public OperableBigDecimal negated() { |
| 157 | 97 | return new OperableBigDecimal( unwrapped().negate() ); |
| 158 | |
} |
| 159 | |
|
| 160 | |
|
| 161 | |
|
| 162 | |
|
| 163 | |
@Override |
| 164 | |
public void incrementBy( OperableNumber<BigDecimal> increment ) { |
| 165 | 596 | update( unwrapped().add( increment.unwrapped() ) ); |
| 166 | 596 | } |
| 167 | |
|
| 168 | |
|
| 169 | |
|
| 170 | |
|
| 171 | |
@Override |
| 172 | |
public OperableNumber<BigDecimal> one() { |
| 173 | 181 | return ONE; |
| 174 | |
} |
| 175 | |
} |