List of usage examples for java.math BigInteger ZERO
BigInteger ZERO
To view the source code for java.math BigInteger ZERO.
Click Source Link
From source file:net.sf.json.TestJSONObject.java
public void testToBean_DynaBean__BigInteger_BigDecimal() { BigInteger l = new BigDecimal("1.7976931348623157E308").toBigInteger(); BigDecimal m = new BigDecimal("1.7976931348623157E307").add(new BigDecimal("0.0001")); JSONObject json = new JSONObject().element("i", BigInteger.ZERO).element("d", MorphUtils.BIGDECIMAL_ONE) .element("bi", l).element("bd", m); Object bean = JSONObject.toBean(json); Object i = ((MorphDynaBean) bean).get("i"); Object d = ((MorphDynaBean) bean).get("d"); assertTrue(i instanceof Integer); assertTrue(d instanceof Integer); Object bi = ((MorphDynaBean) bean).get("bi"); Object bd = ((MorphDynaBean) bean).get("bd"); assertTrue(bi instanceof BigInteger); assertTrue(bd instanceof BigDecimal); }
From source file:com.google.bitcoin.core.Wallet.java
/** * <p>Returns true if the given transaction sends coins to any of our keys, or has inputs spending any of our outputs, * and if includeDoubleSpending is true, also returns true if tx has inputs that are spending outputs which are * not ours but which are spent by pending transactions.</p> * * <p>Note that if the tx has inputs containing one of our keys, but the connected transaction is not in the wallet, * it will not be considered relevant.</p> *///from ww w .ja v a2 s .com public boolean isTransactionRelevant(Transaction tx) throws ScriptException { lock.lock(); try { return tx.isMine(this) || tx.getValueSentFromMe(this).compareTo(BigInteger.ZERO) > 0 || tx.getValueSentToMe(this).compareTo(BigInteger.ZERO) > 0 || checkForDoubleSpendAgainstPending(tx, false); } finally { lock.unlock(); } }
From source file:edu.hku.sdb.rewrite.SdbSchemeRewriter.java
/** * Rewrite the group by expression./*ww w . j a va2s. c o m*/ * * @param groupExprs * @throws UnSupportedException */ protected void rewriteGroupByExprs(List<Expr> groupExprs) throws UnSupportedException { if (groupExprs == null) return; Set<String> tbls = new HashSet<>(); for (Expr expr : groupExprs) { tbls.addAll(findAllTbls(expr)); } if (tbls.size() < 1) { // No column involved in the group by clause, no need to rewrite. return; } else if (tbls.size() == 1) { String tblName = (String) tbls.toArray()[0]; FieldLiteral S = new FieldLiteral(tblName, ColumnDefinition.S_COLUMN_NAME, Type.INT, true, null); S.setSdbColKey(getTableColumnKey(tblName, ColumnDefinition.S_COLUMN_NAME)); for (int i = 0; i < groupExprs.size(); i++) { if (groupExprs.get(i).involveEncrytedCol()) { if (groupExprs.get(i) instanceof FieldLiteral) { BigInteger targetM = SDBEncrypt.generatePositiveRand(prime1, prime2); BigInteger targetX = BigInteger.ZERO; BigInteger[] pqLeft = SDBEncrypt.keyUpdateClient(groupExprs.get(i).getSdbColKey().getM(), targetM, S.getSdbColKey().getM(), groupExprs.get(i).getSdbColKey().getX(), targetX, S.getSdbColKey().getX(), prime1, prime2); groupExprs.set(i, buildSdbKeyUpdateExpr(groupExprs.get(i), S, new BigIntLiteral(pqLeft[0]), new BigIntLiteral(pqLeft[1]), new BigIntLiteral(n), targetM, targetX)); } else { UnSupportedException e = new UnSupportedException( "Can not support " + groupExprs.get(i).getClass().getName()); LOG.error("There is unsupported group by attributes!", e); throw e; } } } } else { UnSupportedException e = new UnSupportedException( "Can not support " + "group by clause involves columns from different tables!"); LOG.error("There is unsupported group by clause!", e); throw e; } }
From source file:org.sparkbit.jsonrpc.SparkBitJSONRPCServiceImpl.java
private ArrayList<JSONRPCTransactionAmount> getAssetTransactionAmounts(Wallet wallet, Transaction tx, boolean excludeBTCFee, boolean absoluteBTCFee) { if (wallet == null || tx == null) return null; Map<Integer, BigInteger> receiveMap = wallet.CS.getAssetsSentToMe(tx); Map<Integer, BigInteger> sendMap = wallet.CS.getAssetsSentFromMe(tx); // System.out.println(">>>> tx = " + tx.getHashAsString()); // System.out.println(">>>> receive map = " + receiveMap); // System.out.println(">>>> send map = " + sendMap); //Map<String, String> nameAmountMap = new TreeMap<>(); ArrayList<JSONRPCTransactionAmount> resultList = new ArrayList<>(); boolean isSentByMe = tx.sent(wallet); Map<Integer, BigInteger> loopMap = (isSentByMe) ? sendMap : receiveMap; // Integer assetID = null; BigInteger netAmount = null;//from ww w . j ava 2 s. com // for (Map.Entry<Integer, BigInteger> entry : loopMap.entrySet()) { for (Integer assetID : loopMap.keySet()) { // assetID = entry.getKey(); if (assetID == null || assetID == 0) continue; // skip bitcoin BigInteger receivedAmount = receiveMap.get(assetID); // should be number of raw units BigInteger sentAmount = sendMap.get(assetID); boolean isReceivedAmountMissing = (receivedAmount == null); boolean isSentAmountMissing = (sentAmount == null); netAmount = BigInteger.ZERO; if (!isReceivedAmountMissing) netAmount = netAmount.add(receivedAmount); if (!isSentAmountMissing) netAmount = netAmount.subtract(sentAmount); if (isSentByMe && !isSentAmountMissing && sentAmount.equals(BigInteger.ZERO)) { // Catch a case where for a send transaction, the send amount for an asset is 0, // but the receive cmount is not 0. Also the asset was not valid. continue; } CSAsset asset = wallet.CS.getAsset(assetID); if (asset == null) { // something went wrong, we have asset id but no asset, probably deleted. // For now, we carry on, and we display what we know. } if (netAmount.equals(BigInteger.ZERO) && isSentByMe) { // If net asset is 0 and this is our send transaction, // we don't need to show anything, as this probably due to implicit transfer. // So continue the loop. continue; } if (netAmount.equals(BigInteger.ZERO) && !isSentByMe) { // Receiving an asset, where the value is 0 because its not confirmed yet, // or not known because asset files not uploaded so we dont know display format. // Anyway, we don't do anything here as we do want to display this incoming // transaction the best we can. } // System.out.println(">>>> isSentAmountMissing = " + isSentAmountMissing); // System.out.println(">>>> asset reference = " + asset.getAssetReference()); // System.out.println(">>>> asset name = " + asset.getName()); String name = null; CoinSparkGenesis genesis = null; boolean isUnknown = false; if (asset != null) { genesis = asset.getGenesis(); name = asset.getNameShort(); // could return null? } if (name == null) { isUnknown = true; if (genesis != null) { name = "Asset from " + genesis.getDomainName(); } else { // No genesis block found yet name = "Other Asset"; } } String s1 = null; if (asset == null || isUnknown == true || (netAmount.equals(BigInteger.ZERO) && !isSentByMe)) { // We don't have formatting details since asset is unknown or deleted // If there is a quantity, we don't display it since we don't have display format info // Of if incoming asset transfer, unconfirmed, it will be zero, so show ... instead s1 = "..."; } else { BigDecimal displayUnits = CSMiscUtils.getDisplayUnitsForRawUnits(asset, netAmount); s1 = CSMiscUtils.getFormattedDisplayString(asset, displayUnits); } // // Create JSONRPCTransactionAmount and add it to list // String fullName = ""; String assetRef = ""; if (asset != null) { fullName = asset.getName(); if (fullName == null) fullName = name; // use short name assetRef = CSMiscUtils.getHumanReadableAssetRef(asset); } BigDecimal displayQty = CSMiscUtils.getDisplayUnitsForRawUnits(asset, netAmount); JSONRPCTransactionAmount amount = new JSONRPCTransactionAmount(); amount.setAsset_ref(assetRef); amount.setDisplay(s1); amount.setName(fullName); amount.setName_short(name); amount.setQty(displayQty.doubleValue()); amount.setRaw(netAmount.longValue()); resultList.add(amount); } BigInteger satoshiAmount = receiveMap.get(0); satoshiAmount = satoshiAmount.subtract(sendMap.get(0)); // We will show the fee separately so no need to include here. if (excludeBTCFee && isSentByMe) { BigInteger feeSatoshis = tx.calculateFee(wallet); // returns positive if (absoluteBTCFee) { satoshiAmount = satoshiAmount.abs().subtract(feeSatoshis); } else { satoshiAmount = satoshiAmount.add(feeSatoshis); } } String btcAmount = Utils.bitcoinValueToFriendlyString(satoshiAmount) + " BTC"; BigDecimal satoshiAmountBTC = new BigDecimal(satoshiAmount).divide(new BigDecimal(Utils.COIN)); JSONRPCTransactionAmount amount = new JSONRPCTransactionAmount(); amount.setAsset_ref("bitcoin"); amount.setDisplay(btcAmount); amount.setName("Bitcoin"); amount.setName_short("Bitcoin"); amount.setQty(satoshiAmountBTC.doubleValue()); amount.setRaw(satoshiAmount.longValue()); resultList.add(amount); return resultList; }
From source file:piuk.blockchain.android.MyRemoteWallet.java
public Pair<Transaction, Long> makeTransactionCustom(final HashMap<String, BigInteger> sendingAddresses, List<MyTransactionOutPoint> unspent, HashMap<String, BigInteger> receivingAddresses, BigInteger fee, final String changeAddress) throws Exception { long priority = 0; if (unspent == null || unspent.size() == 0) throw new InsufficientFundsException("No free outputs to spend."); if (fee == null) fee = BigInteger.ZERO; //Construct a new transaction Transaction tx = new Transaction(getParams()); BigInteger outputValueSum = BigInteger.ZERO; for (Iterator<Entry<String, BigInteger>> iterator = receivingAddresses.entrySet().iterator(); iterator .hasNext();) {//from w w w .j a v a 2 s . c o m Map.Entry<String, BigInteger> mapEntry = iterator.next(); String toAddress = mapEntry.getKey(); BigInteger amount = mapEntry.getValue(); if (amount == null || amount.compareTo(BigInteger.ZERO) <= 0) throw new Exception("You must provide an amount"); outputValueSum = outputValueSum.add(amount); //Add the output BitcoinScript toOutputScript = BitcoinScript.createSimpleOutBitoinScript(new BitcoinAddress(toAddress)); // Log.d("MyRemoteWallet", "MyRemoteWallet makeTransactionCustom toAddress: " + toAddress + "amount: " + amount); TransactionOutput output = new TransactionOutput(getParams(), null, amount, toOutputScript.getProgram()); tx.addOutput(output); } //Now select the appropriate inputs BigInteger valueSelected = BigInteger.ZERO; BigInteger valueNeeded = outputValueSum.add(fee); Map<String, BigInteger> addressTotalUnspentValues = new HashMap<String, BigInteger>(); for (MyTransactionOutPoint outPoint : unspent) { BitcoinScript script = new BitcoinScript(outPoint.getScriptBytes()); if (script.getOutType() == BitcoinScript.ScriptOutTypeStrange) continue; BitcoinScript inputScript = new BitcoinScript(outPoint.getConnectedPubKeyScript()); String address = inputScript.getAddress().toString(); BigInteger addressSendAmount = sendingAddresses.get(address); if (addressSendAmount == null) { throw new Exception("Invalid transaction address send amount is null"); } final BigInteger addressTotalUnspentValue = addressTotalUnspentValues.get(address); if (addressTotalUnspentValue == null) { addressTotalUnspentValues.put(address, outPoint.value); } else { addressTotalUnspentValues.put(address, addressTotalUnspentValue.add(outPoint.value)); } MyTransactionInput input = new MyTransactionInput(getParams(), null, new byte[0], outPoint); input.outpoint = outPoint; // Log.d("MyRemoteWallet", "MyRemoteWallet makeTransactionCustom fromAddress: " + address + "amount: " + outPoint.value); tx.addInput(input); valueSelected = valueSelected.add(outPoint.value); priority += outPoint.value.longValue() * outPoint.confirmations; //if (valueSelected.compareTo(valueNeeded) == 0 || valueSelected.compareTo(valueNeeded.add(minFreeOutputSize)) >= 0) // break; } //Check the amount we have selected is greater than the amount we need if (valueSelected.compareTo(valueNeeded) < 0) { throw new InsufficientFundsException("Insufficient Funds"); } //decide change if (changeAddress == null) { BigInteger feeAmountLeftToAccountedFor = fee; for (Iterator<Entry<String, BigInteger>> iterator = addressTotalUnspentValues.entrySet() .iterator(); iterator.hasNext();) { final Entry<String, BigInteger> entry = iterator.next(); final String address = entry.getKey(); final BigInteger addressTotalUnspentValue = entry.getValue(); final BigInteger addressSendAmount = sendingAddresses.get(address); BigInteger addressChangeAmount = addressTotalUnspentValue.subtract(addressSendAmount); if (feeAmountLeftToAccountedFor.compareTo(BigInteger.ZERO) > 0) { if (addressChangeAmount.compareTo(feeAmountLeftToAccountedFor) >= 0) { //have enough to fill fee addressChangeAmount = addressChangeAmount.subtract(feeAmountLeftToAccountedFor); feeAmountLeftToAccountedFor = BigInteger.ZERO; } else { // do not have enough to fill fee feeAmountLeftToAccountedFor = feeAmountLeftToAccountedFor.subtract(addressChangeAmount); addressChangeAmount = BigInteger.ZERO; } } if (addressChangeAmount.compareTo(BigInteger.ZERO) > 0) { //Add the output BitcoinScript toOutputScript = BitcoinScript .createSimpleOutBitoinScript(new BitcoinAddress(address)); // Log.d("MyRemoteWallet", "MyRemoteWallet makeTransactionCustom changeAddress == null: " + address + "addressChangeAmount: " + addressChangeAmount); TransactionOutput output = new TransactionOutput(getParams(), null, addressChangeAmount, toOutputScript.getProgram()); tx.addOutput(output); } } } else { BigInteger addressChangeAmountSum = BigInteger.ZERO; for (Iterator<Entry<String, BigInteger>> iterator = addressTotalUnspentValues.entrySet() .iterator(); iterator.hasNext();) { final Entry<String, BigInteger> entry = iterator.next(); final String address = entry.getKey(); final BigInteger addressTotalUnspentValue = entry.getValue(); final BigInteger addressSendAmount = sendingAddresses.get(address); final BigInteger addressChangeAmount = addressTotalUnspentValue.subtract(addressSendAmount); addressChangeAmountSum = addressChangeAmountSum.add(addressChangeAmount); } if (addressChangeAmountSum.compareTo(BigInteger.ZERO) > 0) { //Add the output BitcoinScript toOutputScript = BitcoinScript .createSimpleOutBitoinScript(new BitcoinAddress(changeAddress)); TransactionOutput output = new TransactionOutput(getParams(), null, addressChangeAmountSum.subtract(fee), toOutputScript.getProgram()); // Log.d("MyRemoteWallet", "MyRemoteWallet makeTransactionCustom changeAddress != null: " + changeAddress + "addressChangeAmount: " + output.getValue()); tx.addOutput(output); } } long estimatedSize = tx.bitcoinSerialize().length + (114 * tx.getInputs().size()); priority /= estimatedSize; return new Pair<Transaction, Long>(tx, priority); }
From source file:net.sf.json.TestJSONArray.java
public void testToList_BigInteger() { List expected = new ArrayList(); expected.add(BigInteger.ZERO); expected.add(BigInteger.ONE); JSONArray jsonArray = JSONArray.fromObject(expected); List actual = JSONArray.toList(jsonArray); Assertions.assertEquals(expected, actual); }
From source file:org.docx4j.convert.in.xhtml.XHTMLImporter.java
private void setCellWidthAuto(TcPr tcPr) { // <w:tcW w:w="0" w:type="auto"/> TblWidth tblW = Context.getWmlObjectFactory().createTblWidth(); tblW.setW(BigInteger.ZERO); tblW.setType(TblWidth.TYPE_AUTO);/*from w ww .j av a 2 s . c o m*/ tcPr.setTcW(tblW); }
From source file:com.sdcs.courierbooking.service.UserServiceImpl.java
@Override public String deliveryBoyBooking(String contactNumber, String drestorantName, Double lat, Double longitude) { String newCOurier = userDao.foodPickUpUserRegister(contactNumber, drestorantName, lat, longitude); JSONObject newCourierJsonObject = new JSONObject(); if (newCOurier == null) { newCourierJsonObject.put("result", false); } else {/* ww w.j a va2 s .c o m*/ String strSmsText = "M/S%20" + drestorantName + "%20your%20delivery%20boy%20booking%20has%20been%20confirmed%20&%20your%20reference%20number%20is%20" + newCOurier + ".Our%20delivery%20boy%20will%20pick%20the%20consignment%20shortly.Thank%20you."; SdcsSMSComponent.sendSms(contactNumber, strSmsText); String strSmsTexta = "A%20new%20delivery%20boy%20booking%20is%20done%20from%20" + drestorantName + ".%20Reference%20id%20is%20" + newCOurier + ".Contact%20number%20is%20" + contactNumber + "."; SdcsSMSComponent.sendSms("9535337626", strSmsTexta); SdcsSMSComponent.sendSms("9916168585", strSmsTexta); newCourierJsonObject.put("trackingNumber", newCOurier); newCourierJsonObject.put("result", true); DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss"); Date date = new Date(); String body = "<div>" + "<h4 style='color:navy'>Dear Admin.,</h4><br>" + "<p Style='color:orange'>New Delivery Boy Booking from the following Details</p><br>" + "<table style='border:1px solid blue;border-collapse: collapse;'>" + "<tr style='color:red;border:1px solid blue'>" + "<th style='border:1px solid blue'>" + "Time" + "</th>" + "<th style='border:1px solid blue'>" + "Order Id" + "</th>" + "<th style='border:1px solid blue'>" + "Restaurant name" + "</th>" + "<th style='border:1px solid blue'>" + "Contact Number" + "</th>" + "</tr>" + "<tr>" + "<td style='border:1px solid blue;color:blue;'>" + dateFormat.format(date) + "</td>" + "<td style='border:1px solid blue;color:blue;'>" + newCOurier + "</td>" + "<td style='border:1px solid blue;color:blue;'>" + drestorantName + "</td>" + "<td style='border:1px solid blue;color:blue;'>" + contactNumber + "</td>" + "</tr>" + "</table><br>" + "<p>Thank you</p>" + "</div>"; SdcsEmailComponent.sendMail("sdcs2me@gmail.com", "DELIVERY BOY BOOKING", body, BigInteger.ZERO); // TODO Auto-generated method stub } return newCourierJsonObject.toString(); }
From source file:org.ethereum.rpc.Web3Impl.java
private String sendPersonalTransacction(CallArguments args, Account account) throws Exception { if (account == null) throw new Exception("From address private key could not be found in this node"); String toAddress = args.to != null ? Hex.toHexString(StringHexToByteArray(args.to)) : null; BigInteger accountNonce = args.nonce != null ? TypeConverter.StringNumberAsBigInt(args.nonce) : (worldManager.getPendingState().getRepository().getNonce(account.getAddress())); BigInteger value = args.value != null ? TypeConverter.StringNumberAsBigInt(args.value) : BigInteger.ZERO; BigInteger gasPrice = args.gasPrice != null ? TypeConverter.StringNumberAsBigInt(args.gasPrice) : BigInteger.ZERO;//w w w . j av a 2s .c o m BigInteger gasLimit = args.gas != null ? TypeConverter.StringNumberAsBigInt(args.gas) : BigInteger.valueOf(GasCost.TRANSACTION); if (args.data != null && args.data.startsWith("0x")) args.data = args.data.substring(2); Transaction tx = Transaction.create(toAddress, value, accountNonce, gasPrice, gasLimit, args.data); tx.sign(account.getEcKey().getPrivKeyBytes()); eth.submitTransaction(tx); return TypeConverter.toJsonHex(tx.getHash()); }
From source file:edu.hku.sdb.rewrite.SdbSchemeRewriter.java
/** * Rewrite a function call expression.//from ww w . j av a2 s . co m * * @param funCallExpr * @param S * @return * @throws UnSupportedException */ protected Expr rewriteFunCallExpr(FunctionCallExpr funCallExpr, Expr S) throws UnSupportedException { FunctionName funName = funCallExpr.getFunctionName(); if (funName.getName().equals(ParserConstant.FUNCTION_COUNT)) { return funCallExpr; } else if (funName.getName().equals(ParserConstant.FUNCTION_SUM)) { FunctionParams functionParams = funCallExpr.getFunctionParams(); // The sum function can only has one parameter expression assert (functionParams.getExprs().size() == 1); Expr expr = functionParams.getExprs().get(0); BigInteger targetM = SDBEncrypt.generatePositiveRand(prime1, prime2); BigInteger targetX = BigInteger.ZERO; BigInteger[] pqLeft = SDBEncrypt.keyUpdateClient(expr.getSdbColKey().getM(), targetM, S.getSdbColKey().getM(), expr.getSdbColKey().getX(), targetX, S.getSdbColKey().getX(), prime1, prime2); functionParams.getExprs().set(0, buildSdbKeyUpdateExpr(expr, S, new BigIntLiteral(pqLeft[0]), new BigIntLiteral(pqLeft[1]), new BigIntLiteral(n), targetM, targetX)); functionParams.getExprs().get(0).setSdbColKey(new SdbColumnKey(targetM, targetX)); functionParams.getExprs().add(new BigIntLiteral(n)); funName.setName(SdbOperator.SDB_SUM.toString()); funCallExpr.setName(funName); funCallExpr.setFunctionParams(functionParams); funCallExpr.setSdbColKey(new SdbColumnKey(targetM, targetX)); funCallExpr.setType(functionParams.getExprs().get(0).getType()); return funCallExpr; } else { UnSupportedException e = new UnSupportedException("Unsupported function " + funName); LOG.error("There is unsupported function call!", e); throw e; } }