List of usage examples for java.math RoundingMode HALF_UP
RoundingMode HALF_UP
To view the source code for java.math RoundingMode HALF_UP.
Click Source Link
From source file:org.openlmis.migration.tool.openlmis.requisition.domain.LineItemFieldsCalculator.java
/** * Calculates Adjusted Consumption (N) value and returns it. * The formula is N = RoundUp(C * ((M * 30) / ((M * 30) - X))) * C = Total Consumed Quantity/* w w w .j a v a2 s.c o m*/ * M = Months in the previous period * N = Adjusted Consumption * X = Total Stockout Days * If non-stockout days is zero the formula is N = C */ public static int calculateAdjustedConsumption(RequisitionLineItem lineItem, int monthsInThePeriod) { int consumedQuantity = zeroIfNull(lineItem.getTotalConsumedQuantity()); if (consumedQuantity == 0) { return 0; } int totalDays = 30 * monthsInThePeriod; int stockoutDays = zeroIfNull(lineItem.getTotalStockoutDays()); int nonStockoutDays = totalDays - stockoutDays; if (nonStockoutDays == 0) { return consumedQuantity; } BigDecimal divide = new BigDecimal(totalDays).divide(new BigDecimal(nonStockoutDays), 1000, BigDecimal.ROUND_HALF_UP); // in OpenLMIS Core is RoundingMode.CEILING BigDecimal adjustedConsumption = new BigDecimal(consumedQuantity).multiply(divide).setScale(0, RoundingMode.HALF_UP); return adjustedConsumption.intValue(); }
From source file:com.mark.test.framework.core.service.impl.CreateAccountImpl.java
private IomRequest generateIomRequest(CreateAccDto createAccDto) { String serialno = CommUtils.getRandomNo("sn"); String customerid = CommUtils.getRandomNo("cu"); String cardId = CommUtils.getRandomNo("ca"); String addressId = CommUtils.getRandomNo("ad"); String TelId = CommUtils.getRandomNo("tel"); String ContactId = CommUtils.getRandomNo("ct"); String today = CommUtils.getNowDate(5); IomReqApplicationDomain iomReqApplicationDomain = new IomReqApplicationDomain(); IomCustomerInfoDomain iomCustomerInfoDomain = new IomCustomerInfoDomain(); IomCardInfoDomain iomCardInfoDomain = new IomCardInfoDomain(); IomAddressDomain iomAddressDomain = new IomAddressDomain(); IomTelInfoDomain iomTelInfoDomain = new IomTelInfoDomain(); IomContactInfoDomain iomContactInfoDomain = new IomContactInfoDomain(); iomReqApplicationDomain.setInDate(today); iomReqApplicationDomain.setSerialno(serialno); iomReqApplicationDomain.setCustId(customerid); iomReqApplicationDomain.setTerm((short) createAccDto.getTerm()); iomReqApplicationDomain.setApplDate(today); iomReqApplicationDomain.setContractAmt(new BigDecimal(10000)); iomReqApplicationDomain.setLoanDate(today); iomReqApplicationDomain.setLoanAmt(new BigDecimal(9000)); iomReqApplicationDomain.setPrincipal(new BigDecimal(10000)); iomReqApplicationDomain.setFee01(new BigDecimal(1000)); iomReqApplicationDomain.setFee02(new BigDecimal(0)); iomReqApplicationDomain.setFee03(new BigDecimal(0)); iomReqApplicationDomain.setGpsFee(new BigDecimal(0)); iomReqApplicationDomain.setAssessFee(new BigDecimal(0)); iomReqApplicationDomain.setViolateDeposit(new BigDecimal(0)); iomReqApplicationDomain.setConsultFee(new BigDecimal(0)); iomReqApplicationDomain.setDeposits(new BigDecimal(0)); iomReqApplicationDomain.setLoanPenalty(new BigDecimal(0)); iomReqApplicationDomain.setOtFee01(new BigDecimal(0)); iomReqApplicationDomain.setOtFee02(new BigDecimal(0)); iomReqApplicationDomain.setOtFee03(new BigDecimal(0)); iomReqApplicationDomain.setOtFee04(new BigDecimal(0)); iomReqApplicationDomain.setOtFee05(new BigDecimal(0)); iomReqApplicationDomain.setIntRate(new BigDecimal(9)); iomReqApplicationDomain.setPenaltyIntRate(new BigDecimal(0.15).setScale(2, RoundingMode.HALF_UP)); iomReqApplicationDomain.setGraceDays((short) 1); iomReqApplicationDomain.setMaxPutoutDays("3"); iomReqApplicationDomain.setRepayMethod("RPT000010"); iomReqApplicationDomain.setMethodFlag("0"); iomReqApplicationDomain.setBusinessType("A0007"); // ? FK011 FK012 iomReqApplicationDomain.setProductName(""); iomReqApplicationDomain.setPayLoanBrh(createAccDto.getPayLoanBrh()); iomReqApplicationDomain.setBusinessResource("1"); iomReqApplicationDomain.setInputOrgId("2015072200000003"); iomReqApplicationDomain.setProcFlg("0"); iomReqApplicationDomain.setInputOrgName(""); iomReqApplicationDomain.setContractOrgId("2015072200000003"); iomReqApplicationDomain.setContractOrgName(""); iomReqApplicationDomain.setOwnerOrgId("2015072200000003"); iomReqApplicationDomain.setOwnerOrgName(""); iomReqApplicationDomain.setPlatDamagesFee((Map) new HashMap().put("1", "1.5")); iomReqApplicationDomain.setInvestorDamagesFee((Map) new HashMap().put("1", "1.5")); iomReqApplicationDomain.setOtherFeesList((Map) new HashMap().put("businessRiskSum", ".00")); businessapplyList.add(iomReqApplicationDomain); iomCustomerInfoDomain.setInDate(today); iomCustomerInfoDomain.setCustId(customerid); iomCustomerInfoDomain.setName(""); iomCustomerInfoDomain.setIdType("01"); iomCustomerInfoDomain.setIdNum("51152619911214091X"); iomCustomerInfoDomain.setSex("1"); iomCustomerInfoDomain.setBirthday("1988/02/02"); iomCustomerInfoDomain.setMarried("20"); iomCustomerInfoDomain.setEdLevel("3"); iomCustomerInfoDomain.setCaCompany(""); iomCustomerInfoDomain.setCaType("40"); iomCustomerInfoDomain.setCaIndustryType("G"); iomCustomerInfoDomain.setCaDepartment(""); iomCustomerInfoDomain.setCaDuty(""); iomCustomerInfoDomain.setCaOfficialRank("10"); iomCustomerInfoDomain.setCaEnterTime("1991/09/12"); iomCustomerInfoDomain.setCaPayType("PT0002"); iomCustomerInfoDomain.setCaPayDay("15"); iomCustomerInfoDomain.setCaWage(new BigDecimal(30000)); iomCustomerInfoDomain.setCompType("40"); iomCustomerInfoDomain.setCompTimeFounded("2009/05/25"); iomCustomerInfoDomain.setCompShareholdingRatio("100"); iomCustomerInfoDomain.setCompPremisesType("???"); iomCustomerInfoDomain.setCompEmployeeAmount(Integer.getInteger("20")); iomCustomerInfoDomain.setCompProfits(new BigDecimal("800000")); iomCustomerInfoDomain.setCarPrice(new BigDecimal("203800")); iomCustomerInfoDomain.setCarLicense("Q39815"); iomCustomerInfoDomain.setHouseType("LS0004"); iomCustomerInfoDomain.setHouseAddress("beijing"); iomCustomerInfoDomain.setHouseHasLoan("1"); iomCustomerInfoDomain.setHouseBuildingArea(new BigDecimal("86")); iomCustomerInfoDomain.setHouseBuyTime("2008/08/01"); iomCustomerInfoDomain.setHousePrice(new BigDecimal("50")); iomCustomerInfoDomain.setMemo("?"); customerList.add(iomCustomerInfoDomain); iomCardInfoDomain.setInDate(today);/*from w w w .j a va2s. c om*/ iomCardInfoDomain.setCustId(customerid); iomCardInfoDomain.setCardId(cardId); iomCardInfoDomain.setCardNo("622908553566782415"); iomCardInfoDomain.setAliasCode("3091000"); iomCardInfoDomain.setAgmtType(Integer.valueOf("1")); iomCardInfoDomain.setTreatyNo("20160729558882"); iomCardInfoDomain.setAgmtStartDate("20170501"); iomCardInfoDomain.setAgmtEndDate("20180501"); iomCardInfoDomain.setPayLoanBrh("0"); bankcardList.add(iomCardInfoDomain); iomAddressDomain.setInDate(today); iomAddressDomain.setCustId(customerid); iomAddressDomain.setAddressId(addressId); iomAddressDomain.setObjectType(""); iomAddressDomain.setAddressType("02"); iomAddressDomain.setAddress(""); iomAddressDomain.setValid("0"); addressDomainList.add(iomAddressDomain); iomTelInfoDomain.setInDate(today); iomTelInfoDomain.setTelId(TelId); iomTelInfoDomain.setObjectType("?"); iomTelInfoDomain.setObjectId(customerid); iomTelInfoDomain.setTelType("01"); iomTelInfoDomain.setTel("18604722914"); telephoneList.add(iomTelInfoDomain); iomContactInfoDomain.setInDate(today); iomContactInfoDomain.setCustId(customerid); iomContactInfoDomain.setContactId(ContactId); iomContactInfoDomain.setRelation("0503"); iomContactInfoDomain.setName("1"); contractList.add(iomContactInfoDomain); List<IomRepayPlanDomain> repayplanList = this.genRepayPlanList(serialno, today); IomRequest iomRequest = new IomRequest(); iomRequest.setAddress(addressDomainList); iomRequest.setBusinessapply(businessapplyList); iomRequest.setCustomer(customerList); iomRequest.setBankcard(bankcardList); iomRequest.setTelephone(telephoneList); iomRequest.setRepayplan(repayplanList); iomRequest.setContract(contractList); return iomRequest; }
From source file:org.fede.util.Util.java
private static BigDecimal avg(List<BigDecimal> list) { if (list.isEmpty()) { return BigDecimal.ZERO; }//from w w w.j av a 2s.c o m return list.stream().reduce(BigDecimal.ZERO, (left, right) -> left.add(right)) .setScale(7, RoundingMode.HALF_UP).divide(new BigDecimal(list.size()), MathContext.DECIMAL32); }
From source file:com.cmsz.cloudplatform.utils.StringUtils.java
public static String convertBytes(String bytes) { if (StringUtil.isNullString(bytes)) { return null; }// w w w . j a va 2 s.c o m // NumberFormat format = new DecimalFormat("##0.00"); BigDecimal _1024 = new BigDecimal(1024); BigDecimal value = new BigDecimal(bytes); if (value.compareTo(_1024) == -1) { return value.divide(new BigDecimal(1), 2, RoundingMode.HALF_UP) + " KB"; } else if (value.compareTo(_1024.multiply(_1024)) == -1) { return value.divide(_1024, 2, RoundingMode.HALF_UP) + " MB"; } else if (value.compareTo(_1024.multiply(_1024).multiply(_1024)) == -1) { return value.divide(_1024).divide(_1024, 2, RoundingMode.HALF_UP) + " GB"; } else { return value.divide(_1024).divide(_1024).divide(_1024, 2, RoundingMode.HALF_UP) + " TB"; } }
From source file:org.mot.common.math.CalculatorFactory.java
/** * @param value -- double value to round * @param places -- decimal places to round to * @return - Double value//from w w w . j av a 2s . co m */ public Double round(double value, int places) { if (places < 0) throw new IllegalArgumentException(); BigDecimal bd = new BigDecimal(value); bd = bd.setScale(places, RoundingMode.HALF_UP); return bd.doubleValue(); }
From source file:org.yes.cart.payment.impl.PayPalProPaymentGatewayImpl.java
private NvpBuilder createAuthRequest(final Payment payment, final String paymentAction) { final NvpBuilder npvs = new NvpBuilder(); npvs.addRaw("PAYMENTACTION", paymentAction); npvs.addRaw("INVNUM", payment.getOrderShipment()); npvs.addRaw("CREDITCARDTYPE", payment.getCardType()); npvs.addRaw("ACCT", payment.getCardNumber()); npvs.addRaw("EXPDATE", payment.getCardExpireMonth() + payment.getCardExpireYear()); npvs.addRaw("CVV2", payment.getCardCvv2Code()); npvs.addRaw("AMT", payment.getPaymentAmount().setScale(2, RoundingMode.HALF_UP).toString()); npvs.addRaw("CURRENCYCODE", payment.getOrderCurrency()); int i = 0;/*from ww w.j ava2 s . c o m*/ BigDecimal itemsNetTotal = Total.ZERO; BigDecimal ship = Total.ZERO; for (final PaymentLine item : payment.getOrderItems()) { if (item.isShipment()) { ship = item.getUnitPrice(); } else { final BigDecimal intQty = item.getQuantity().setScale(0, RoundingMode.CEILING); final String skuName; final BigDecimal qty; if (MoneyUtils.isFirstEqualToSecond(intQty, item.getQuantity())) { // integer qty skuName = item.getSkuName(); qty = intQty.stripTrailingZeros(); } else { // fractional qty skuName = item.getQuantity().toPlainString().concat("x ").concat(item.getSkuName()); qty = BigDecimal.ONE; } npvs.addEncoded("L_NUMBER" + i, item.getSkuCode().length() > ITEMSKU ? item.getSkuCode().substring(0, ITEMSKU - 1) + "~" : item.getSkuCode()); npvs.addEncoded("L_NAME" + i, skuName.length() > ITEMNAME ? skuName.substring(0, ITEMNAME - 1) + "~" : skuName); npvs.addRaw("L_QTY" + i, qty.stripTrailingZeros().toPlainString()); final BigDecimal itemNetAmount = item.getUnitPrice().multiply(item.getQuantity()) .subtract(item.getTaxAmount()).setScale(Total.ZERO.scale(), RoundingMode.HALF_UP); final BigDecimal itemNetPricePerAdjustedQty = itemNetAmount.divide(qty, Total.ZERO.scale(), BigDecimal.ROUND_HALF_UP); // Need to do this to overcome rounding final BigDecimal restoredNetAmount = itemNetPricePerAdjustedQty.multiply(qty) .setScale(Total.ZERO.scale(), BigDecimal.ROUND_HALF_UP); itemsNetTotal = itemsNetTotal.add(restoredNetAmount); // final BigDecimal taxUnit = MoneyUtils.isFirstBiggerThanSecond(item.getTaxAmount(), Total.ZERO) ? item.getTaxAmount().divide(qty, Total.ZERO.scale(), BigDecimal.ROUND_HALF_UP) : Total.ZERO; npvs.addRaw("L_AMT" + i, itemNetPricePerAdjustedQty.toPlainString()); // npvs.addRaw("L_TAXAMT" + i, taxUnit.toPlainString()); i++; } } final BigDecimal itemsAndShipping = itemsNetTotal.add(ship); final BigDecimal paymentNet = payment.getPaymentAmount().subtract(payment.getTaxAmount()); if (MoneyUtils.isFirstBiggerThanSecond(itemsAndShipping, paymentNet)) { npvs.addRaw("SHIPDISCAMT", paymentNet.subtract(itemsAndShipping).toPlainString()); } npvs.addRaw("ITEMAMT", itemsNetTotal.toPlainString()); npvs.addRaw("SHIPPINGAMT", ship.toPlainString()); npvs.addRaw("TAXAMT", payment.getTaxAmount().toPlainString()); if (payment.getBillingAddress() != null) { npvs.addEncoded("EMAIL", payment.getBillingEmail()); npvs.addEncoded("FIRSTNAME", payment.getBillingAddress().getFirstname()); npvs.addEncoded("LASTNAME", payment.getBillingAddress().getLastname()); npvs.addEncoded("STREET", payment.getBillingAddress().getAddrline1()); if (StringUtils.isNotBlank(payment.getBillingAddress().getAddrline2())) { npvs.addEncoded("STREET2", payment.getBillingAddress().getAddrline2()); } npvs.addEncoded("CITY", payment.getBillingAddress().getCity()); npvs.addEncoded("STATE", payment.getBillingAddress().getStateCode()); npvs.addEncoded("ZIP", payment.getBillingAddress().getStateCode()); npvs.addEncoded("COUNTRYCODE", payment.getBillingAddress().getCountryCode()); } if (payment.getShippingAddress() != null) { npvs.addEncoded("SHIPTONAME", payment.getShippingAddress().getFirstname() + " " + payment.getShippingAddress().getLastname()); npvs.addEncoded("SHIPTOSTREET", payment.getShippingAddress().getAddrline1()); if (StringUtils.isNotBlank(payment.getShippingAddress().getAddrline2())) { npvs.addEncoded("SHIPTOSTREET2", payment.getShippingAddress().getAddrline2()); } npvs.addEncoded("SHIPTOCITY", payment.getShippingAddress().getCity()); npvs.addEncoded("SHIPTOSTATE", payment.getShippingAddress().getStateCode()); npvs.addEncoded("SHIPTOZIP", payment.getShippingAddress().getStateCode()); npvs.addEncoded("SHIPTOCOUNTRY", payment.getShippingAddress().getCountryCode()); } return npvs; }
From source file:com.thousandthoughts.tutorials.SensorFusionActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main);/* ww w . j a v a 2 s . c o m*/ layout = (RelativeLayout) findViewById(R.id.mainlayout); IP1 = ""; IP2 = ""; angle1 = 0.0f; angle2 = 0.0f; gyroOrientation[0] = 0.0f; gyroOrientation[1] = 0.0f; gyroOrientation[2] = 0.0f; // initialise gyroMatrix with identity matrix gyroMatrix[0] = 1.0f; gyroMatrix[1] = 0.0f; gyroMatrix[2] = 0.0f; gyroMatrix[3] = 0.0f; gyroMatrix[4] = 1.0f; gyroMatrix[5] = 0.0f; gyroMatrix[6] = 0.0f; gyroMatrix[7] = 0.0f; gyroMatrix[8] = 1.0f; // get sensorManager and initialise sensor listeners mSensorManager = (SensorManager) this.getSystemService(SENSOR_SERVICE); initListeners(); // wait for one second until gyroscope and magnetometer/accelerometer // data is initialised then scedule the complementary filter task fuseTimer.scheduleAtFixedRate(new calculateFusedOrientationTask(), 1000, TIME_CONSTANT); // GUI stuff try { client1 = new MyCoapClient(this.IP1); client2 = new MyCoapClient(this.IP2); } catch (UnknownHostException e) { // TODO Auto-generated catch block e.printStackTrace(); } json = new JSONObject(); mHandler = new Handler(); radioSelection = 0; d.setRoundingMode(RoundingMode.HALF_UP); d.setMaximumFractionDigits(3); d.setMinimumFractionDigits(3); /// Application layout here only RelativeLayout.LayoutParams left = new RelativeLayout.LayoutParams( android.view.ViewGroup.LayoutParams.WRAP_CONTENT, android.view.ViewGroup.LayoutParams.WRAP_CONTENT); RelativeLayout.LayoutParams right = new RelativeLayout.LayoutParams( android.view.ViewGroup.LayoutParams.WRAP_CONTENT, android.view.ViewGroup.LayoutParams.WRAP_CONTENT); RelativeLayout.LayoutParams up = new RelativeLayout.LayoutParams( android.view.ViewGroup.LayoutParams.WRAP_CONTENT, android.view.ViewGroup.LayoutParams.WRAP_CONTENT); RelativeLayout.LayoutParams down = new RelativeLayout.LayoutParams( android.view.ViewGroup.LayoutParams.WRAP_CONTENT, android.view.ViewGroup.LayoutParams.WRAP_CONTENT); RelativeLayout.LayoutParams button1 = new RelativeLayout.LayoutParams( android.view.ViewGroup.LayoutParams.WRAP_CONTENT, android.view.ViewGroup.LayoutParams.WRAP_CONTENT); RelativeLayout.LayoutParams button2 = new RelativeLayout.LayoutParams( android.view.ViewGroup.LayoutParams.WRAP_CONTENT, android.view.ViewGroup.LayoutParams.WRAP_CONTENT); RelativeLayout.LayoutParams text1 = new RelativeLayout.LayoutParams( android.view.ViewGroup.LayoutParams.WRAP_CONTENT, android.view.ViewGroup.LayoutParams.WRAP_CONTENT); RelativeLayout.LayoutParams text2 = new RelativeLayout.LayoutParams( android.view.ViewGroup.LayoutParams.WRAP_CONTENT, android.view.ViewGroup.LayoutParams.WRAP_CONTENT); ImageView img_left = new ImageView(this); ImageView img_right = new ImageView(this); ImageView img_up = new ImageView(this); ImageView img_down = new ImageView(this); ImageView img_button1 = new ImageView(this); ImageView img_button2 = new ImageView(this); final EditText edittext1 = new EditText(this); final EditText edittext2 = new EditText(this); img_left.setImageResource(R.drawable.left_button); img_right.setImageResource(R.drawable.right_button); img_up.setImageResource(R.drawable.up); img_down.setImageResource(R.drawable.down); img_button1.setImageResource(R.drawable.button); img_button2.setImageResource(R.drawable.button); left.setMargins(0, 66, 0, 0); right.setMargins(360, 66, 0, 0); up.setMargins(240, 90, 0, 0); down.setMargins(240, 240, 0, 0); button1.setMargins(440, 800, 0, 0); button2.setMargins(440, 900, 0, 0); text1.setMargins(5, 800, 0, 0); text2.setMargins(5, 900, 0, 0); layout.addView(img_left, left); layout.addView(img_right, right); layout.addView(img_up, up); layout.addView(img_down, down); layout.addView(img_button1, button1); layout.addView(edittext1, text1); layout.addView(img_button2, button2); layout.addView(edittext2, text2); img_left.getLayoutParams().height = 560; img_left.getLayoutParams().width = 280; img_right.getLayoutParams().height = 560; img_right.getLayoutParams().width = 280; img_up.getLayoutParams().height = 150; img_up.getLayoutParams().width = 150; img_down.getLayoutParams().height = 150; img_down.getLayoutParams().width = 150; img_button1.getLayoutParams().height = 100; img_button1.getLayoutParams().width = 200; edittext1.getLayoutParams().width = 400; edittext1.setText("84.248.76.84"); edittext2.setText("84.248.76.84"); img_button2.getLayoutParams().height = 100; img_button2.getLayoutParams().width = 200; edittext2.getLayoutParams().width = 400; /////////// Define and Remember Position for EACH PHYSICAL OBJECTS (LAPTOPS) ///////////////////// img_button1.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View view, MotionEvent event) { // TODO Auto-generated method stub switch (event.getAction()) { case MotionEvent.ACTION_DOWN: // POSITION OF LAPTOP 1 IS REMEMBERED angle1 = fusedOrientation[0]; IP1 = edittext1.getText().toString(); try { // CREATE CLIENT CONNECT TO FIRST LAPTOP client1 = new MyCoapClient(IP1); } catch (UnknownHostException e) { // TODO Auto-generated catch block e.printStackTrace(); } break; case MotionEvent.ACTION_MOVE: break; case MotionEvent.ACTION_UP: //view.setImageResource(R.drawable.left_button); break; } return true; } }); img_button2.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View view, MotionEvent event) { // TODO Auto-generated method stub switch (event.getAction()) { case MotionEvent.ACTION_DOWN: // POSITION OF LAPTOP 2 IS REMEMBERED angle2 = fusedOrientation[0]; IP2 = edittext2.getText().toString(); try { // CREATE CLIENT CONNECT TO SECOND LAPTOP client2 = new MyCoapClient(IP2); } catch (UnknownHostException e) { // TODO Auto-generated catch block e.printStackTrace(); } break; case MotionEvent.ACTION_MOVE: break; case MotionEvent.ACTION_UP: break; } return true; } }); img_left.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { ImageView view = (ImageView) v; switch (event.getAction()) { case MotionEvent.ACTION_DOWN: view.setImageResource(R.drawable.left_button_press); ///////////////////// PERFORM CLICK ACTION BASED ON POSITION OF 2 PHYSICAL OBJECTS (LAPTOPs) HERE///////////////////////// // PHONE's ANGLE WITHIN FIRST LAPTOP// if (angle1 != 0.0f) { if (angle1 * 180 / Math.PI - 40.0 < fusedOrientation[0] * 180 / Math.PI && fusedOrientation[0] * 180 / Math.PI < angle1 * 180 / Math.PI + 40.0) { client1.runClient("left pressed"); } } //PHONE's ANGLE WITHIN SECOND LAPTOP// if (angle2 != 0.0f) { if (angle2 * 180 / Math.PI - 40.0 < fusedOrientation[0] * 180 / Math.PI && fusedOrientation[0] * 180 / Math.PI < angle2 * 180 / Math.PI + 40.0) { client2.runClient("left pressed"); } } break; case MotionEvent.ACTION_MOVE: break; case MotionEvent.ACTION_UP: view.setImageResource(R.drawable.left_button); // PHONE's ANGLE WITHIN FIRST LAPTOP// if (angle1 != 0.0f) { if (angle1 * 180 / Math.PI - 40.0f < fusedOrientation[0] * 180 / Math.PI && fusedOrientation[0] * 180 / Math.PI < angle1 * 180 / Math.PI + 40.0f) { client1.runClient("left released"); } } //PHONE's ANGLE WITHIN SECOND LAPTOP// if (angle2 != 0.0f) { if (angle2 * 180 / Math.PI - 40.0f < fusedOrientation[0] * 180 / Math.PI && fusedOrientation[0] * 180 / Math.PI < angle2 * 180 / Math.PI + 40.0f) { client2.runClient("left released"); } } break; } return true; } }); img_right.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { ImageView view = (ImageView) v; switch (event.getAction()) { case MotionEvent.ACTION_DOWN: view.setImageResource(R.drawable.right_button_press); // PHONE's ANGLE WITHIN FIRST LAPTOP// if (angle1 != 0.0f) { if (angle1 * 180 / Math.PI - 40.0f < fusedOrientation[0] * 180 / Math.PI && fusedOrientation[0] * 180 / Math.PI < angle1 * 180 / Math.PI + 40.0f) { client1.runClient("right pressed"); } } //PHONE's ANGLE WITHIN SECOND LAPTOP// if (angle2 != 0.0f) { if (angle2 * 180 / Math.PI - 40.0f < fusedOrientation[0] * 180 / Math.PI && fusedOrientation[0] * 180 / Math.PI < angle2 * 180 / Math.PI + 40.0f) { client2.runClient("right pressed"); } } break; case MotionEvent.ACTION_MOVE: break; case MotionEvent.ACTION_UP: view.setImageResource(R.drawable.right_button); break; } return true; } }); img_up.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { ImageView view = (ImageView) v; switch (event.getAction()) { case MotionEvent.ACTION_DOWN: view.setImageResource(R.drawable.up_press); // PHONE's ANGLE WITHIN FIRST LAPTOP// if (angle1 != 0.0f) { if (angle1 * 180 / Math.PI - 40.0f < fusedOrientation[0] * 180 / Math.PI && fusedOrientation[0] * 180 / Math.PI < angle1 * 180 / Math.PI + 40.0f) { client1.runClient("up pressed"); } } //PHONE's ANGLE WITHIN SECOND LAPTOP// if (angle2 != 0.0f) { if (angle2 * 180 / Math.PI - 40.0f < fusedOrientation[0] * 180 / Math.PI && fusedOrientation[0] * 180 / Math.PI < angle2 * 180 / Math.PI + 40.0f) { client2.runClient("up pressed"); } } break; case MotionEvent.ACTION_MOVE: break; case MotionEvent.ACTION_UP: view.setImageResource(R.drawable.up); break; } return true; } }); img_down.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { ImageView view = (ImageView) v; switch (event.getAction()) { case MotionEvent.ACTION_DOWN: view.setImageResource(R.drawable.down_press); // PHONE's ANGLE WITHIN FIRST LAPTOP// if (angle1 != 0.0f) { if (angle1 * 180 / Math.PI - 40.0f < fusedOrientation[0] * 180 / Math.PI && fusedOrientation[0] * 180 / Math.PI < angle1 * 180 / Math.PI + 40.0f) { client1.runClient("down pressed"); } } //PHONE's ANGLE WITHIN SECOND LAPTOP// if (angle2 != 0.0f) { if (angle2 * 180 / Math.PI - 40.0f < fusedOrientation[0] * 180 / Math.PI && fusedOrientation[0] * 180 / Math.PI < angle2 * 180 / Math.PI + 40.0f) { client2.runClient("down pressed"); } } break; case MotionEvent.ACTION_MOVE: break; case MotionEvent.ACTION_UP: view.setImageResource(R.drawable.down); break; } return true; } }); }
From source file:org.yes.cart.shoppingcart.impl.DefaultAmountCalculationStrategy.java
Total applyOrderLevelPromotions(final Customer customer, final MutableShoppingCart cart, final Total itemTotal, final PromotionContext promoCtx) { final Total tmp = promoCtx.applyOrderPromo(customer, cart, itemTotal); final BigDecimal orderLevelDiscountRatio = MoneyUtils.isFirstBiggerThanSecond(itemTotal.getSubTotal(), BigDecimal.ZERO) ? tmp.getSubTotal().divide(itemTotal.getSubTotal(), 16, RoundingMode.HALF_UP) : Total.ZERO;//from www . ja v a2 s .c o m final BigDecimal subTotal = tmp.getSubTotal(); final BigDecimal subTotalTax = multiply(itemTotal.getSubTotalTax(), orderLevelDiscountRatio); final BigDecimal subTotalAmount = MoneyUtils.isFirstBiggerThanSecond(itemTotal.getSubTotalAmount(), itemTotal.getSubTotal()) ? subTotal.add(subTotalTax) : subTotal; final BigDecimal total = subTotal.add(tmp.getDeliveryCost()); final BigDecimal totalTax = subTotalTax.add(tmp.getDeliveryTax()); final BigDecimal totalAmount = subTotalAmount.add(tmp.getDeliveryCostAmount()); final BigDecimal listTotalAmount = itemTotal.getListTotalAmount(); // list does not change return new TotalImpl(tmp.getListSubTotal(), tmp.getSaleSubTotal(), tmp.getNonSaleSubTotal(), tmp.getPriceSubTotal(), tmp.isOrderPromoApplied(), tmp.getAppliedOrderPromo(), subTotal, subTotalTax, subTotalAmount, tmp.getDeliveryListCost(), tmp.getDeliveryCost(), tmp.isDeliveryPromoApplied(), tmp.getAppliedDeliveryPromo(), tmp.getDeliveryTax(), tmp.getDeliveryCostAmount(), total, totalTax, listTotalAmount, totalAmount); }
From source file:piuk.blockchain.android.ui.AmountCalculatorFragment.java
private void done() { final BigInteger amount = exchangeDirection ? btcAmountView.getAmount() : new BigDecimal(localAmountView.getAmount()) .divide(new BigDecimal(exchangeRate), RoundingMode.HALF_UP).toBigInteger(); listener.use(amount);// w w w. j a va 2 s.c om dismiss(); }
From source file:org.yes.cart.payment.impl.PayPalNvpPaymentGatewayImpl.java
/** * {@inheritDoc}//from ww w . j a v a 2s . c om */ public Payment capture(final Payment paymentIn) { final Payment payment = (Payment) SerializationUtils.clone(paymentIn); payment.setTransactionOperation(CAPTURE); final NVPEncoder encoder = new NVPEncoder(); encoder.add("METHOD", "DoCapture"); encoder.add("TRXTYPE", "D"); encoder.add("AUTHORIZATIONID", payment.getTransactionAuthorizationCode()); encoder.add("AMT", payment.getPaymentAmount().setScale(2, RoundingMode.HALF_UP).toString()); encoder.add("COMPLETETYPE", "NotComplete"); encoder.add("CURRENCYCODE", payment.getOrderCurrency()); return runTransaction(encoder, payment, CAPTURE); }