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.mifos.accounts.savings.struts.action.SavingsAction.java

@TransactionDemarcate(validateAndResetToken = true)
public ActionForward create(ActionMapping mapping, ActionForm form, HttpServletRequest request,
        @SuppressWarnings("unused") HttpServletResponse response) throws Exception {
    SavingsActionForm savingsActionForm = ((SavingsActionForm) form);
    logger.debug("In SavingsAction::create(), accountStateId: " + savingsActionForm.getStateSelected());
    UserContext uc = (UserContext) SessionUtils.getAttribute(Constants.USER_CONTEXT_KEY, request.getSession());
    CustomerBO customer = (CustomerBO) SessionUtils.getAttribute(SavingsConstants.CLIENT, request);

    Integer customerId = customer.getCustomerId();
    Integer productId = Integer.valueOf(savingsActionForm.getSelectedPrdOfferingId());
    String recommendedOrMandatoryAmount = savingsActionForm.getRecommendedAmount();
    Short accountState = Short.valueOf(savingsActionForm.getStateSelected());

    customer = this.customerDao.findCustomerById(customerId);
    checkPermissionForCreate(accountState, uc, customer.getOffice().getOfficeId(),
            customer.getPersonnel().getPersonnelId());

    SavingsAccountCreationDto savingsAccountCreation = new SavingsAccountCreationDto(productId, customerId,
            accountState, recommendedOrMandatoryAmount);
    Long savingsId = this.savingsServiceFacade.createSavingsAccount(savingsAccountCreation);

    SavingsBO saving = this.savingsDao.findById(savingsId);

    createGroupQuestionnaire.saveResponses(request, savingsActionForm, saving.getAccountId());

    request.setAttribute(SavingsConstants.GLOBALACCOUNTNUM, saving.getGlobalAccountNum());
    request.setAttribute(SavingsConstants.RECORD_OFFICE_ID, saving.getOffice().getOfficeId());
    request.setAttribute(SavingsConstants.CLIENT_NAME, customer.getDisplayName());
    request.setAttribute(SavingsConstants.CLIENT_ID, customer.getCustomerId());
    request.setAttribute(SavingsConstants.CLIENT_LEVEL, customer.getCustomerLevel().getId());

    logger.info("In SavingsAction::create(), Savings object saved successfully ");
    return mapping.findForward("create_success");
}

From source file:org.brekka.stillingar.spring.bpp.ConfigurationBeanPostProcessorTest.java

@Test
public void primitiveDefaultShort() {
    assertEquals(ConfigurationBeanPostProcessor.primitiveDefault(Short.TYPE), Short.valueOf((short) 0));
}

From source file:com.sm.query.utils.QueryUtils.java

public static Object convertType(Type type, String value) {
    switch (type) {
    case STRING://from  w  w w  .  j  av a 2  s .  c  o  m
        return value;
    case INTS:
    case INT:
        return Integer.valueOf(value);
    case SHORT:
    case SHORTS:
        return Short.valueOf(value);
    case LONG:
    case LONGS:
        return Long.valueOf(value);
    case NUMBER:
        return Long.valueOf(value);
    default:
        throw new ObjectIdException("wrong type to convert long " + type);
    }
}

From source file:org.apache.hadoop.hive.jdbc.TestJdbcDriver.java

private PreparedStatement createPreapredStatementUsingSetObject(String sql) throws SQLException {
    PreparedStatement ps = con.prepareStatement(sql);

    ps.setObject(1, true); //setBoolean
    ps.setObject(2, true); //setBoolean

    ps.setObject(3, Short.valueOf("1")); //setShort
    ps.setObject(4, 2); //setInt
    ps.setObject(5, 3f); //setFloat
    ps.setObject(6, Double.valueOf(4)); //setDouble
    ps.setObject(7, "test'string\""); //setString
    ps.setObject(8, 5L); //setLong
    ps.setObject(9, (byte) 1); //setByte
    ps.setObject(10, (byte) 1); //setByte
    ps.setString(11, "2012-01-01"); //setString

    ps.setMaxRows(2);// ww  w  .  j a  v  a 2 s .  c  om
    return ps;
}

From source file:org.mifos.customers.office.struts.action.OffAction.java

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

    OffActionForm offActionForm = (OffActionForm) form;

    OfficeDto sessionOffice = (OfficeDto) SessionUtils.getAttribute(OfficeConstants.OFFICE_DTO, request);
    OfficeBO office = this.officeDao.findOfficeById(sessionOffice.getOfficeId());

    checkVersionMismatch(sessionOffice.getVersionNum(), office.getVersionNo());

    String officeLevel = request.getParameter("officeLevel");
    OfficeDetailsForEdit officeDetailsForEdit = this.officeServiceFacade
            .retrieveOfficeDetailsForEdit(officeLevel);

    if (StringUtils.isNotBlank(officeLevel)) {
        offActionForm.setOfficeLevel(officeLevel);

        List<OfficeDetailsDto> parents = this.officeServiceFacade
                .retrieveActiveParentOffices(Short.valueOf(officeLevel));
        OfficeDto office1 = (OfficeDto) SessionUtils.getAttribute(OfficeConstants.OFFICE_DTO, request);

        if (offActionForm.getInput() != null && offActionForm.getInput().equals("edit") && office1 != null) {
            for (int i = 0; i < parents.size(); i++) {
                OfficeDetailsDto view = parents.get(i);
                if (view.getOfficeId().equals(office1.getOfficeId())) {
                    parents.remove(view);
                }//from w w w . j av a  2 s . c o m
            }
        }
        SessionUtils.setCollectionAttribute(OfficeConstants.PARENTS, parents, request);
    }
    offActionForm.setCustomFields(new ArrayList<CustomFieldDto>());

    SessionUtils.setCollectionAttribute(OfficeConstants.OFFICELEVELLIST,
            officeDetailsForEdit.getConfiguredOfficeLevels(), request);
    SessionUtils.setCollectionAttribute(OfficeConstants.OFFICESTATUSLIST, officeDetailsForEdit.getStatusList(),
            request);

    List<CustomFieldDefinitionEntity> customFieldDefs = new ArrayList<CustomFieldDefinitionEntity>();
    SessionUtils.setCollectionAttribute(CustomerConstants.CUSTOM_FIELDS_LIST, customFieldDefs, request);

    return mapping.findForward(ActionForwards.edit_success.toString());
}

From source file:org.codice.ddf.spatial.ogc.wfs.v1_0_0.catalog.source.WfsFilterDelegate.java

@Override
public FilterType propertyIsEqualTo(String propertyName, short literal) {
    return buildPropertyIsFilterType(propertyName, Short.valueOf(literal), PROPERTY_IS_OPS.PropertyIsEqualTo);
}

From source file:idgs.IdgsDriver.java

@SuppressWarnings("unchecked")
@Override/*  w w w .ja va 2 s  .  c o m*/
public boolean getResults(@SuppressWarnings("rawtypes") List result)
        throws IOException, CommandNeedRetryException {
    int maxRows = 100;
    try {
        maxRows = (Integer) maxRowsField.get(this);
    } catch (Exception e) {
        e.printStackTrace();
        return false;
    }

    ResultSet resultSet = getResultSet();
    if (resultSet == null) {
        return super.getResults(result);
    }

    List<RowData> results = resultSet.getResults(maxRows);
    if (results == null) {
        return false;
    }

    List<FieldSchema> fieldSchemas = getSchema().getFieldSchemas();
    for (RowData rowData : results) {
        Object[] row = new Object[fieldSchemas.size()];

        for (int i = 0; i < fieldSchemas.size(); ++i) {
            FieldSchema schema = fieldSchemas.get(i);
            Object value = rowData.getFieldValue(schema.getName());
            row[i] = null;

            if (value != null) {
                String type = schema.getType();
                if (type.equalsIgnoreCase("smallint")) {
                    if (value instanceof Integer) {
                        row[i] = ((Integer) value).shortValue();
                    }
                    row[i] = Short.valueOf(value.toString());
                } else if (type.equalsIgnoreCase("tinyint")) {
                    if (value instanceof Integer) {
                        row[i] = ((Integer) value).byteValue();
                    }
                } else if (type.equalsIgnoreCase("binary")) {
                    if (value instanceof String) {
                        row[i] = ((String) value).getBytes();
                    }
                } else if (type.equalsIgnoreCase("timestamp")) {
                    if (value instanceof String) {
                        try {
                            row[i] = Timestamp.valueOf((String) value);
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                    }
                } else if (type.equalsIgnoreCase("date")) {
                    if (value instanceof String) {
                        try {
                            row[i] = Date.valueOf((String) value);
                        } catch (Exception e) {
                        }
                    }
                } else {
                    row[i] = value;
                }
            }
        }

        result.add(row);
    }

    return true;
}

From source file:br.gov.frameworkdemoiselle.ldap.internal.ClazzUtils.java

public static Object getValueAsFieldType(Field field, Object values, boolean cascade) {
    if (values instanceof String[]) {
        String[] valueArray = (String[]) values;

        if (valueArray == null || valueArray.length == 0)
            return null;

        if (field.getType().isAssignableFrom(String.class))
            return valueArray[0];

        if (field.getType().isArray())
            if (field.getType().getComponentType().isAssignableFrom(String.class))
                return valueArray;

        if (field.getType().isPrimitive()) {

            if (field.getType().isAssignableFrom(int.class))
                return Integer.valueOf(valueArray[0]);

            if (field.getType().isAssignableFrom(long.class))
                return Long.valueOf(valueArray[0]);

            if (field.getType().isAssignableFrom(double.class))
                return Double.valueOf(valueArray[0]);

            if (field.getType().isAssignableFrom(float.class))
                return Float.valueOf(valueArray[0]);

            if (field.getType().isAssignableFrom(short.class))
                return Short.valueOf(valueArray[0]);

            if (field.getType().isAssignableFrom(byte.class))
                return Byte.valueOf(valueArray[0]);

        }/*  w w w. ja v a2  s . co m*/

        if (isAnnotationPresent(field.getType(), LDAPEntry.class, false))
            return getMappedEntryObject(field.getType(), valueArray, cascade);

        if (field.getType().isAssignableFrom(ArrayList.class))
            if (String.class.isAssignableFrom(Reflections.getGenericTypeArgument(field.getType(), 0)))
                return new ArrayList<String>(Arrays.asList(valueArray));

        if (field.getType().isAssignableFrom(Integer.class))
            return Integer.valueOf(valueArray[0]);

        if (field.getType().isAssignableFrom(Long.class))
            return Long.valueOf(valueArray[0]);

        if (field.getType().isAssignableFrom(Double.class))
            return Double.valueOf(valueArray[0]);

        if (field.getType().isAssignableFrom(Float.class))
            return Float.valueOf(valueArray[0]);

        if (field.getType().isAssignableFrom(Short.class))
            return Short.valueOf(valueArray[0]);

        if (field.getType().isAssignableFrom(Byte.class))
            return Byte.valueOf(valueArray[0]);

        logger.error("Handling not implemented for field " + field.getName() + " with type "
                + field.getType().getSimpleName());

    } else if (values instanceof byte[][]) {

        if (field.getType().isAssignableFrom(byte[][].class))
            return values;

        if (field.getType().isAssignableFrom(byte[].class))
            return ((byte[][]) values)[0];

        logger.error("Binary data from LDAP can't be set in " + field.getName() + " with type "
                + field.getType().getSimpleName());

    }

    logger.error("Object value should be String[] or byte[][]. The value type " + values.getClass()
            + " can't be set in " + field.getName() + " with type " + field.getType().getSimpleName());
    return null;
}

From source file:org.apache.hadoop.hive.jdbc.TestJdbcDriver.java

private PreparedStatement createPreapredStatementUsingSetXXX(String sql) throws SQLException {
    PreparedStatement ps = con.prepareStatement(sql);

    ps.setBoolean(1, true); //setBoolean
    ps.setBoolean(2, true); //setBoolean

    ps.setShort(3, Short.valueOf("1")); //setShort
    ps.setInt(4, 2); //setInt
    ps.setFloat(5, 3f); //setFloat
    ps.setDouble(6, Double.valueOf(4)); //setDouble
    ps.setString(7, "test'string\""); //setString
    ps.setLong(8, 5L); //setLong
    ps.setByte(9, (byte) 1); //setByte
    ps.setByte(10, (byte) 1); //setByte
    ps.setString(11, "2012-01-01"); //setString

    ps.setMaxRows(2);//from www .  j a va 2  s  .  c  o m
    return ps;
}

From source file:org.mifos.accounts.productsmix.struts.action.ProductMixAction.java

@TransactionDemarcate(joinToken = true)
public ActionForward loadDefaultAllowedProduct(ActionMapping mapping, ActionForm form,
        HttpServletRequest request, HttpServletResponse response) throws Exception {
    ProductMixActionForm prdMixActionForm = (ProductMixActionForm) form;
    SessionUtils.setAttribute(Constants.BUSINESS_KEY,
            getPrdMixBusinessService().getPrdOfferingByID(Short.valueOf(prdMixActionForm.getProductInstance())),
            request);//from   w  w  w .ja  v  a2  s .c o  m

    if (StringUtils.isNotBlank(prdMixActionForm.getProductType())) {

        List<PrdOfferingBO> prdOfferingList = ((ProductMixBusinessService) getService())
                .getAllowedPrdOfferingsForMixProduct(prdMixActionForm.getProductInstance(),
                        prdMixActionForm.getProductType());

        List<PrdOfferingBO> notAllowedPrdOfferingList = ((ProductMixBusinessService) getService())
                .getNotAllowedPrdOfferingsForMixProduct(prdMixActionForm.getProductInstance(),
                        prdMixActionForm.getProductType());

        SessionUtils.setCollectionAttribute(ProductDefinitionConstants.ALLOWEDPRODUCTLIST, prdOfferingList,
                request);
        SessionUtils.setCollectionAttribute(ProductDefinitionConstants.NOTALLOWEDPRODUCTLIST,
                notAllowedPrdOfferingList, request);
        SessionUtils.setCollectionAttribute(ProductDefinitionConstants.OLDNOTALLOWEDPRODUCTLIST,
                notAllowedPrdOfferingList, request);
        SessionUtils.setCollectionAttribute(ProductDefinitionConstants.PRODUCTOFFERINGLIST, prdOfferingList,
                request);

    }
    return mapping.findForward(ActionForwards.loadParents_success.toString());
}