IDEMPIERE-455 Discover and fix FindBugs problems / DMI_BIGDECIMAL_CONSTRUCTED_FROM_DOUBLE / Improve some calculations for BigDecimal

This commit is contained in:
Carlos Ruiz 2013-04-09 17:48:34 -05:00
parent e4476ec95c
commit 6b108cff55
16 changed files with 47 additions and 47 deletions

View File

@ -193,10 +193,10 @@ public class PromotionRule {
} else if (pr.getRewardType().equals(MPromotionReward.REWARDTYPE_FlatDiscount)) {
discount = pr.getAmount();
} else if (pr.getRewardType().equals(MPromotionReward.REWARDTYPE_Percentage)) {
discount = pr.getAmount().divide(BigDecimal.valueOf(100.00)).multiply(totalPrice);
discount = pr.getAmount().divide(Env.ONEHUNDRED).multiply(totalPrice);
}
if (discount.signum() > 0) {
addDiscountLine(order, null, discount, BigDecimal.valueOf(1.00), pr.getC_Charge_ID(), pr.getM_Promotion());
addDiscountLine(order, null, discount, Env.ONE, pr.getC_Charge_ID(), pr.getM_Promotion());
}
} else {
int M_PromotionDistribution_ID = pr.getM_PromotionDistribution_ID();
@ -260,10 +260,10 @@ public class PromotionRule {
if (ol.getC_OrderLine_ID() == C_OrderLine_ID) {
if (pr.getRewardType().equals(MPromotionReward.REWARDTYPE_Percentage)) {
BigDecimal priceActual = ol.getPriceActual();
BigDecimal discount = priceActual.multiply(pr.getAmount().divide(BigDecimal.valueOf(100.00)));
BigDecimal discount = priceActual.multiply(pr.getAmount().divide(Env.ONEHUNDRED));
addDiscountLine(order, ol, discount, qty, pr.getC_Charge_ID(), pr.getM_Promotion());
} else if (pr.getRewardType().equals(MPromotionReward.REWARDTYPE_FlatDiscount)) {
addDiscountLine(order, ol, pr.getAmount(), BigDecimal.valueOf(1.00), pr.getC_Charge_ID(), pr.getM_Promotion());
addDiscountLine(order, ol, pr.getAmount(), Env.ONE, pr.getC_Charge_ID(), pr.getM_Promotion());
} else if (pr.getRewardType().equals(MPromotionReward.REWARDTYPE_AbsoluteAmount)) {
BigDecimal priceActual = ol.getPriceActual();
totalPrice = totalPrice.add(priceActual.multiply(qty));
@ -278,7 +278,7 @@ public class PromotionRule {
}
if (pr.getRewardType().equals(MPromotionReward.REWARDTYPE_AbsoluteAmount)) {
if (pr.getAmount().compareTo(totalPrice) < 0) {
addDiscountLine(order, null, totalPrice.subtract(pr.getAmount()), BigDecimal.valueOf(1.00), pr.getC_Charge_ID(), pr.getM_Promotion());
addDiscountLine(order, null, totalPrice.subtract(pr.getAmount()), Env.ONE, pr.getC_Charge_ID(), pr.getM_Promotion());
}
}
}

View File

@ -16,14 +16,14 @@
*****************************************************************************/
package org.compiere;
import java.math.BigDecimal;
import static org.compiere.model.SystemIDs.WINDOW_WINDOW_TAB_FIELD;
import java.util.Properties;
import org.compiere.model.GridWindow;
import org.compiere.model.GridWindowVO;
import org.compiere.model.MConversionRate;
import org.compiere.model.MUOMConversion;
import static org.compiere.model.SystemIDs.*;
import org.compiere.util.Env;
import org.compiere.util.Login;
@ -97,9 +97,9 @@ class Base
listThreads();
//
System.out.println("API Test");
System.out.println("64.72=" + MConversionRate.convert(ctx, BigDecimal.valueOf(100.0), 116, 100,0,0));
System.out.println("64.72=" + MConversionRate.convert(ctx, Env.ONEHUNDRED, 116, 100,0,0));
System.out.println("0.647169=" + MConversionRate.getRate(116, 100, null, 0,0,0));
System.out.println("12.5=" + MUOMConversion.convert(101, 102, BigDecimal.valueOf(100.0), true));
System.out.println("12.5=" + MUOMConversion.convert(101, 102, Env.ONEHUNDRED, true));
} // Base

View File

@ -105,7 +105,7 @@ public class Doc_Requisition extends Doc
*/
public BigDecimal getBalance ()
{
BigDecimal retValue = BigDecimal.valueOf(0.0);
BigDecimal retValue = Env.ZERO;
return retValue;
} // getBalance

View File

@ -27,6 +27,7 @@ import java.util.logging.Level;
import org.compiere.model.Callout;
import org.compiere.model.X_AD_ImpFormat_Row;
import org.compiere.util.CLogger;
import org.compiere.util.Env;
/**
* Import Format Row with parsing capability
@ -486,7 +487,7 @@ public final class ImpFormatRow
return "0";
BigDecimal bd = new BigDecimal(sb.toString());
if (m_divideBy100) // assumed two decimal scale
bd = bd.divide(BigDecimal.valueOf(100.0), 2, BigDecimal.ROUND_HALF_UP);
bd = bd.divide(Env.ONEHUNDRED, 2, BigDecimal.ROUND_HALF_UP);
return bd.toString();
} // parseNumber

View File

@ -250,10 +250,9 @@ public class CalloutEngine implements Callout
BigDecimal rate1 = (BigDecimal)value;
BigDecimal rate2 = Env.ZERO;
BigDecimal one = BigDecimal.valueOf(1.0);
if (rate1.doubleValue() != 0.0) // no divide by zero
rate2 = one.divide(rate1, 12, BigDecimal.ROUND_HALF_UP);
if (rate1.signum() != 0.0) // no divide by zero
rate2 = Env.ONE.divide(rate1, 12, BigDecimal.ROUND_HALF_UP);
//
if (mField.getColumnName().equals("MultiplyRate"))
mTab.setValue("DivideRate", rate2);

View File

@ -16,11 +16,12 @@
*****************************************************************************/
package org.compiere.model;
import java.math.BigDecimal;
import java.sql.ResultSet;
import java.sql.Timestamp;
import java.util.Properties;
import org.compiere.util.Env;
/**
* Resource Assignment Model
@ -48,7 +49,7 @@ public class MResourceAssignment extends X_S_ResourceAssignment
if (S_ResourceAssignment_ID == 0)
{
setAssignDateFrom(new Timestamp(System.currentTimeMillis()));
setQty(BigDecimal.valueOf(1.0));
setQty(Env.ONE);
setName(".");
setIsConfirmed(false);
}

View File

@ -486,7 +486,7 @@ public class MPrintTableFormat extends X_AD_PrintTableFormat
{
BigDecimal retValue = super.getLineStroke();
if (retValue == null || Env.ZERO.compareTo(retValue) <= 0)
retValue = BigDecimal.valueOf(1.0);
retValue = Env.ONE;
return retValue;
} // getLineStroke
@ -498,7 +498,7 @@ public class MPrintTableFormat extends X_AD_PrintTableFormat
{
BigDecimal retValue = super.getLineStroke();
if (retValue == null || Env.ZERO.compareTo(retValue) <= 0)
retValue = BigDecimal.valueOf(1.0);
retValue = Env.ONE;
return retValue;
} // getVLineStroke

View File

@ -75,9 +75,6 @@ public class RModelData
private ArrayList<Integer> m_groupRows = new ArrayList<Integer>();
private ArrayList<Boolean> m_groupRowsIndicator = null;
/** Constant 1 */
private static final BigDecimal ONE = BigDecimal.valueOf(1.0);
/** Logger */
private static CLogger log = CLogger.getCLogger(RModelData.class);
@ -322,7 +319,7 @@ public class RModelData
if (funcFuns[fc].equals(RModel.FUNCTION_SUM))
funcVals[fc][level] = funcVals[fc][level].add(bd);
else if (funcFuns[fc].equals(RModel.FUNCTION_COUNT))
funcVals[fc][level] = funcVals[fc][level].add(ONE);
funcVals[fc][level] = funcVals[fc][level].add(Env.ONE);
} // for all group levels
} // for all functions

View File

@ -13,6 +13,10 @@
*****************************************************************************/
package org.compiere.apps.form;
import static org.compiere.model.SystemIDs.COLUMN_C_INVOICE_C_BPARTNER_ID;
import static org.compiere.model.SystemIDs.COLUMN_C_INVOICE_C_CURRENCY_ID;
import static org.compiere.model.SystemIDs.COLUMN_C_PERIOD_AD_ORG_ID;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.GridBagConstraints;
@ -22,7 +26,6 @@ import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.beans.PropertyChangeEvent;
import java.beans.VetoableChangeListener;
import java.math.BigDecimal;
import java.util.Vector;
import java.util.logging.Level;
@ -46,7 +49,6 @@ import org.compiere.minigrid.MiniTable;
import org.compiere.model.MAllocationHdr;
import org.compiere.model.MLookup;
import org.compiere.model.MLookupFactory;
import static org.compiere.model.SystemIDs.*;
import org.compiere.plaf.CompiereColor;
import org.compiere.swing.CPanel;
import org.compiere.swing.CTextField;
@ -394,7 +396,7 @@ public class VAllocation extends Allocation
private void setAllocateButton() {
if (totalDiff.compareTo(BigDecimal.valueOf(0.0)) == 0 ^ m_C_Charge_ID > 0 )
if (totalDiff.signum() == 0 ^ m_C_Charge_ID > 0 )
{
allocateButton.setEnabled(true);
// chargePick.setValue(m_C_Charge_ID);
@ -404,7 +406,7 @@ public class VAllocation extends Allocation
allocateButton.setEnabled(false);
}
if ( totalDiff.compareTo(BigDecimal.valueOf(0.0)) == 0 )
if ( totalDiff.signum() == 0 )
{
chargePick.setValue(null);
m_C_Charge_ID = 0;

View File

@ -320,7 +320,7 @@ implements FormPanel, ActionListener, TableModelListener, VetoableChangeListener
public void calculateSelection()
{
m_noSelected = 0;
BigDecimal selectedAmt = BigDecimal.valueOf(0.0);
BigDecimal selectedAmt = Env.ZERO;
int rows = miniTable.getRowCount();
for (int i = 0; i < rows; i++)

View File

@ -96,7 +96,7 @@ public final class Calculator extends CDialog
//
m_number = number;
if (m_number == null)
m_number = BigDecimal.valueOf(0.0);
m_number = Env.ZERO;
//
try
{
@ -433,7 +433,7 @@ public final class Calculator extends CDialog
// nothing or zero
if (m_display == null || m_display.equals("") || m_display.equals("0"))
{
m_number = BigDecimal.valueOf(0.0);
m_number = Env.ZERO;
return m_number;
}
@ -448,7 +448,7 @@ public final class Calculator extends CDialog
token += st.nextToken();
else
{
m_number = BigDecimal.valueOf(0.0);
m_number = Env.ZERO;
return m_number;
}
}
@ -462,7 +462,7 @@ public final class Calculator extends CDialog
catch (ParseException pe1)
{
log.log(Level.SEVERE, "Calculator.evaluate - token: " + token, pe1);
m_number = BigDecimal.valueOf(0.0);
m_number = Env.ZERO;
return m_number;
}
BigDecimal firstNo = new BigDecimal(firstNumber.toString());
@ -485,7 +485,7 @@ public final class Calculator extends CDialog
char op = token.charAt(0);
if (op == '%') {
firstNo = firstNo.divide(BigDecimal.valueOf(100.0), m_format.getMaximumFractionDigits(), BigDecimal.ROUND_HALF_UP);
firstNo = firstNo.divide(Env.ONEHUNDRED, m_format.getMaximumFractionDigits(), BigDecimal.ROUND_HALF_UP);
m_number = firstNo;
}
@ -502,7 +502,7 @@ public final class Calculator extends CDialog
catch (ParseException pe2)
{
log.log(Level.SEVERE, "Calculator.evaluate - token: " + token, pe2);
m_number = BigDecimal.valueOf(0.0);
m_number = Env.ZERO;
return m_number;
}
BigDecimal secondNo = new BigDecimal(secondNumber.toString());
@ -523,7 +523,7 @@ public final class Calculator extends CDialog
// Percent operation
if (op2 == '%')
secondNo = secondNo.divide(BigDecimal.valueOf(100.0), m_format.getMaximumFractionDigits(), BigDecimal.ROUND_HALF_UP);
secondNo = secondNo.divide(Env.ONEHUNDRED, m_format.getMaximumFractionDigits(), BigDecimal.ROUND_HALF_UP);
switch (op)
{

View File

@ -30,6 +30,7 @@ import javax.swing.text.PlainDocument;
import org.compiere.apps.ADialog;
import org.compiere.util.CLogger;
import org.compiere.util.DisplayType;
import org.compiere.util.Env;
/**
* Number Document Model.
@ -220,14 +221,14 @@ public final class MDocNumber extends PlainDocument
else
{
String value = getText();
BigDecimal percentValue = BigDecimal.valueOf(0.0);
BigDecimal percentValue = Env.ZERO;
try
{
if (value != null && value.length() > 0)
{
Number number = m_format.parse(value);
percentValue = new BigDecimal (number.toString());
percentValue = percentValue.divide(BigDecimal.valueOf(100.0), m_format.getMaximumFractionDigits(), BigDecimal.ROUND_HALF_UP);
percentValue = percentValue.divide(Env.ONEHUNDRED, m_format.getMaximumFractionDigits(), BigDecimal.ROUND_HALF_UP);
m_tc.setText(m_format.format(percentValue));
}
}

View File

@ -20,7 +20,6 @@ import static org.compiere.model.SystemIDs.COLUMN_C_INVOICE_C_BPARTNER_ID;
import static org.compiere.model.SystemIDs.COLUMN_C_INVOICE_C_CURRENCY_ID;
import static org.compiere.model.SystemIDs.COLUMN_C_PERIOD_AD_ORG_ID;
import java.math.BigDecimal;
import java.util.Vector;
import java.util.logging.Level;
@ -485,7 +484,7 @@ public class WAllocation extends Allocation
} // vetoableChange
private void setAllocateButton() {
if (totalDiff.compareTo(BigDecimal.valueOf(0.0)) == 0 ^ m_C_Charge_ID > 0 )
if (totalDiff.signum() == 0 ^ m_C_Charge_ID > 0 )
{
allocateButton.setEnabled(true);
// chargePick.setValue(m_C_Charge_ID);
@ -495,7 +494,7 @@ public class WAllocation extends Allocation
allocateButton.setEnabled(false);
}
if ( totalDiff.compareTo(BigDecimal.valueOf(0.0)) == 0 )
if ( totalDiff.signum() == 0 )
{
chargePick.setValue(null);
m_C_Charge_ID = 0;

View File

@ -334,7 +334,7 @@ implements IFormController, EventListener<Event>, WTableModelListener, ValueChan
public void calculateSelection()
{
m_noSelected = 0;
BigDecimal selectedAmt = BigDecimal.valueOf(0.0);
BigDecimal selectedAmt = Env.ZERO;
int rows = miniTable.getRowCount();
for (int i = 0; i < rows; i++)

View File

@ -53,9 +53,9 @@ public class Allocation
public int m_C_BPartner_ID = 0;
private int m_noInvoices = 0;
private int m_noPayments = 0;
public BigDecimal totalInv = BigDecimal.valueOf(0.0);
public BigDecimal totalPay = BigDecimal.valueOf(0.0);
public BigDecimal totalDiff = BigDecimal.valueOf(0.0);
public BigDecimal totalInv = Env.ZERO;
public BigDecimal totalPay = Env.ZERO;
public BigDecimal totalDiff = Env.ZERO;
public Timestamp allocDate = null;
@ -548,7 +548,7 @@ public class Allocation
log.config("");
// Payment
totalPay = BigDecimal.valueOf(0.0);
totalPay = Env.ZERO;
int rows = payment.getRowCount();
m_noPayments = 0;
for (int i = 0; i < rows; i++)
@ -571,7 +571,7 @@ public class Allocation
public String calculateInvoice(IMiniTable invoice, boolean isMultiCurrency)
{
// Invoices
totalInv = BigDecimal.valueOf(0.0);
totalInv = Env.ZERO;
int rows = invoice.getRowCount();
m_noInvoices = 0;

View File

@ -61,7 +61,7 @@ public class PaySelect
/** Format */
public DecimalFormat m_format = DisplayType.getNumberFormat(DisplayType.Amount);
/** Bank Balance */
private BigDecimal m_bankBalance = BigDecimal.valueOf(0.0);
private BigDecimal m_bankBalance = Env.ZERO;
/** SQL for Query */
private String m_sql;
/** Number of selected rows */
@ -379,7 +379,7 @@ public class PaySelect
public String calculateSelection(IMiniTable miniTable)
{
m_noSelected = 0;
BigDecimal invoiceAmt = BigDecimal.valueOf(0.0);
BigDecimal invoiceAmt = Env.ZERO;
int rows = miniTable.getRowCount();
for (int i = 0; i < rows; i++)