List of usage examples for java.lang Short valueOf
@HotSpotIntrinsicCandidate public static Short valueOf(short s)
From source file:org.mifos.accounts.productsmix.struts.action.ProductMixAction.java
@TransactionDemarcate(validateAndResetToken = true) @CloseSession//w ww .jav a 2 s.c om public ActionForward create(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { ProductMixActionForm prdMixActionForm = (ProductMixActionForm) form; PrdOfferingBO prdOfferingBO = getPrdMixBusinessService() .getPrdOfferingByID(Short.valueOf(prdMixActionForm.getProductInstance())); prdOfferingBO.updatePrdOfferingFlag(); List<PrdOfferingBO> notAllowedProductList = (List<PrdOfferingBO>) SessionUtils .getAttribute(ProductDefinitionConstants.NOTALLOWEDPRODUCTLIST, request); PrdOfferingBO productOff = getPrdMixBusinessService() .getPrdOfferingByID(Short.valueOf(prdMixActionForm.getProductInstance())); productOff.setUserContext(getUserContext(request)); List<PrdOfferingBO> oldNotAllowedProductList = (List<PrdOfferingBO>) SessionUtils .getAttribute(ProductDefinitionConstants.OLDNOTALLOWEDPRODUCTLIST, request); if (null != oldNotAllowedProductList && oldNotAllowedProductList.size() != 0) { for (PrdOfferingBO oldnotallowedProduct : oldNotAllowedProductList) { ProductMixBO product = getPrdMixBusinessService().getPrdOfferingMixByPrdOfferingID( productOff.getPrdOfferingId(), oldnotallowedProduct.getPrdOfferingId()); if (null != product) { product.delete(); } ProductMixBO productmix = getPrdMixBusinessService().getPrdOfferingMixByPrdOfferingID( oldnotallowedProduct.getPrdOfferingId(), productOff.getPrdOfferingId()); if (null != productmix) { productmix.delete(); } } } if (null != notAllowedProductList) { for (PrdOfferingBO notallowedProduct : notAllowedProductList) { ProductMixBO product = new ProductMixBO(productOff, notallowedProduct); product.setUserContext(getUserContext(request)); product.update(); } } request.setAttribute(ProductDefinitionConstants.PRDOFFERINGBO, prdOfferingBO); prdOfferingBO = null; return mapping.findForward(ActionForwards.create_success.toString()); }
From source file:ch.entwine.weblounge.common.impl.request.RequestUtils.java
/** * Checks if a parameter is present in the url at position * <code>parameter</code> and represents a valid <code>short</code>. In that * case, the parameter is returned as a <code>short</code>, otherwise * <code>0</code> is returned. * <p>/*w w w . j a va 2 s . com*/ * If the parameter is required, and it is not part of the url, then an * {@link IllegalStateException} is thrown. * * @param request * the weblounge request * @param action * the action that determines the mountpoint * @param index * the index of the parameter in the url * @param required * <code>true</code> if this parameter is mandatory * @return the parameter value or <code>0</code> if the parameter is not * available * @throws IllegalArgumentException * if the parameter value cannot be cast to a <code>short</code> * @throws IllegalStateException * if the parameter was not found in the request */ private static short getShortParameter(WebloungeRequest request, Action action, int index, boolean required) throws IllegalArgumentException, IllegalStateException { String p = null; if (required) p = getRequiredParameter(request, action, index); else p = getParameter(request, action, index); if (p == null) return 0; try { return Short.valueOf(p); } catch (NumberFormatException e) { throw new IllegalArgumentException("Url parameter at index " + index + " must be a short"); } }
From source file:edu.ku.brc.af.ui.forms.validation.ValFormattedTextFieldSingle.java
/** * @param value/* w w w .j a v a2 s .c o m*/ * @return */ protected UIValidatable.ErrorType validateNumeric(final String value) { Class<?> cls = formatter.getDataClass(); try { if (cls == BigDecimal.class) { if (bdValidator == null) { bdValidator = CurrencyValidator.getInstance(); } Number maxVal = formatter.getMaxValue(); Number minVal = formatter.getMinValue(); BigDecimal fooAmount = bdValidator.validate(value, Locale.getDefault()); // XXX FINAL RELEASE if (fooAmount == null) { // error...not a valid currency amount return UIValidatable.ErrorType.Error; } if (!bdValidator.minValue(fooAmount, minVal) || !bdValidator.maxValue(fooAmount, maxVal)) { // valid...in the specified range return UIValidatable.ErrorType.Error; } return UIValidatable.ErrorType.Valid; } else { try { if (cls == Long.class) { Number num = numIntFormatter.parse(value); Long val = Long.valueOf(num.toString()); return !isMinMaxOK(val) ? UIValidatable.ErrorType.Error : UIValidatable.ErrorType.Valid; } else if (cls == Integer.class) { Number num = numIntFormatter.parse(value); Integer val = Integer.valueOf(num.toString()); return !isMinMaxOK(val) ? UIValidatable.ErrorType.Error : UIValidatable.ErrorType.Valid; } else if (cls == Short.class) { Number num = numIntFormatter.parse(value); Short val = Short.valueOf(num.toString()); return !isMinMaxOK(val) ? UIValidatable.ErrorType.Error : UIValidatable.ErrorType.Valid; } else if (cls == Byte.class) { Number num = numIntFormatter.parse(value); Byte val = Byte.valueOf(num.toString()); return !isMinMaxOK(val) ? UIValidatable.ErrorType.Error : UIValidatable.ErrorType.Valid; } else if (cls == Double.class) { Number num = numberFormatter.parse(value); Double val = Double.valueOf(num.toString()); return !isMinMaxOK(val) ? UIValidatable.ErrorType.Error : UIValidatable.ErrorType.Valid; } else if (cls == Float.class) { Number num = numberFormatter.parse(value); Float val = Float.valueOf(num.toString()); return !isMinMaxOK(val) ? UIValidatable.ErrorType.Error : UIValidatable.ErrorType.Valid; } else { throw new RuntimeException("Missing case for numeric class [" + cls.getName() + "]"); } } catch (NumberFormatException fex) { return UIValidatable.ErrorType.Error; } } } catch (Exception ex) { } return UIValidatable.ErrorType.Error; }
From source file:org.mifos.accounts.loan.business.LoanBORedoDisbursalIntegrationTest.java
@Ignore @Test// ww w .jav a 2 s. co m public void testRedoLoanApplyFractionalMiscFeeAfterPartialPayment() throws Exception { try { LoanBO loan = redoLoanWithMondayMeetingAndVerify(userContext, 14, new ArrayList<AccountFeesEntity>()); disburseLoanAndVerify(userContext, loan, 14); LoanTestUtils.assertInstallmentDetails(loan, 1, 50.9, 0.1, 0.0, 0.0, 0.0); LoanTestUtils.assertInstallmentDetails(loan, 2, 50.9, 0.1, 0.0, 0.0, 0.0); LoanTestUtils.assertInstallmentDetails(loan, 3, 50.9, 0.1, 0.0, 0.0, 0.0); LoanTestUtils.assertInstallmentDetails(loan, 4, 50.9, 0.1, 0.0, 0.0, 0.0); LoanTestUtils.assertInstallmentDetails(loan, 5, 50.9, 0.1, 0.0, 0.0, 0.0); LoanTestUtils.assertInstallmentDetails(loan, 6, 45.5, 0.5, 0.0, 0.0, 0.0); applyAndVerifyPayment(userContext, loan, 7, new Money(getCurrency(), "50")); LoanTestUtils.assertInstallmentDetails(loan, 1, 1.0, 0.0, 0.0, 0.0, 0.0); LoanTestUtils.assertInstallmentDetails(loan, 2, 50.9, 0.1, 0.0, 0.0, 0.0); LoanTestUtils.assertInstallmentDetails(loan, 3, 50.9, 0.1, 0.0, 0.0, 0.0); LoanTestUtils.assertInstallmentDetails(loan, 4, 50.9, 0.1, 0.0, 0.0, 0.0); LoanTestUtils.assertInstallmentDetails(loan, 5, 50.9, 0.1, 0.0, 0.0, 0.0); LoanTestUtils.assertInstallmentDetails(loan, 6, 45.5, 0.5, 0.0, 0.0, 0.0); Assert.assertFalse(MoneyUtils.isRoundedAmount(33.7)); Assert.assertFalse(loan.canApplyMiscCharge(new Money(getCurrency(), new BigDecimal(33.7)))); // Should throw AccountExcption applyCharge(loan, Short.valueOf(AccountConstants.MISC_FEES), new Double("33.7")); LoanTestUtils.assertInstallmentDetails(loan, 1, 1.0, 0.0, 0.0, 0.0, 0.0); LoanTestUtils.assertInstallmentDetails(loan, 2, 51.2, 0.1, 0.0, 33.7, 0.0); LoanTestUtils.assertInstallmentDetails(loan, 3, 50.9, 0.1, 0.0, 0.0, 0.0); LoanTestUtils.assertInstallmentDetails(loan, 4, 50.9, 0.1, 0.0, 0.0, 0.0); LoanTestUtils.assertInstallmentDetails(loan, 5, 50.9, 0.1, 0.0, 0.0, 0.0); LoanTestUtils.assertInstallmentDetails(loan, 6, 45.2, 0.8, 0.0, 0.0, 0.0); Assert.fail("Expected AccountException !!"); } catch (AccountException e) { } }
From source file:org.codice.ddf.spatial.ogc.csw.catalog.converter.impl.CswRecordConverter.java
/** * Converts properties in CSW records that overlap with same name as a basic Metacard attribute, * e.g., title. This conversion method is needed mainly because CSW records express all dates as * strings, whereas MetacardImpl expresses them as java.util.Date types. * /* w ww . java 2 s. co m*/ * @param attributeFormat * @param value * @return */ public Serializable convertStringValueToMetacardValue(AttributeFormat attributeFormat, String value) { LOGGER.debug("converting csw record overlapping property {}", value); Serializable ser = null; if (attributeFormat == null) { LOGGER.debug("AttributeFormat was null when converting {}", value); return ser; } switch (attributeFormat) { case BOOLEAN: ser = Boolean.valueOf(value); break; case DOUBLE: ser = Double.valueOf(value); break; case FLOAT: ser = Float.valueOf(value); break; case INTEGER: ser = Integer.valueOf(value); break; case LONG: ser = Long.valueOf(value); break; case SHORT: ser = Short.valueOf(value); break; case XML: case STRING: ser = value; break; case DATE: ser = convertToDate(value); break; default: break; } return ser; }
From source file:org.mifos.application.servicefacade.CollectionSheetServiceImpl.java
private CollectionSheetCustomerAccountDto sumAccountCollectionFees( final List<CollectionSheetCustomerAccountCollectionDto> customerAccountCollectionFees) { Double totalFee = Double.valueOf("0.0"); if (customerAccountCollectionFees == null) { return new CollectionSheetCustomerAccountDto(-1, Short.valueOf("1"), totalFee); }//from w w w. j a va2 s. c om if (customerAccountCollectionFees.size() > 1) { throw new IllegalStateException("Multiple currency"); } return new CollectionSheetCustomerAccountDto(customerAccountCollectionFees.get(0).getAccountId(), customerAccountCollectionFees.get(0).getCurrencyId(), customerAccountCollectionFees.get(0).getTotalFeeAmountDue()); }
From source file:org.apache.openjpa.enhance.Reflection.java
/** * Invoke the given setter on the given object. *///w ww .j a v a 2 s . co m public static void set(Object target, Method setter, short value) { set(target, setter, Short.valueOf(value)); }
From source file:org.apache.struts2.jasper.compiler.JspUtil.java
public static String coerceToPrimitiveShort(String s, boolean isNamedAttribute) { if (isNamedAttribute) { return "org.apache.struts2.jasper.runtime.JspRuntimeLibrary.coerceToShort(" + s + ")"; } else {/*www. j a v a 2 s . c om*/ if (s == null || s.length() == 0) return "(short) 0"; else return "((short) " + Short.valueOf(s).toString() + ")"; } }
From source file:net.sf.json.TestJSONObject.java
public void testFromObject_ObjectBean() { // FR 1611204 ObjectBean bean = new ObjectBean(); bean.setPbyte(Byte.valueOf("1")); bean.setPshort(Short.valueOf("1")); bean.setPint(Integer.valueOf("1")); bean.setPlong(Long.valueOf("1")); bean.setPfloat(Float.valueOf("1")); bean.setPdouble(Double.valueOf("1")); bean.setPchar(new Character('1')); bean.setPboolean(Boolean.TRUE); bean.setPstring("json"); bean.setParray(new String[] { "a", "b" }); bean.setPbean(new BeanA()); List list = new ArrayList(); list.add("1"); list.add("2"); bean.setPlist(list);//from www . java 2 s . c o m Map map = new HashMap(); map.put("string", "json"); bean.setPmap(map); bean.setPfunction(new JSONFunction("this;")); JSONObject json = JSONObject.fromObject(bean); assertEquals(1, json.getInt("pbyte")); assertEquals(1, json.getInt("pshort")); assertEquals(1, json.getInt("pint")); assertEquals(1, json.getInt("plong")); assertEquals(1d, json.getDouble("pfloat"), 0d); assertEquals(1d, json.getDouble("pdouble"), 0d); assertTrue(json.getBoolean("pboolean")); assertEquals("json", json.get("pstring")); Assertions.assertEquals(JSONArray.fromObject("['a','b']"), json.getJSONArray("parray")); Assertions.assertEquals(JSONArray.fromObject("['1','2']"), json.getJSONArray("plist")); assertEquals("1", json.getString("pchar")); JSONObject b = new JSONObject().element("string", "json").element("integer", "42").element("bool", "true"); Assertions.assertEquals(b, json.getJSONObject("pbean")); b = new JSONObject().element("string", "json"); Assertions.assertEquals(b, json.getJSONObject("pmap")); }
From source file:org.apache.struts2.jasper.compiler.JspUtil.java
public static String coerceToShort(String s, boolean isNamedAttribute) { if (isNamedAttribute) { return "(Short) org.apache.struts2.jasper.runtime.JspRuntimeLibrary.coerce(" + s + ", Short.class)"; } else {/* w w w . j av a 2 s.c o m*/ if (s == null || s.length() == 0) { return "new Short((short) 0)"; } else { // Detect format error at translation time return "new Short(\"" + Short.valueOf(s).toString() + "\")"; } } }