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:com.bittorrent.mpetazzoni.bencode.BDecoder.java
/** * Returns the next b-encoded value on the stream and makes sure it is a * number./*from w w w . j av a 2 s.co m*/ * * @throws InvalidBEncodingException If it is not a number. */ public BEValue bdecodeNumber() throws IOException { int c = this.getNextIndicator(); if (c != 'i') { throw new InvalidBEncodingException("Expected 'i', not '" + (char) c + "'"); } this.indicator = 0; c = this.read(); if (c == '0') { c = this.read(); if (c == 'e') return new BEValue(BigInteger.ZERO); else throw new InvalidBEncodingException("'e' expected after zero," + " not '" + (char) c + "'"); } // We don't support more the 255 char big integers char[] chars = new char[256]; int off = 0; if (c == '-') { c = this.read(); if (c == '0') throw new InvalidBEncodingException("Negative zero not allowed"); chars[off] = '-'; off++; } if (c < '1' || c > '9') throw new InvalidBEncodingException("Invalid Integer start '" + (char) c + "'"); chars[off] = (char) c; off++; c = this.read(); int i = c - '0'; while (i >= 0 && i <= 9) { chars[off] = (char) c; off++; c = read(); i = c - '0'; } if (c != 'e') throw new InvalidBEncodingException("Integer should end with 'e'"); String s = new String(chars, 0, off); return new BEValue(new BigInteger(s)); }
From source file:de.decoit.visa.net.IPAddress.java
/** * Return a {@link java.math.BigInteger BigInteger} object containing the * bit mask of this address.// w ww . jav a 2 s.com * * @return Bit mask of this address */ BigInteger toBigIntBitmask() { BigInteger rv = BigInteger.ZERO; for (int i = 0; i < ipAddressGroups.length; i++) { rv = rv.add(BigInteger.valueOf(ipAddressGroups[i])); if (i < ipAddressGroups.length - 1) { rv = rv.shiftLeft(ipVersion.getSegmentBitCount()); } } return rv; }
From source file:com.smi.travel.controller.PaymentStockController.java
@Override protected ModelAndView process(HttpServletRequest request, HttpServletResponse response, HttpSession session) { UtilityFunction utilty = new UtilityFunction(); SystemUser user = (SystemUser) session.getAttribute("USER"); String action = request.getParameter("action"); String payNo = request.getParameter("payNo"); String payId = request.getParameter("payId"); String createBy = request.getParameter("createBy"); String createDate = request.getParameter("createDate"); // String totalSale = request.getParameter("totalSaleAll"); // String totalCost = request.getParameter("totalCostAll"); String curCost = request.getParameter("curCost"); String curSale = request.getParameter("curSale"); String noStockTable = request.getParameter("noStockTable"); // String totalCostAll = request.getParameter("totalCostAll"); // String totalSaleAll = request.getParameter("totalSaleAll"); System.out.println("===== createDate =====" + createDate); request.setAttribute(NOSTOCKTABLE, 1); String saveresult = ""; if ("new".equalsIgnoreCase(action)) { } else if ("searchPayNo".equalsIgnoreCase(action)) { PaymentStock paymentStock = new PaymentStock(); PaymentStockDetail paymentStockDetail = new PaymentStockDetail(); PaymentStockItem paymentStockItem = new PaymentStockItem(); if (!"".equals(payNo)) { paymentStock = paymentStockService.getPaymentStockFromPayNo(payNo); if (paymentStock != null) { if (!paymentStock.getId().isEmpty()) { request.setAttribute("totalCostAll", paymentStock.getCostAmount() == null ? "" : paymentStock.getCostAmount()); request.setAttribute("totalSaleAll", paymentStock.getSaleAmount() == null ? "" : paymentStock.getSaleAmount()); List<PaymentStockDetail> psdList = new ArrayList<PaymentStockDetail>(); List<PaymentStockDetail> paymentStockDetailList = paymentStockService .getListPaymentStockDetailFromPaymentStockId(paymentStock.getId()); // List<PaymentStockItem> paymentStockItemList = paymentStockService.getListPaymentStockItemFromPaymentStockId(paymentStock.getId()); // request.setAttribute(PAYMENTSTOCKITEMLIST,paymentStockItemList); List<StockDetail> stockDetailList = new ArrayList<StockDetail>(); if (paymentStockDetailList != null) { for (int i = 0; i < paymentStockDetailList.size(); i++) { BigDecimal cost = new BigDecimal(BigInteger.ZERO); BigDecimal sale = new BigDecimal(BigInteger.ZERO); PaymentStockDetail pad = paymentStockDetailList.get(i); List<PaymentStockItem> paymentStockItems = new ArrayList<PaymentStockItem>( pad.getPaymentStockItems()); if (paymentStockItems != null) { for (int k = 0; k < paymentStockItems.size(); k++) { PaymentStockItem psi = paymentStockItems.get(k); if (psi.getCost() != null) { cost = cost.add(psi.getCost()); }//from w ww . j av a 2 s .c o m if (psi.getSale() != null) { sale = sale.add(psi.getSale()); } } } pad.setCost(cost); pad.setSale(sale); psdList.add(pad); if (pad.getStock() != null) { List<StockDetail> stockDetails = new ArrayList<StockDetail>( pad.getStock().getStockDetails()); if (stockDetails != null) { for (int j = 0; j < stockDetails.size(); j++) { StockDetail sd = new StockDetail(); sd = stockDetails.get(j); stockDetailList.add(sd); } } } } } request.setAttribute(STOCKDETAILLIST, stockDetailList); request.setAttribute(PAYMENTSTOCKDETAILLIST, psdList); if (paymentStockDetailList != null) { request.setAttribute(NOSTOCKTABLE, paymentStockDetailList.size() + 1); } request.setAttribute(PAYMENTSTOCK, paymentStock); request.setAttribute(CREATEDATE, String.valueOf(paymentStock.getCreateDate())); List<PaymentStock> payList = new ArrayList<PaymentStock>(); payList.add(paymentStock); request.setAttribute(PAYMENTSTOCKTEMP, payList); } } else { request.setAttribute(SEARCHRESULT, "searchfail"); } } } else if ("deletePaymentStock".equalsIgnoreCase(action)) { String psdIdDelete = request.getParameter("psdIdDelete"); System.out.println("psdIdDelete ::: " + psdIdDelete); String result = paymentStockService.deletePaymentStock(psdIdDelete); if (result == "success") { request.setAttribute(DELETERESULT, "delete successful"); } else { request.setAttribute(DELETERESULT, "delete unsuccessful"); } } else if ("savePaymentStock".equalsIgnoreCase(action)) { PaymentStock paymentStock = new PaymentStock(); paymentStock.setId(payId); paymentStock.setPayStockNo(payNo); if ("".equalsIgnoreCase(payId)) { paymentStock.setCreateBy(user.getUsername()); paymentStock.setCreateDate(new Date()); } else { System.out.println(" createDate " + createDate); paymentStock.setCreateBy(createBy); paymentStock.setCreateDate( utilty.convertStringToDate(new SimpleDateFormat("yyyy-MM-dd", new Locale("us", "us")) .format(utilty.convertStringToDate(createDate)))); paymentStock.setUpdateBy(user.getUsername()); paymentStock.setUpdateDate(new Date()); } // totalcost = totalcost.add(new BigDecimal(String.valueOf(StringUtils.isNotEmpty(totalCostTempCal) ? totalCostTempCal.replaceAll(",","") : 0))); // totalsale = totalsale.add(new BigDecimal(String.valueOf(StringUtils.isNotEmpty(totalSaleTempCal) ? totalSaleTempCal.replaceAll(",","") : 0))); paymentStock.setCurCost(curCost); paymentStock.setCurSale(curSale); String countRowStock = request.getParameter("countRowStock"); String countRowDetail = request.getParameter("countRowDetail"); countRowStock = noStockTable; System.out.println(" countRowStock " + countRowStock + "+++++++ countRowDetail " + countRowDetail); int rowsStock = Integer.parseInt(countRowStock); int rowsDetail = Integer.parseInt(countRowDetail); if (paymentStock.getPaymentStockDetails() == null) { paymentStock.setPaymentStockDetails(new ArrayList<PaymentStockDetail>()); } for (int i = 1; i < rowsStock; i++) { String paymentStockId = request.getParameter("paymentStockId" + i); String stockId = request.getParameter("stockId" + i); String paymentStockDetailId = request.getParameter("paymentStockDetailId" + i); if (!"".equalsIgnoreCase(stockId) && stockId != null) { PaymentStockDetail psd = new PaymentStockDetail(); psd.setId(paymentStockDetailId); // save Payment Stock Detail Id psd.setPaymentStock(paymentStock); Stock stock = new Stock(); // save Stock Id stock.setId(stockId); psd.setStock(stock); for (int j = 1; j < rowsDetail; j++) { PaymentStockItem psi = new PaymentStockItem(); String psiIdTable = request.getParameter("psiIdTableTempCount" + j); String psdIdTable = request.getParameter("psdIdTableTempCount" + j); String stockDetailIdTable = request.getParameter("stockDetailIdTableTempCount" + j); String cost = request.getParameter("costTempCount" + j); String sale = request.getParameter("saleTempCount" + j); String stockIdTable = request.getParameter("stockIdTableTempCount" + j); if ((!"".equalsIgnoreCase(stockIdTable) && stockIdTable != null) && (!"".equalsIgnoreCase(stockId) && stockId != null)) { System.out.println(" stockId " + i + " ____ " + stockId); System.out.println(" stockIdTable " + j + " ____ " + stockIdTable); if (stockId.equalsIgnoreCase(stockIdTable)) { if ((!"".equalsIgnoreCase(cost) && cost != null) || (!"".equalsIgnoreCase(sale) && sale != null)) { System.out.println(" psiIdTable " + j + " ____ " + psiIdTable); psi.setId(psiIdTable); psi.setPaymentStockDetail(psd); StockDetail stockDetail = new StockDetail(); stockDetail.setId(stockDetailIdTable); psi.setStockDetail(stockDetail); // totalCostAll = totalCostAll.add(new BigDecimal(String.valueOf(StringUtils.isNotEmpty(cost) ? cost.replaceAll(",","") : 0))); // totalSaleAll = totalSaleAll.add(new BigDecimal(String.valueOf(StringUtils.isNotEmpty(sale) ? sale.replaceAll(",","") : 0))); psi.setCost(new BigDecimal(String .valueOf(StringUtils.isNotEmpty(cost) ? cost.replaceAll(",", "") : 0))); psi.setSale(new BigDecimal(String .valueOf(StringUtils.isNotEmpty(sale) ? sale.replaceAll(",", "") : 0))); psd.getPaymentStockItems().add(psi); } } } } paymentStock.getPaymentStockDetails().add(psd); } } // paymentStock.setCostAmount(totalCostAll); // paymentStock.setSaleAmount(totalSaleAll); saveresult = paymentStockService.insertOrUpdatePaymentStock(paymentStock); System.out.println(" saveresult " + saveresult); if ("fail".equalsIgnoreCase(saveresult)) { request.setAttribute(SAVERESULT, "save unsuccessful"); } else if ("success".equalsIgnoreCase(saveresult)) { request.setAttribute(SAVERESULT, "save successful"); } else { paymentStock.setPayStockNo(saveresult); request.setAttribute(SAVERESULT, "save successful"); } request.setAttribute(PAYMENTSTOCK, paymentStock); List<PaymentStockDetail> paymentStockDetailList = paymentStockService .getListPaymentStockDetailFromPaymentStockId(paymentStock.getId()); // List<PaymentStockItem> paymentStockItemList = paymentStockService.getListPaymentStockItemFromPaymentStockId(paymentStock.getId()); List<PaymentStock> payList = new ArrayList<PaymentStock>(); payList.add(paymentStock); request.setAttribute(PAYMENTSTOCKTEMP, payList); List<PaymentStockDetail> psdList = new ArrayList<PaymentStockDetail>(); List<StockDetail> stockDetailList = new ArrayList<StockDetail>(); BigDecimal totalCostAll = new BigDecimal(0); BigDecimal totalSaleAll = new BigDecimal(0); if (paymentStockDetailList != null) { for (int i = 0; i < paymentStockDetailList.size(); i++) { BigDecimal cost = new BigDecimal(BigInteger.ZERO); BigDecimal sale = new BigDecimal(BigInteger.ZERO); PaymentStockDetail pad = paymentStockDetailList.get(i); List<PaymentStockItem> paymentStockItems = new ArrayList<PaymentStockItem>( pad.getPaymentStockItems()); if (paymentStockItems != null) { for (int k = 0; k < paymentStockItems.size(); k++) { PaymentStockItem psi = paymentStockItems.get(k); if (psi.getCost() != null) { cost = cost.add(psi.getCost()); } if (psi.getSale() != null) { sale = sale.add(psi.getSale()); } } } pad.setCost(cost); pad.setSale(sale); totalCostAll = totalCostAll.add(cost); totalSaleAll = totalSaleAll.add(sale); psdList.add(pad); if (pad.getStock() != null) { List<StockDetail> stockDetails = new ArrayList<StockDetail>( pad.getStock().getStockDetails()); if (stockDetails != null) { for (int j = 0; j < stockDetails.size(); j++) { StockDetail sd = new StockDetail(); sd = stockDetails.get(j); stockDetailList.add(sd); } } } } } System.out.println(" totalCostAll :::: " + totalCostAll); System.out.println(" totalSaleAll :::: " + totalSaleAll); paymentStockService.updateTotalCostAndSale(totalCostAll, totalSaleAll, paymentStock.getId()); request.setAttribute("totalCostAll", totalCostAll); request.setAttribute("totalSaleAll", totalSaleAll); request.setAttribute(STOCKDETAILLIST, stockDetailList); request.setAttribute(PAYMENTSTOCKDETAILLIST, psdList); // request.setAttribute(PAYMENTSTOCKDETAILLIST,paymentStockDetailList); // request.setAttribute(PAYMENTSTOCKITEMLIST,paymentStockItemList); request.setAttribute(CREATEDATE, new SimpleDateFormat("yyyy-MM-dd", new Locale("us", "us")) .format(paymentStock.getCreateDate())); request.setAttribute(NOSTOCKTABLE, noStockTable); } setResponseAttribute(request); return PaymentStock; }
From source file:com.aegiswallet.utils.BasicUtils.java
public static BigInteger toNanoCoins(final String value, final int shift) { try {/* ww w . java2s. c om*/ final BigInteger nanoCoins = new BigDecimal(value).movePointRight(8 - shift).toBigIntegerExact(); if (nanoCoins.signum() < 0) throw new IllegalArgumentException("negative amount: " + value); if (nanoCoins.compareTo(NetworkParameters.MAX_MONEY) > 0) Log.e(TAG, "AMOUNT TOO LARGE"); return nanoCoins; } catch (ArithmeticException e) { Log.d(TAG, e.getMessage()); return BigInteger.ZERO; } }
From source file:com.sdcs.courierbooking.service.UserServiceImpl.java
/** * This method sends data to DAO to save details in database * //from w ww .j av a 2 s. c o m * @param sdcsUser * @return Json string for newly created user */ @Override public String registerUser(SdcsUser sdcsUser) { SdcsUser newUser = userDao.registerUser(sdcsUser); JSONObject registrationJsonObject = new JSONObject(); if (newUser == null) { registrationJsonObject.put("result", false); registrationJsonObject.put("message", "Email Id already exists. Please choose different email address and try again!"); } else { registrationJsonObject.put("result", true); registrationJsonObject.put("message", "Welcome to SDCS "); registrationJsonObject.put("user_id", sdcsUser.getUserId()); registrationJsonObject.put("full_name", sdcsUser.getStrFullname()); registrationJsonObject.put("email", sdcsUser.getStrEmail()); registrationJsonObject.put("mobile", sdcsUser.getStrMobile()); String strEmail = sdcsUser.getStrEmail(); String strname = sdcsUser.getStrFullname(); String strMobile = sdcsUser.getStrMobile(); String mailBody = "<b>Dear " + strname + ",</b>" + "<br>" + "<b><i> Thank you for choosing SDCS.</i></b>" + "Thanks" + "<br>" + "SDCS Team" + "<br>" + "info@sdcs.me"; SdcsEmailComponent.sendMail(strEmail, "Welcome To SDCS", mailBody, BigInteger.ZERO); String strSmsText = "%20Welcome%20to%20SDCS%20" + strname + ".%20Thank%20you%20for%20Choosing%20SDCS.%20"; SdcsSMSComponent.sendSms(strMobile, strSmsText); } return registrationJsonObject.toString(); }
From source file:de.jfachwert.math.Bruch.java
/** * Liefert einen gekuerzten Bruch zurueck. So wird z.B. der Bruch "2/4" als * "1/2" zurueckgegeben.//from ww w .ja v a 2 s. c o m * * @return gekuerzter Bruch */ public Bruch kuerzen() { BigInteger z = getZaehler(); BigInteger n = getNenner(); for (Primzahl p = Primzahl.first(); p.toBigInteger().compareTo(n) < 0; p = p.next()) { BigInteger teiler = p.toBigInteger(); while (z.mod(teiler).equals(BigInteger.ZERO) && (n.mod(teiler).equals(BigInteger.ZERO))) { z = z.divide(teiler); n = n.divide(teiler); } } return Bruch.of(z, n); }
From source file:net.bither.rawprivatekey.RawPrivateKeyBinaryFragment.java
private boolean checkValue(byte[] data) { BigInteger value = new BigInteger(1, data); if (value.compareTo(BigInteger.ZERO) == 0 || value.compareTo(ECKey.CURVE.getN()) == 0) { return false; }/*from ww w .j a v a 2s. c o m*/ return true; }
From source file:org.openmrs.module.casereport.DocumentUtil.java
/** * Converts the specified uuid to its decimal representation * /*from www. j a va 2s . com*/ * @param uuid the uuid to convert * @return a string representation of the decimal number */ public static String convertToDecimal(UUID uuid) { ByteBuffer bb = ByteBuffer.wrap(new byte[16]); bb.putLong(uuid.getMostSignificantBits()); bb.putLong(uuid.getLeastSignificantBits()); BigInteger bi = new BigInteger(bb.array()); //Get the unsigned representation for -ve numbers if (bi.compareTo(BigInteger.ZERO) < 0) { bi = DECIMAL_REP_COUNT.add(bi); } return bi.toString(); }
From source file:ga.rugal.jpt.common.tracker.bcodec.BDecoder.java
/** * Returns the next b-encoded value on the stream and makes sure it is a number. * * @return <p>/* w w w. j av a 2 s. c o m*/ * @throws InvalidBEncodingException If it is not a number. */ public BEValue bdecodeNumber() throws IOException { int c = this.getNextIndicator(); if (c != 'i') { throw new InvalidBEncodingException("Expected 'i', not '" + (char) c + "'"); } this.indicator = 0; c = this.read(); if (c == '0') { c = this.read(); if (c == 'e') { return new BEValue(BigInteger.ZERO); } else { throw new InvalidBEncodingException("'e' expected after zero," + " not '" + (char) c + "'"); } } // We don't support more the 255 char big integers char[] chars = new char[256]; int off = 0; if (c == '-') { c = this.read(); if (c == '0') { throw new InvalidBEncodingException("Negative zero not allowed"); } chars[off] = '-'; off++; } if (c < '1' || c > '9') { throw new InvalidBEncodingException("Invalid Integer start '" + (char) c + "'"); } chars[off] = (char) c; off++; c = this.read(); int i = c - '0'; while (i >= 0 && i <= 9) { chars[off] = (char) c; off++; c = read(); i = c - '0'; } if (c != 'e') { throw new InvalidBEncodingException("Integer should end with 'e'"); } String s = new String(chars, 0, off); return new BEValue(new BigInteger(s)); }
From source file:org.apache.poi.hpsf.CustomProperties.java
/** * Adds a named property.//from w w w.java2s . com * * @param key The property's name. * @param value The property's value. * @return the property that was stored under the specified name before, or * {@code null} if there was no such property before. */ @Override public Object put(String key, Object value) { int variantType; if (value instanceof String) { variantType = Variant.VT_LPSTR; } else if (value instanceof Short) { variantType = Variant.VT_I2; } else if (value instanceof Integer) { variantType = Variant.VT_I4; } else if (value instanceof Long) { variantType = Variant.VT_I8; } else if (value instanceof Float) { variantType = Variant.VT_R4; } else if (value instanceof Double) { variantType = Variant.VT_R8; } else if (value instanceof Boolean) { variantType = Variant.VT_BOOL; } else if (value instanceof BigInteger && ((BigInteger) value).bitLength() <= 64 && ((BigInteger) value).compareTo(BigInteger.ZERO) >= 0) { variantType = Variant.VT_UI8; } else if (value instanceof Date) { variantType = Variant.VT_FILETIME; } else { throw new IllegalStateException( "unsupported datatype - currently String,Short,Integer,Long,Float,Double,Boolean,BigInteger(unsigned long),Date can be processed."); } final Property p = new MutableProperty(-1, variantType, value); return put(new CustomProperty(p, key)); }