List of usage examples for java.lang Short valueOf
@HotSpotIntrinsicCandidate public static Short valueOf(short s)
From source file:org.mifos.accounts.loan.struts.actionforms.LoanAccountActionFormTest.java
private ArrayList<FeeDto> createDefaultFees() { AmountFeeBO amountFee = createMock(AmountFeeBO.class); expect(amountFee.getFeeId()).andReturn(Short.valueOf("1")); expect(amountFee.getFeeType()).andReturn(RateAmountFlag.AMOUNT).times(2); expect(amountFee.getFeeName()).andReturn("TestAmountFee"); expect(amountFee.getFeeAmount()).andReturn(new Money(TestUtils.RUPEE, "5000.0")).times(2); expect(amountFee.isPeriodic()).andReturn(false).times(2); replay(amountFee);/*from w w w .ja va2 s .co m*/ RateFeeBO rateFee = createMock(RateFeeBO.class); expect(rateFee.getFeeId()).andReturn(Short.valueOf("1")); expect(rateFee.getFeeType()).andReturn(RateAmountFlag.RATE).times(2); expect(rateFee.getFeeName()).andReturn("TestRateFee"); expect(rateFee.getRate()).andReturn(2.12345); expect(rateFee.getFeeFormula()).andReturn(createFeeFormulaEntityMock()); expect(rateFee.isPeriodic()).andReturn(false).times(2); replay(rateFee); UserContext userContext = createMock(UserContext.class); expect(userContext.getLocaleId()).andReturn(Short.valueOf("1")).times(2); replay(userContext); ArrayList<FeeDto> defaultFees = new ArrayList<FeeDto>(); defaultFees.add(new FeeDto(userContext, amountFee)); defaultFees.add(new FeeDto(userContext, rateFee)); return defaultFees; }
From source file:org.mifos.application.servicefacade.CenterServiceFacadeWebTier.java
@Override public void updateCustomerStatus(Integer customerId, Integer previousCustomerVersionNo, String flagIdAsString, String newStatusIdAsString, String notes) { MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal(); UserContext userContext = toUserContext(user); Short flagId = null;/* w w w .j av a2 s . co m*/ Short newStatusId = null; if (StringUtils.isNotBlank(flagIdAsString)) { flagId = Short.valueOf(flagIdAsString); } if (StringUtils.isNotBlank(newStatusIdAsString)) { newStatusId = Short.valueOf(newStatusIdAsString); } CustomerStatusFlag customerStatusFlag = null; if (flagId != null) { customerStatusFlag = CustomerStatusFlag.fromInt(flagId); } CustomerStatus newStatus = CustomerStatus.fromInt(newStatusId); CustomerStatusUpdate customerStatusUpdate = new CustomerStatusUpdate(customerId, previousCustomerVersionNo, customerStatusFlag, newStatus, notes); try { this.customerService.updateCustomerStatus(userContext, customerStatusUpdate); } catch (CustomerException e) { throw new BusinessRuleException(e.getKey(), e); } }
From source file:bammerbom.ultimatecore.bukkit.configuration.ConfigSection.java
public List<Short> getShortList(String path) { List<?> list = getList(path); if (list == null) { return new ArrayList<>(0); }/*from www. j av a 2s . c om*/ List<Short> result = new ArrayList<>(); for (Object object : list) { if (object instanceof Short) { result.add((Short) object); } else if (object instanceof String) { try { result.add(Short.valueOf((String) object)); } catch (Exception ex) { } } else if (object instanceof Character) { result.add((short) ((Character) object).charValue()); } else if (object instanceof Number) { result.add(((Number) object).shortValue()); } } return result; }
From source file:com.cloud.api.ApiDispatcher.java
@SuppressWarnings({ "unchecked", "rawtypes" }) private static void setFieldValue(Field field, BaseCmd cmdObj, Object paramObj, Parameter annotation) throws IllegalArgumentException, ParseException { try {//from w ww . j a va 2 s . c o m field.setAccessible(true); CommandType fieldType = annotation.type(); switch (fieldType) { case BOOLEAN: field.set(cmdObj, Boolean.valueOf(paramObj.toString())); break; case DATE: // This piece of code is for maintaining backward compatibility // and support both the date formats(Bug 9724) // Do the date messaging for ListEventsCmd only if (cmdObj instanceof ListEventsCmd) { boolean isObjInNewDateFormat = isObjInNewDateFormat(paramObj.toString()); if (isObjInNewDateFormat) { DateFormat newFormat = BaseCmd.NEW_INPUT_FORMAT; synchronized (newFormat) { field.set(cmdObj, newFormat.parse(paramObj.toString())); } } else { DateFormat format = BaseCmd.INPUT_FORMAT; synchronized (format) { Date date = format.parse(paramObj.toString()); if (field.getName().equals("startDate")) { date = messageDate(date, 0, 0, 0); } else if (field.getName().equals("endDate")) { date = messageDate(date, 23, 59, 59); } field.set(cmdObj, date); } } } else { DateFormat format = BaseCmd.INPUT_FORMAT; format.setLenient(false); synchronized (format) { field.set(cmdObj, format.parse(paramObj.toString())); } } break; case FLOAT: // Assuming that the parameters have been checked for required before now, // we ignore blank or null values and defer to the command to set a default // value for optional parameters ... if (paramObj != null && isNotBlank(paramObj.toString())) { field.set(cmdObj, Float.valueOf(paramObj.toString())); } break; case INTEGER: // Assuming that the parameters have been checked for required before now, // we ignore blank or null values and defer to the command to set a default // value for optional parameters ... if (paramObj != null && isNotBlank(paramObj.toString())) { field.set(cmdObj, Integer.valueOf(paramObj.toString())); } break; case LIST: List listParam = new ArrayList(); StringTokenizer st = new StringTokenizer(paramObj.toString(), ","); while (st.hasMoreTokens()) { String token = st.nextToken(); CommandType listType = annotation.collectionType(); switch (listType) { case INTEGER: listParam.add(Integer.valueOf(token)); break; case UUID: if (token.isEmpty()) break; Long internalId = translateUuidToInternalId(token, annotation); listParam.add(internalId); break; case LONG: { listParam.add(Long.valueOf(token)); } break; case SHORT: listParam.add(Short.valueOf(token)); case STRING: listParam.add(token); break; } } field.set(cmdObj, listParam); break; case UUID: if (paramObj.toString().isEmpty()) break; Long internalId = translateUuidToInternalId(paramObj.toString(), annotation); field.set(cmdObj, internalId); break; case LONG: field.set(cmdObj, Long.valueOf(paramObj.toString())); break; case SHORT: field.set(cmdObj, Short.valueOf(paramObj.toString())); break; case STRING: if ((paramObj != null) && paramObj.toString().length() > annotation.length()) { s_logger.error("Value greater than max allowed length " + annotation.length() + " for param: " + field.getName()); throw new InvalidParameterValueException("Value greater than max allowed length " + annotation.length() + " for param: " + field.getName()); } field.set(cmdObj, paramObj.toString()); break; case TZDATE: field.set(cmdObj, DateUtil.parseTZDateString(paramObj.toString())); break; case MAP: default: field.set(cmdObj, paramObj); break; } } catch (IllegalAccessException ex) { s_logger.error("Error initializing command " + cmdObj.getCommandName() + ", field " + field.getName() + " is not accessible."); throw new CloudRuntimeException("Internal error initializing parameters for command " + cmdObj.getCommandName() + " [field " + field.getName() + " is not accessible]"); } }
From source file:ddf.common.test.ServiceManager.java
private Object getAttributeValue(String value, int type) { switch (type) { case AttributeDefinition.BOOLEAN: return Boolean.valueOf(value); case AttributeDefinition.BYTE: return Byte.valueOf(value); case AttributeDefinition.DOUBLE: return Double.valueOf(value); case AttributeDefinition.CHARACTER: return value.toCharArray()[0]; case AttributeDefinition.FLOAT: return Float.valueOf(value); case AttributeDefinition.INTEGER: return Integer.valueOf(value); case AttributeDefinition.LONG: return Long.valueOf(value); case AttributeDefinition.SHORT: return Short.valueOf(value); case AttributeDefinition.PASSWORD: case AttributeDefinition.STRING: default://www. j a va2s.c o m return value; } }
From source file:org.mifos.accounts.loan.business.LoanBORedoDisbursalIntegrationTest.java
@Ignore @Test/* www. ja v a 2s. com*/ public void testRedoLoanApplyWholeMiscFeeAfterPartialPayment() throws Exception { 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); applyCharge(loan, Short.valueOf(AccountConstants.MISC_FEES), new Double("33")); LoanTestUtils.assertInstallmentDetails(loan, 1, 1.0, 0.0, 0.0, 0.0, 0.0); LoanTestUtils.assertInstallmentDetails(loan, 2, 50.9, 0.1, 0.0, 33.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); }
From source file:com.sun.faces.el.impl.Coercions.java
/** * Coerces a String to the given primitive number class *///from w w w .j av a 2 s. c o m static Number coerceToPrimitiveNumber(String pValue, Class pClass) throws ElException { if (pClass == Byte.class || pClass == Byte.TYPE) { return Byte.valueOf(pValue); } else if (pClass == Short.class || pClass == Short.TYPE) { return Short.valueOf(pValue); } else if (pClass == Integer.class || pClass == Integer.TYPE) { return Integer.valueOf(pValue); } else if (pClass == Long.class || pClass == Long.TYPE) { return Long.valueOf(pValue); } else if (pClass == Float.class || pClass == Float.TYPE) { return Float.valueOf(pValue); } else if (pClass == Double.class || pClass == Double.TYPE) { return Double.valueOf(pValue); } else if (pClass == BigInteger.class) { return new BigInteger(pValue); } else if (pClass == BigDecimal.class) { return new BigDecimal(pValue); } else { return PrimitiveObjects.getInteger(0); } }
From source file:com.sm.query.utils.QueryUtils.java
public static Object convert(Type type, Result result) { if (isSameType(type, result.getType())) return result.getValue(); switch (type) { case INT://w w w .j ava2s .c o m case INTS: return Integer.valueOf((String) result.getValue()); case SHORT: case SHORTS: return Short.valueOf((String) result.getValue()); case LONG: case LONGS: return Long.valueOf((String) result.getValue()); case FLOAT: case FLOATS: return Float.valueOf((String) result.getValue()); case DOUBLE: case DOUBLES: return Double.valueOf((String) result.getValue()); case BOOLEAN: case BOOLEANS: return Boolean.valueOf((String) result.getValue()); default: throw new QueryException(type.toString() + " is not supported yet"); } }
From source file:org.mifos.accounts.productsmix.struts.action.ProductMixAction.java
@TransactionDemarcate(saveToken = true) public ActionForward get(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { ProductMixActionForm prdMixActionForm = (ProductMixActionForm) form; PrdOfferingBO prdOfferingBO = getPrdMixBusinessService() .getPrdOfferingByID(Short.valueOf(prdMixActionForm.getPrdOfferingId())); SessionUtils.removeAttribute(Constants.BUSINESS_KEY, request); SessionUtils.setAttribute(Constants.BUSINESS_KEY, prdOfferingBO, request); if (StringUtils.isNotBlank(prdOfferingBO.getPrdType().getProductTypeID().toString())) { List<PrdOfferingBO> prdOfferingList = ((ProductMixBusinessService) getService()) .getAllowedPrdOfferingsByType(prdMixActionForm.getPrdOfferingId(), prdMixActionForm.getProductType()); List<PrdOfferingBO> notAllowedPrdOfferingList = ((ProductMixBusinessService) getService()) .getNotAllowedPrdOfferingsByType(prdMixActionForm.getPrdOfferingId()); SessionUtils.setCollectionAttribute(ProductDefinitionConstants.ALLOWEDPRODUCTLIST, prdOfferingList, request);//from w w w. j a va 2 s. c o m SessionUtils.setCollectionAttribute(ProductDefinitionConstants.NOTALLOWEDPRODUCTLIST, notAllowedPrdOfferingList, request); SessionUtils.setCollectionAttribute(ProductDefinitionConstants.PRODUCTOFFERINGLIST, prdOfferingList, request); SessionUtils.setCollectionAttribute(ProductDefinitionConstants.OLDPRODUCTOFFERINGLIST, notAllowedPrdOfferingList, request); } return mapping.findForward(ActionForwards.get_success.toString()); }
From source file:org.datanucleus.store.hbase.fieldmanager.FetchFieldManager.java
private short fetchShortInternal(AbstractMemberMetaData mmd, byte[] bytes) { short value;// w ww . j a v a 2 s . c o m if (bytes == null) { // Handle missing field String dflt = HBaseUtils.getDefaultValueForMember(mmd); if (dflt != null) { return Short.valueOf(dflt).shortValue(); } return 0; } if (mmd.isSerialized()) { try { ByteArrayInputStream bis = new ByteArrayInputStream(bytes); ObjectInputStream ois = new ObjectInputStream(bis); value = ois.readShort(); ois.close(); bis.close(); } catch (IOException e) { throw new NucleusException(e.getMessage(), e); } } else { value = Bytes.toShort(bytes); } return value; }