Example usage for java.lang Short valueOf

List of usage examples for java.lang Short valueOf

Introduction

In this page you can find the example usage for java.lang Short valueOf.

Prototype

@HotSpotIntrinsicCandidate
public static Short valueOf(short s) 

Source Link

Document

Returns a Short instance representing the specified short value.

Usage

From source file:org.apache.click.util.RequestTypeConverter.java

/**
 * Return the converted value for the given value object and target type.
 *
 * @param value the value object to convert
 * @param toType the target class type to convert the value to
 * @return a converted value into the specified type
 *//*from  ww  w  . j a  v a2s .co m*/
protected Object convertValue(Object value, Class<?> toType) {
    Object result = null;

    if (value != null) {

        // If array -> array then convert components of array individually
        if (value.getClass().isArray() && toType.isArray()) {
            Class<?> componentType = toType.getComponentType();

            result = Array.newInstance(componentType, Array.getLength(value));

            for (int i = 0, icount = Array.getLength(value); i < icount; i++) {
                Array.set(result, i, convertValue(Array.get(value, i), componentType));
            }

        } else {
            if ((toType == Integer.class) || (toType == Integer.TYPE)) {
                result = Integer.valueOf((int) OgnlOps.longValue(value));

            } else if ((toType == Double.class) || (toType == Double.TYPE)) {
                result = new Double(OgnlOps.doubleValue(value));

            } else if ((toType == Boolean.class) || (toType == Boolean.TYPE)) {
                result = Boolean.valueOf(value.toString());

            } else if ((toType == Byte.class) || (toType == Byte.TYPE)) {
                result = Byte.valueOf((byte) OgnlOps.longValue(value));

            } else if ((toType == Character.class) || (toType == Character.TYPE)) {
                result = Character.valueOf((char) OgnlOps.longValue(value));

            } else if ((toType == Short.class) || (toType == Short.TYPE)) {
                result = Short.valueOf((short) OgnlOps.longValue(value));

            } else if ((toType == Long.class) || (toType == Long.TYPE)) {
                result = Long.valueOf(OgnlOps.longValue(value));

            } else if ((toType == Float.class) || (toType == Float.TYPE)) {
                result = new Float(OgnlOps.doubleValue(value));

            } else if (toType == BigInteger.class) {
                result = OgnlOps.bigIntValue(value);

            } else if (toType == BigDecimal.class) {
                result = bigDecValue(value);

            } else if (toType == String.class) {
                result = OgnlOps.stringValue(value);

            } else if (toType == java.util.Date.class) {
                long time = getTimeFromDateString(value.toString());
                if (time > Long.MIN_VALUE) {
                    result = new java.util.Date(time);
                }

            } else if (toType == java.sql.Date.class) {
                long time = getTimeFromDateString(value.toString());
                if (time > Long.MIN_VALUE) {
                    result = new java.sql.Date(time);
                }

            } else if (toType == java.sql.Time.class) {
                long time = getTimeFromDateString(value.toString());
                if (time > Long.MIN_VALUE) {
                    result = new java.sql.Time(time);
                }

            } else if (toType == java.sql.Timestamp.class) {
                long time = getTimeFromDateString(value.toString());
                if (time > Long.MIN_VALUE) {
                    result = new java.sql.Timestamp(time);
                }
            }
        }

    } else {
        if (toType.isPrimitive()) {
            result = OgnlRuntime.getPrimitiveDefaultValue(toType);
        }
    }
    return result;
}

From source file:org.mifos.accounts.fees.struts.actionforms.FeeActionForm.java

public FeeFrequencyType getFeeFrequencyTypeValue() {
    return StringUtils.isNotBlank(feeFrequencyType)
            ? FeeFrequencyType.getFeeFrequencyType(Short.valueOf(feeFrequencyType))
            : null;// ww w. j a v a2 s .  c om
}

From source file:de.odysseus.calyxo.base.util.ParseUtils.java

/**
     * Parse value of specified type. The string value has to be in
     * standard notation for the specified type.
     *//*from ww  w.  j av a2s .  c o  m*/
    public static Object parse(Class type, String value) throws Exception {
        if (value == null) {
            return nullValue(type);
        } else if (value.length() == 0) {
            return type == String.class ? value : nullValue(type);
        }

        type = objectType(type);

        if (type == BigDecimal.class) {
            return new BigDecimal(value);
        } else if (type == BigInteger.class) {
            return new BigInteger(value);
        } else if (type == Boolean.class) {
            return parseBoolean(value);
        } else if (type == Byte.class) {
            return Byte.valueOf(value);
        } else if (type == Character.class) {
            return parseCharacter(value);
        } else if (type == Date.class) {
            return parseDate(value);
        } else if (type == Double.class) {
            return Double.valueOf(value);
        } else if (type == Float.class) {
            return Float.valueOf(value);
        } else if (type == Integer.class) {
            return Integer.valueOf(value);
        } else if (type == Long.class) {
            return Long.valueOf(value);
        } else if (type == Short.class) {
            return Short.valueOf(value);
        } else if (type == String.class) {
            return value;
        }
        throw new ParseException("Cannot parse type " + type, 0);
    }

From source file:edu.uniminuto.servlets.GuardarDisco.java

/**
 * Handles the HTTP <code>POST</code> method.
 *
 * @param request servlet request/*from   w w  w .  j  a  v  a  2 s .  c  o m*/
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {

    String nombre = "";
    long precio = 0;
    int anhio = 0;
    short genero = 1;
    int interprete = 1;

    //        String nombre = getParameter(request, "nombre");
    //        long precio = Long.valueOf(getParameter(request, "precio"));
    //        int anhio = Integer.valueOf(getParameter(request, "anhio"));
    //
    //        int genero = Integer.valueOf(getParameter(request, "genero"));
    //        int interprete = Integer.valueOf(getParameter(request, "interprete"));

    String url = "";
    try {

        boolean isMultipart = ServletFileUpload.isMultipartContent(request);
        String imagen = "images/";

        // Create a factory for disk-based file items
        DiskFileItemFactory factory = new DiskFileItemFactory(1024 * 4, new File("c;//tmp"));

        // Configure a repository (to ensure a secure temp location is used)
        ServletContext servletContext = this.getServletConfig().getServletContext();
        File repository = (File) servletContext.getAttribute("javax.servlet.context.tempdir");
        factory.setRepository(repository);

        // Create a new file upload handler
        ServletFileUpload upload = new ServletFileUpload(factory);

        // Parse the request
        List<FileItem> items = upload.parseRequest(request);
        Iterator<FileItem> iter = items.iterator();
        while (iter.hasNext()) {
            FileItem item = iter.next();

            if (item.isFormField()) {
                if (item.getFieldName().equals("nombre")) {
                    nombre = item.getString();
                } else if (item.getFieldName().equals("anhio")) {
                    anhio = Integer.valueOf(item.getString());
                } else if (item.getFieldName().equals("genero")) {
                    genero = Short.valueOf(item.getString());
                } else if (item.getFieldName().equals("interprete")) {
                    interprete = Integer.valueOf(item.getString());
                } else if (item.getFieldName().equals("precio")) {
                    precio = Long.valueOf(item.getString());
                }

            } else {
                String fieldName = item.getFieldName();
                String fileName = item.getName();
                String contentType = item.getContentType();
                boolean isInMemory = item.isInMemory();
                long sizeInBytes = item.getSize();

                //                    InputStream uploadedStream = item.getInputStream();
                //                    uploadedStream.close();
                //                    InputStream uploadedStream = item.getInputStream();
                //                    uploadedStream.close();
                imagen = imagen + fileName;
                File uploadedFile = new File(RUTA + fileName);

                item.write(uploadedFile);
                //                    } else {
                //                        
                //                    }
            }
        }

        java.util.Calendar cl = java.util.Calendar.getInstance();
        cl.set(anhio, 0, 0, 0, 0, 0);

        Disco disco = new Disco();
        disco.setGenero(generoFacade.find(genero));
        disco.setInterprete(interpreteFacade.find(interprete));
        disco.setNombre(nombre);
        disco.setImagen(imagen);
        disco.setAnhio(cl.getTime());

        discoFacade.create(disco);

        if (disco.getId() != null) {

            Discopropietario dp = new Discopropietario();
            dp.setDisco(disco);
            dp.setPropietario((Persona) request.getSession().getAttribute("usuario"));
            dp.setPrecio(precio);
            dp.setVendido(false);

            dpFacade.create(dp);

            url = "disco?id=" + disco.getId();

        } else {
            url = "fdisco?nombre=" + nombre + "&precio=" + precio + "&anhio=" + anhio + "&genero=" + genero
                    + "&interprete=" + interprete;
        }

    } catch (FileUploadException ex) {
        Logger.getLogger(GuardarDisco.class.getName()).log(Level.SEVERE, null, ex);
    } catch (Exception ex) {
        Logger.getLogger(GuardarDisco.class.getName()).log(Level.SEVERE, null, ex);
    }

    response.sendRedirect(url);

}

From source file:it.unimi.dsi.util.Properties.java

public void addProperty(final String key, final short s) {
    super.addProperty(key, Short.valueOf(s));
}

From source file:org.mifos.accounts.fees.business.FeeDto.java

public Short getFeeIdValue() {
    return StringUtils.isNotBlank(feeId) ? Short.valueOf(feeId) : null;
}

From source file:it.unimi.dsi.util.Properties.java

public void setProperty(final String key, final short s) {
    super.setProperty(key, Short.valueOf(s));
}

From source file:com.wirecard.ezlinkwebservices.util.TerminalUtil.java

public synchronized ETranxLogDto insertNonWDTransaction(String merchantNo, String merchantTranxRefNo,
        String orderNo, double amount) {

    Date objDate = new Date();
    int returnValue = 0;
    SpringBeanAutowiringSupport.processInjectionBasedOnCurrentContext(this);

    ETranxLogDto objETranxLogDto = new ETranxLogDto();
    objETranxLogDto.setDatetime(objDate);
    objETranxLogDto.setMerchantTranxDate(objDate);
    objETranxLogDto.setVersion(StringConstants.Common.VERSION);
    objETranxLogDto.setTranxcode(StringConstants.Common.TRANX_CODE_DEBIT);
    objETranxLogDto.setMerchantNo(merchantNo);
    objETranxLogDto.setMerchantRefno(merchantTranxRefNo);
    objETranxLogDto.setOrderNo(orderNo);
    objETranxLogDto.setOrderInfo("NON WD");
    objETranxLogDto.setAmount(amount);/*from   w ww.j a v  a2 s .c o  m*/
    objETranxLogDto.setCurrency(Short.valueOf("702"));
    objETranxLogDto.setSecurehashType("SHA256");
    objETranxLogDto.setResponseCode(StringConstants.ResponseCode.SUCCESS);
    objETranxLogDto.setApprovalCode("A012");
    objETranxLogDto.setRrn("111");
    objETranxLogDto.setChannel("NW");
    objETranxLogDto.setMcc("NOWC");
    objETranxLogDto.setTranxStatus(StringConstants.Common.TRANX_STATUS_DEBIT);

    try {
        returnValue = objETranxLogDtoMapper.insert(objETranxLogDto);
        if (returnValue == 1) {

        }
    } catch (Exception ex) {
        Logger.getLogger(TerminalUtil.class.getName()).log(Level.SEVERE, null, ex);
        ezlink.error(new Object(), ex);
        return null;
    }

    return objETranxLogDto;
}

From source file:org.mifos.accounts.loan.struts.action.LoanDisbursementAction.java

@TransactionDemarcate(joinToken = true)
public ActionForward load(final ActionMapping mapping, final ActionForm form, final HttpServletRequest request,
        @SuppressWarnings("unused") final HttpServletResponse response) throws Exception {

    LoanDisbursementActionForm loanDisbursementActionForm = (LoanDisbursementActionForm) form;
    loanDisbursementActionForm.clear();// w ww.  j a va  2s.co m
    loanDisbursementActionForm.setAmountCannotBeZero(false);

    Integer loanAccountId = Integer.valueOf(loanDisbursementActionForm.getAccountId());
    LoanDisbursalDto loanDisbursalDto = loanAccountServiceFacade.retrieveLoanDisbursalDetails(loanAccountId);

    UserContext uc = getUserContext(request);
    SessionUtils.setAttribute(LoanConstants.PROPOSED_DISBURSAL_DATE, loanDisbursalDto.getProposedDate(),
            request);
    loanDisbursementActionForm
            .setTransactionDate(getUserLocaleDate(uc.getPreferredLocale(), loanDisbursalDto.getProposedDate()));

    loanDisbursementActionForm.setAmount(loanDisbursalDto.getAmountPaidAtDisbursement());
    loanDisbursementActionForm.setLoanAmount(loanDisbursalDto.getLoanAmount());
    if (loanDisbursalDto.isMultiCurrencyEnabled()) {
        loanDisbursementActionForm.setCurrencyId(loanDisbursalDto.getCurrencyId());
    }

    Short repaymentIndependentOfMeetingScheduleValue = loanDisbursalDto
            .isRepaymentIndependentOfMeetingSchedule() ? Short.valueOf("1") : Short.valueOf("0");
    SessionUtils.setAttribute(LoanConstants.REPAYMENT_SCHEDULES_INDEPENDENT_OF_MEETING_IS_ENABLED,
            repaymentIndependentOfMeetingScheduleValue, request);
    SessionUtils.setAttribute(AccountingRulesConstants.BACKDATED_TRANSACTIONS_ALLOWED,
            loanDisbursalDto.isBackDatedTransactionsAllowed(), request);

    List<PaymentTypeEntity> paymentTypes = legacyAcceptedPaymentTypeDao
            .getAcceptedPaymentTypesForATransaction(uc.getLocaleId(), TrxnTypes.loan_disbursement.getValue());
    SessionUtils.setCollectionAttribute(MasterConstants.PAYMENT_TYPE, paymentTypes, request);

    return mapping.findForward(Constants.LOAD_SUCCESS);
}

From source file:com.github.wnameless.spring.bulkapi.DefaultBulkApiService.java

private BulkResult buldResult(ResponseEntity<String> rawRes) {
    BulkResult res = new BulkResult();
    res.setStatus(Short.valueOf(rawRes.getStatusCode().toString()));
    res.setHeaders(rawRes.getHeaders().toSingleValueMap());
    res.setBody(rawRes.getBody());//from w w  w  . j a v  a  2s .com

    return res;
}