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 18:09:44 -05:00
parent 16094d84d5
commit 01a9897cc1
24 changed files with 40 additions and 56 deletions

View File

@ -186,7 +186,7 @@ public class CalloutInventory extends CalloutEngine
} else {
// gwu: 1719401: clear Booked Quantity to zero first in case the query returns no rows,
// for example when the locator has never stored a particular product.
return new BigDecimal(0);
return Env.ZERO;
}
}
catch (SQLException e)
@ -201,7 +201,7 @@ public class CalloutInventory extends CalloutEngine
pstmt = null;
}
return new BigDecimal(0);
return Env.ZERO;
}

View File

@ -70,7 +70,7 @@ public class ImmediateBankTransfer extends SvrProcess
private String p_Name = ""; // Name
private String p_Description= ""; // Description
private int p_C_CashBook_ID = 0; // CashBook to be used as bridge
private BigDecimal p_Amount = new BigDecimal(0); // Amount to be transfered between the accounts
private BigDecimal p_Amount = Env.ZERO; // Amount to be transfered between the accounts
private int p_From_C_BankAccount_ID = 0; // Bank Account From
private int p_To_C_BankAccount_ID= 0; // Bank Account To
private Timestamp p_StatementDate = null; // Date Statement
@ -134,7 +134,7 @@ public class ImmediateBankTransfer extends SvrProcess
if (!isSameCurrency())
throw new AdempiereUserError ("Banks and CashBook must have same currency");
if (p_Amount.compareTo(new BigDecimal(0)) == 0)
if (p_Amount.signum() == 0)
throw new AdempiereUserError ("Amount required");
// Login Date

View File

@ -348,7 +348,7 @@ public class DunningRunCreate extends SvrProcess
//
MDunningRunLine line = new MDunningRunLine (entry);
line.setInvoice(C_Invoice_ID, C_Currency_ID, GrandTotal, Open,
new BigDecimal(0), DaysDue, IsInDispute, TimesDunned,
Env.ZERO, DaysDue, IsInDispute, TimesDunned,
DaysAfterLast);
line.setC_InvoicePaySchedule_ID(C_InvoicePaySchedule_ID);
if (!line.save())
@ -497,7 +497,7 @@ public class DunningRunCreate extends SvrProcess
line.setFee (p_C_Currency_ID, level.getFeeAmt());
if (!line.save())
throw new IllegalStateException("Cannot save MDunningRunLine");
element.setQty (element.getQty ().subtract (new BigDecimal(1)));
element.setQty (element.getQty ().subtract (Env.ONE));
}
}
} // addFees

View File

@ -40,9 +40,6 @@ public class RfQCreateSO extends SvrProcess
private int p_C_RfQ_ID = 0;
private int p_C_DocType_ID = 0;
/** 100 */
private static BigDecimal ONEHUNDRED = new BigDecimal (100);
/**
* Prepare
*/
@ -130,9 +127,9 @@ public class RfQCreateSO extends SvrProcess
margin = rfq.getMargin();
if (margin != null && margin.signum() != 0)
{
margin = margin.add(ONEHUNDRED);
margin = margin.add(Env.ONEHUNDRED);
price = price.multiply(margin)
.divide(ONEHUNDRED, 2, BigDecimal.ROUND_HALF_UP);
.divide(Env.ONEHUNDRED, 2, BigDecimal.ROUND_HALF_UP);
}
}
} // price

View File

@ -36,6 +36,7 @@ import org.compiere.util.AdempiereUserError;
import org.compiere.util.CLogger;
import org.compiere.util.DB;
import org.compiere.util.DisplayType;
import org.compiere.util.Env;
import org.compiere.util.Trx;
import org.compiere.util.ValueNamePair;
@ -119,7 +120,7 @@ public class UUIDGenerator extends SvrProcess {
mColumn.setEntityType("U");
mColumn.setFieldLength(36);
mColumn.setName(columnName);
mColumn.setVersion(new BigDecimal("1.00"));
mColumn.setVersion(Env.ONE);
mColumn.saveEx();
syncColumn(mColumn);

View File

@ -193,7 +193,7 @@ public class Doc_Production extends Doc
as.get_ID(), base.getAccount_ID(), 0,0,0,0,0,0,0,0,0,0,0,0,0,0);
//
// only post variance if it's not zero
if (variance.compareTo(new BigDecimal("0.00")) != 0)
if (variance.signum() != 0)
{
//post variance
fl = fact.createLine(line,

View File

@ -41,6 +41,7 @@ import java.util.Properties;
import java.util.logging.Level;
import org.compiere.util.DB;
import org.compiere.util.Env;
/**
* Deposit Batch Model
@ -69,7 +70,7 @@ public class MDepositBatch extends X_C_DepositBatch
setDocStatus (DOCSTATUS_Drafted);
setProcessed (false);
setProcessing (false);
setDepositAmt(new BigDecimal(0));
setDepositAmt(Env.ZERO);
}
} // MDepositBatch

View File

@ -201,7 +201,7 @@ public class MDiscountSchema extends X_M_DiscountSchema
if (discount == null || discount.signum() == 0)
return Price;
//
BigDecimal onehundred = new BigDecimal(100);
BigDecimal onehundred = Env.ONEHUNDRED;
BigDecimal multiplier = (onehundred).subtract(discount);
multiplier = multiplier.divide(onehundred, 6, BigDecimal.ROUND_HALF_UP);
BigDecimal newPrice = Price.multiply(multiplier);

View File

@ -96,10 +96,6 @@ public class MInvoicePaySchedule extends X_C_InvoicePaySchedule
/** Static Logger */
private static CLogger s_log = CLogger.getCLogger (MInvoicePaySchedule.class);
/** 100 */
private final static BigDecimal HUNDRED = new BigDecimal(100);
/**************************************************************************
* Standard Constructor
* @param ctx context
@ -156,10 +152,10 @@ public class MInvoicePaySchedule extends X_C_InvoicePaySchedule
else
{
due = due.multiply(paySchedule.getPercentage())
.divide(HUNDRED, scale, BigDecimal.ROUND_HALF_UP);
.divide(Env.ONEHUNDRED, scale, BigDecimal.ROUND_HALF_UP);
setDueAmt (due);
BigDecimal discount = due.multiply(paySchedule.getDiscount())
.divide(HUNDRED, scale, BigDecimal.ROUND_HALF_UP);
.divide(Env.ONEHUNDRED, scale, BigDecimal.ROUND_HALF_UP);
setDiscountAmt (discount);
setIsValid(true);
}

View File

@ -720,7 +720,7 @@ public class MOrderLine extends X_C_OrderLine
if (Env.ZERO.compareTo(list) == 0)
return;
BigDecimal discount = list.subtract(getPriceActual())
.multiply(new BigDecimal(100))
.multiply(Env.ONEHUNDRED)
.divide(list, getPrecision(), BigDecimal.ROUND_HALF_UP);
setDiscount(discount);
} // setDiscount

View File

@ -96,10 +96,6 @@ public class MOrderPaySchedule extends X_C_OrderPaySchedule
/** Static Logger */
private static CLogger s_log = CLogger.getCLogger (MOrderPaySchedule.class);
/** 100 */
private final static BigDecimal HUNDRED = new BigDecimal(100);
/**************************************************************************
* Standard Constructor
* @param ctx context
@ -156,10 +152,10 @@ public class MOrderPaySchedule extends X_C_OrderPaySchedule
else
{
due = due.multiply(paySchedule.getPercentage())
.divide(HUNDRED, scale, BigDecimal.ROUND_HALF_UP);
.divide(Env.ONEHUNDRED, scale, BigDecimal.ROUND_HALF_UP);
setDueAmt (due);
BigDecimal discount = due.multiply(paySchedule.getDiscount())
.divide(HUNDRED, scale, BigDecimal.ROUND_HALF_UP);
.divide(Env.ONEHUNDRED, scale, BigDecimal.ROUND_HALF_UP);
setDiscountAmt (discount);
setIsValid(true);
}

View File

@ -78,9 +78,6 @@ public class MPaymentTerm extends X_C_PaymentTerm
super(ctx, rs, trxName);
} // MPaymentTerm
/** 100 */
private final static BigDecimal HUNDRED = new BigDecimal(100);
/** Payment Schedule children */
private MPaySchedule[] m_schedule;
@ -159,7 +156,7 @@ public class MPaymentTerm extends X_C_PaymentTerm
if (percent != null)
total = total.add(percent);
}
boolean valid = total.compareTo(HUNDRED) == 0;
boolean valid = total.compareTo(Env.ONEHUNDRED) == 0;
if (isValid() != valid)
setIsValid (valid);
for (int i = 0; i < m_schedule.length; i++)
@ -172,7 +169,7 @@ public class MPaymentTerm extends X_C_PaymentTerm
}
if (valid)
return validMsg;
return "@Total@ = " + total + " - @Difference@ = " + HUNDRED.subtract(total);
return "@Total@ = " + total + " - @Difference@ = " + Env.ONEHUNDRED.subtract(total);
} // validate

View File

@ -84,8 +84,6 @@ public class MRfQResponseLineQty extends X_C_RfQResponseLineQty implements Compa
/** RfQ Line Qty */
private MRfQLineQty m_rfqQty = null;
/** 100 */
private static BigDecimal ONEHUNDRED = new BigDecimal (100);
/**
* Get RfQ Line Qty
@ -114,7 +112,7 @@ public class MRfQResponseLineQty extends X_C_RfQResponseLineQty implements Compa
BigDecimal discount = getDiscount();
if (discount != null)
{
if (discount.abs().compareTo(ONEHUNDRED) > 0)
if (discount.abs().compareTo(Env.ONEHUNDRED) > 0)
{
log.warning("Discount > 100 - " + discount);
return false;
@ -149,8 +147,8 @@ public class MRfQResponseLineQty extends X_C_RfQResponseLineQty implements Compa
return price;
// Calculate
// double result = price.doubleValue() * (100.0 - discount.doubleValue()) / 100.0;
BigDecimal factor = ONEHUNDRED.subtract(discount);
return price.multiply(factor).divide(ONEHUNDRED, 2, BigDecimal.ROUND_HALF_UP);
BigDecimal factor = Env.ONEHUNDRED.subtract(discount);
return price.multiply(factor).divide(Env.ONEHUNDRED, 2, BigDecimal.ROUND_HALF_UP);
} // getNetAmt

View File

@ -48,8 +48,6 @@ public class MTax extends X_C_Tax
/** Cache of Client */
private static CCache<Integer,MTax[]> s_cacheAll = new CCache<Integer,MTax[]>(Table_Name, Table_Name+"_Of_Client", 5);
/** 100 */
private static BigDecimal ONEHUNDRED = new BigDecimal(100);
/** Child Taxes */
private MTax[] m_childTaxes = null;
/** Postal Codes */
@ -258,7 +256,7 @@ public class MTax extends X_C_Tax
if (isZeroTax())
return Env.ZERO;
BigDecimal multiplier = getRate().divide(ONEHUNDRED, 12, BigDecimal.ROUND_HALF_UP);
BigDecimal multiplier = getRate().divide(Env.ONEHUNDRED, 12, BigDecimal.ROUND_HALF_UP);
BigDecimal tax = null;
if (!taxIncluded) // $100 * 6 / 100 == $6 == $100 * 0.06

View File

@ -44,7 +44,7 @@ public class BankTransfer extends SvrProcess
private int p_C_ConversionType_ID = 0; // Payment Conversion Type
private int p_C_Charge_ID = 0; // Charge to be used as bridge
private BigDecimal p_Amount = new BigDecimal(0); // Amount to be transfered between the accounts
private BigDecimal p_Amount = Env.ZERO; // Amount to be transfered between the accounts
private int p_From_C_BankAccount_ID = 0; // Bank Account From
private int p_To_C_BankAccount_ID= 0; // Bank Account To
private Timestamp p_StatementDate = null; // Date Statement
@ -116,7 +116,7 @@ public class BankTransfer extends SvrProcess
if (p_C_Charge_ID == 0)
throw new AdempiereUserError ("Business Partner required");
if (p_Amount.compareTo(new BigDecimal(0)) == 0)
if (p_Amount.signum() == 0)
throw new AdempiereUserError ("Amount required");
// Login Date

View File

@ -2,6 +2,7 @@
package test.functional;
import org.compiere.model.MProductPrice;
import test.AdempiereTestCase;
public class MProductTest extends AdempiereTestCase {
@ -86,7 +87,7 @@ public class MProductTest extends AdempiereTestCase {
}
public void testSetBaseInfo() {
MProductPricing prodprice = new MProductPricing(122,100, new BigDecimal (100),true);
MProductPricing prodprice = new MProductPricing(122,100, Env.ONEHUNDRED,true);
int uom = 0;
uom = prodprice.getC_UOM_ID();
assertTrue("UOM must be correct", uom == 100);

View File

@ -567,7 +567,7 @@ public class VTreeBOM extends CPanel implements FormPanel, ActionListener, TreeS
MUOM u = new MUOM(M_Product.getCtx(), M_Product.getC_UOM_ID(), M_Product.get_TrxName());
KeyNamePair uom = new KeyNamePair(u.get_ID(), u.getUOMSymbol());
line.add(uom); // 3 C_UOM_ID
line.add((BigDecimal) ((bomline.getBOMQty()!=null) ? bomline.getBOMQty() : new BigDecimal(0))); // 4 QtyBOM
line.add((BigDecimal) ((bomline.getBOMQty()!=null) ? bomline.getBOMQty() : Env.ZERO)); // 4 QtyBOM
DefaultMutableTreeNode child = new DefaultMutableTreeNode(line);
parent.add(child);
@ -595,7 +595,7 @@ public class VTreeBOM extends CPanel implements FormPanel, ActionListener, TreeS
MUOM u = new MUOM(M_Product.getCtx(), M_Product.getC_UOM_ID(), M_Product.get_TrxName());
KeyNamePair uom = new KeyNamePair(u.get_ID(),u.getUOMSymbol());
line.add(uom); // 3 C_UOM_ID
line.add((BigDecimal) ((bom.getBOMQty()!=null) ? bom.getBOMQty() : new BigDecimal(0))); // 4 QtyBOM
line.add((BigDecimal) ((bom.getBOMQty()!=null) ? bom.getBOMQty() : Env.ZERO)); // 4 QtyBOM
if(m_selected_id == bom.getM_ProductBOM_ID() || getM_Product_ID() == bom.getM_ProductBOM_ID())
dataBOM.add(line);

View File

@ -27,7 +27,6 @@ import java.awt.event.MouseListener;
import java.awt.font.LineBreakMeasurer;
import java.awt.font.TextAttribute;
import java.awt.font.TextLayout;
import java.math.BigDecimal;
import java.sql.Timestamp;
import java.text.AttributedCharacterIterator;
import java.text.AttributedString;
@ -391,7 +390,7 @@ public class VSchedulePanel extends JComponent implements MouseListener
ma.setS_Resource_ID(m_S_Resource_ID);
ma.setAssignDateFrom(TimeUtil.getDayTime(TimeUtil.addDays(m_startDate, dayIndex),
m_timePanel.getTimeSlot(timeIndex).getStartTime()));
ma.setQty(new BigDecimal(1));
ma.setQty(Env.ONE);
VAssignmentDialog vad = new VAssignmentDialog (AEnv.getFrame(this), ma, false, m_createNew);
m_infoSchedule.mAssignmentCallback(vad.getMResourceAssignment());
return;

View File

@ -717,7 +717,7 @@ public final class VNumber extends JComponent
DecimalFormat format, int displayType, String title, char operator)
{
if (log.isLoggable(Level.CONFIG)) log.config("Value=" + value);
BigDecimal startValue = BigDecimal.valueOf(0.0);
BigDecimal startValue = Env.ZERO;
try
{
if (value != null && value.length() > 0)

View File

@ -569,7 +569,7 @@ public class SubOrder extends PosSubPanel
if (p_posPanel != null && p_posPanel.f_curLine != null)
{
MOrder order = p_posPanel.f_curLine.getOrder();
BigDecimal total = new BigDecimal(0);
BigDecimal total = Env.ZERO;
if (order != null)
total = order.getGrandTotal();
paid = given.doubleValue() >= total.doubleValue();

View File

@ -207,7 +207,7 @@ public class WBOMDrop extends ADForm implements EventListener<Event>
Label lblProduct = new Label(Msg.translate(Env.getCtx(), "M_Product_ID"));
Label lblQty = new Label(Msg.translate(Env.getCtx(), "Qty"));
productQty.setValue(new BigDecimal(1));
productQty.setValue(Env.ONE);
productField.addEventListener(Events.ON_SELECT, this);
productQty.addEventListener(Events.ON_CHANGE, this);

View File

@ -319,7 +319,7 @@ public class WTreeBOM extends TreeBOM implements IFormController, EventListener<
MUOM u = new MUOM(product.getCtx(), product.getC_UOM_ID(), product.get_TrxName());
KeyNamePair uom = new KeyNamePair(u.get_ID(),u.getUOMSymbol());
line.add(uom); // 3 C_UOM_ID
line.add((BigDecimal) (new BigDecimal(1)).setScale(4, BigDecimal.ROUND_HALF_UP).stripTrailingZeros()); // 4 QtyBOM
line.add((BigDecimal) (Env.ONE).setScale(4, BigDecimal.ROUND_HALF_UP).stripTrailingZeros()); // 4 QtyBOM
// dummy root node, as first node is not displayed in tree
mySimpleTreeNode parent = new mySimpleTreeNode("Root",new ArrayList<TreeNode<Object>>());
@ -441,7 +441,7 @@ public class WTreeBOM extends TreeBOM implements IFormController, EventListener<
MUOM u = new MUOM(M_Product.getCtx(), M_Product.getC_UOM_ID(), M_Product.get_TrxName());
KeyNamePair uom = new KeyNamePair(u.get_ID(),u.getUOMSymbol());
line.add(uom); // 3 C_UOM_ID
line.add((BigDecimal) ((bomline.getBOMQty()!=null) ? bomline.getBOMQty() : new BigDecimal(0)).setScale(4, BigDecimal.ROUND_HALF_UP).stripTrailingZeros()); // 4 QtyBOM
line.add((BigDecimal) ((bomline.getBOMQty()!=null) ? bomline.getBOMQty() : Env.ZERO).setScale(4, BigDecimal.ROUND_HALF_UP).stripTrailingZeros()); // 4 QtyBOM
mySimpleTreeNode child = new mySimpleTreeNode(line,new ArrayList<TreeNode<Object>>());
if (!reload)
@ -470,7 +470,7 @@ public class WTreeBOM extends TreeBOM implements IFormController, EventListener<
MUOM u = new MUOM(M_Product.getCtx(), M_Product.getC_UOM_ID(), M_Product.get_TrxName());
KeyNamePair uom = new KeyNamePair(u.get_ID(),u.getUOMSymbol());
line.add(uom); // 3 C_UOM_ID
line.add((BigDecimal) ((bom.getBOMQty()!=null) ? bom.getBOMQty() : new BigDecimal(0)).setScale(4, BigDecimal.ROUND_HALF_UP).stripTrailingZeros()); // 4 QtyBOM
line.add((BigDecimal) ((bom.getBOMQty()!=null) ? bom.getBOMQty() : Env.ZERO).setScale(4, BigDecimal.ROUND_HALF_UP).stripTrailingZeros()); // 4 QtyBOM
if(m_selected_id == bom.getM_ProductBOM_ID() || getM_Product_ID() == bom.getM_ProductBOM_ID())
dataBOM.add(line);

View File

@ -341,7 +341,7 @@ public abstract class StatementCreateFromBatch extends CreateFromForm
public void info(IMiniTable miniTable, IStatusBar statusBar)
{
DecimalFormat format = DisplayType.getNumberFormat(DisplayType.Amount);
BigDecimal total = new BigDecimal(0);
BigDecimal total = Env.ZERO;
int rows = miniTable.getRowCount();
int count = 0;
for(int i = 0; i < rows; i++)

View File

@ -166,7 +166,7 @@ public abstract class CreateFromBatch extends CreateFrom
public void info(IMiniTable miniTable, IStatusBar statusBar)
{
DecimalFormat format = DisplayType.getNumberFormat(DisplayType.Amount);
BigDecimal total = new BigDecimal(0);
BigDecimal total = Env.ZERO;
int rows = miniTable.getRowCount();
int count = 0;
for(int i = 0; i < rows; i++)