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:net.sf.jasperreports.olap.JROlapDataSource.java

/**
 * Convert the value of the data type of the Field
 * @param jrField the Field whose type has to be converted
 * @return value of field in the requested type
 *
 *///from  www .ja v  a  2  s.  c  o  m
@Override
public Object getFieldValue(JRField jrField) throws JRException {
    Class<?> valueClass = jrField.getValueClass();
    Object value = fieldValues.get(jrField.getName());

    try {
        /*
         * Everything in the result is a string, apart from Member
         */
        if (valueClass.equals(mondrian.olap.Member.class)) {
            if (!(value instanceof mondrian.olap.Member)) {
                throw new JRException(EXCEPTION_MESSAGE_KEY_OLAP_CANNOT_CONVERT_FIELD_TYPE,
                        new Object[] { jrField.getName(), value.getClass(), valueClass.getName() });
            }

            return value;
        }

        /*
         * Convert the rest from String
         */
        String fieldValue = (String) value;

        if (fieldValue == null) {
            return null;
        }
        if (Number.class.isAssignableFrom(valueClass)) {
            fieldValue = fieldValue.trim();
        }
        if (fieldValue.length() == 0) {
            fieldValue = "0";
        }

        if (valueClass.equals(String.class)) {
            return fieldValue;
        } else if (valueClass.equals(Boolean.class)) {
            return fieldValue.equalsIgnoreCase("true");
        } else if (valueClass.equals(Byte.class)) {
            return Byte.valueOf(fieldValue);
        } else if (valueClass.equals(Integer.class)) {
            return Integer.valueOf(fieldValue);
        } else if (valueClass.equals(Long.class)) {
            return Long.valueOf(fieldValue);
        } else if (valueClass.equals(Short.class)) {
            return Short.valueOf(fieldValue);
        } else if (valueClass.equals(Double.class)) {
            return Double.valueOf(fieldValue);
        } else if (valueClass.equals(Float.class)) {
            return Float.valueOf(fieldValue);
        } else if (valueClass.equals(java.math.BigDecimal.class)) {
            return new java.math.BigDecimal(fieldValue);
        } else if (valueClass.equals(java.util.Date.class)) {
            return dateFormat.parse(fieldValue);
        } else if (valueClass.equals(java.sql.Timestamp.class)) {
            return new java.sql.Timestamp(dateFormat.parse(fieldValue).getTime());
        } else if (valueClass.equals(java.sql.Time.class)) {
            return new java.sql.Time(dateFormat.parse(fieldValue).getTime());
        } else if (valueClass.equals(java.lang.Number.class)) {
            return Double.valueOf(fieldValue);
        } else {
            throw new JRException(EXCEPTION_MESSAGE_KEY_OLAP_CANNOT_CONVERT_STRING_VALUE_TYPE,
                    new Object[] { jrField.getName(), fieldValue, fieldValues.get(jrField.getName()).getClass(),
                            valueClass.getName() });
        }
    } catch (Exception e) {
        throw new JRException(EXCEPTION_MESSAGE_KEY_OLAP_FIELD_VALUE_NOT_RETRIEVED,
                new Object[] { jrField.getName(), valueClass.getName() }, e);
    }
}

From source file:org.apache.hadoop.hive.ql.exec.vector.RandomRowObjectSource.java

public Object randomObject(int column) {
    PrimitiveCategory primitiveCategory = primitiveCategories[column];
    PrimitiveTypeInfo primitiveTypeInfo = primitiveTypeInfos[column];
    switch (primitiveCategory) {
    case BOOLEAN:
        return Boolean.valueOf(r.nextInt(1) == 1);
    case BYTE:/*from ww  w  . jav  a2s  .c o m*/
        return Byte.valueOf((byte) r.nextInt());
    case SHORT:
        return Short.valueOf((short) r.nextInt());
    case INT:
        return Integer.valueOf(r.nextInt());
    case LONG:
        return Long.valueOf(r.nextLong());
    case DATE:
        return getRandDate(r);
    case FLOAT:
        return Float.valueOf(r.nextFloat() * 10 - 5);
    case DOUBLE:
        return Double.valueOf(r.nextDouble() * 10 - 5);
    case STRING:
        return getRandString(r);
    case CHAR:
        return getRandHiveChar(r, (CharTypeInfo) primitiveTypeInfo);
    case VARCHAR:
        return getRandHiveVarchar(r, (VarcharTypeInfo) primitiveTypeInfo);
    case BINARY:
        return getRandBinary(r, 1 + r.nextInt(100));
    case TIMESTAMP:
        return getRandTimestamp(r);
    case INTERVAL_YEAR_MONTH:
        return getRandIntervalYearMonth(r);
    case INTERVAL_DAY_TIME:
        return getRandIntervalDayTime(r);
    case DECIMAL:
        return getRandHiveDecimal(r, (DecimalTypeInfo) primitiveTypeInfo);
    default:
        throw new Error("Unknown primitive category " + primitiveCategory);
    }
}

From source file:org.mifos.application.servicefacade.SavingsServiceFacadeWebTier.java

@Override
public void deposit(SavingsDepositDto savingsDeposit) {

    MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    UserContext userContext = toUserContext(user);

    SavingsBO savingsAccount = this.savingsDao.findById(savingsDeposit.getSavingsId());

    try {// w w w  .ja  va  2s  .  c  o m
        personnelDao.checkAccessPermission(userContext, savingsAccount.getOfficeId(),
                savingsAccount.getCustomer().getLoanOfficerId());
    } catch (AccountException e) {
        throw new MifosRuntimeException(e.getMessage(), e);
    }

    savingsAccount.updateDetails(userContext);

    PersonnelBO createdBy = this.personnelDao.findPersonnelById(Short.valueOf((short) user.getUserId()));
    CustomerBO customer = this.customerDao.findCustomerById(savingsDeposit.getCustomerId().intValue());

    Money totalAmount = new Money(savingsAccount.getCurrency(), BigDecimal.valueOf(savingsDeposit.getAmount()));
    PaymentData payment = PaymentData.createPaymentData(totalAmount, createdBy,
            savingsDeposit.getModeOfPayment().shortValue(),
            savingsDeposit.getDateOfDeposit().toDateMidnight().toDate());
    if (savingsDeposit.getDateOfReceipt() != null) {
        payment.setReceiptDate(savingsDeposit.getDateOfReceipt().toDateMidnight().toDate());
    }
    payment.setReceiptNum(savingsDeposit.getReceiptId());
    payment.setCustomer(customer);

    for (AccountActionDateEntity installment : savingsAccount
            .getTotalInstallmentsDue(savingsDeposit.getCustomerId().intValue())) {
        AccountPaymentData accountPaymentData = new SavingsPaymentData(installment);
        payment.addAccountPaymentData(accountPaymentData);
    }

    try {
        this.transactionHelper.startTransaction();
        this.transactionHelper.beginAuditLoggingFor(savingsAccount);
        savingsAccount.applyPayment(payment);

        this.savingsDao.save(savingsAccount);
        this.transactionHelper.commitTransaction();
    } catch (AccountException e) {
        this.transactionHelper.rollbackTransaction();
        throw new BusinessRuleException(e.getKey(), e);
    } finally {
        this.transactionHelper.closeSession();
    }
}

From source file:com.neovisionaries.security.DigestTest.java

@Test
public void test17() {
    List<Short> list = new ArrayList<Short>();
    list.add(Short.valueOf((short) 10));
    list.add(Short.valueOf((short) 20));
    list.add(Short.valueOf((short) 30));

    String digest1 = md5().update(list).digestAsString();

    String digest2 = md5().update((short) 10).update((short) 20).update((short) 30).digestAsString();

    String digest3 = md5().update(new short[] { 10, 20, 30 }).digestAsString();

    String digest4 = md5().update((short) 10, (short) 20, (short) 30).digestAsString();

    assertEquals(digest1, digest2);//from   w ww  .  j  a va  2  s . c o m
    assertEquals(digest1, digest3);
    assertEquals(digest1, digest4);
}

From source file:org.eclipse.dataset.ShortDataset.java

@Override
public Object getObject(final int i) {
    return Short.valueOf(get(i)); // CLASS_TYPE
}

From source file:org.mifos.accounts.productdefinition.struts.actionforms.LoanPrdActionFormTest.java

@Test
public void shouldNotAllowPeriodicFeeForVariableInstallmentLoanProduct() {
    String PERIODIC_FEE_2 = "2";
    String NON_PERIODIC_FEE = "3";

    when(periodicFeeRate.isPeriodic()).thenReturn(true);
    when(periodicFeeRate.getFeeType()).thenReturn(RateAmountFlag.RATE);
    when(periodicFeeRate.getFeeId()).thenReturn(Short.valueOf(PERIODIC_FEE_2));
    when(periodicFeeRate.getFeeName()).thenReturn("periodic fee2");

    when(nonPeriodicFeeRate.isPeriodic()).thenReturn(false);
    when(nonPeriodicFeeRate.getFeeType()).thenReturn(RateAmountFlag.RATE);
    when(nonPeriodicFeeRate.getFeeId()).thenReturn(Short.valueOf(NON_PERIODIC_FEE));
    when(nonPeriodicFeeRate.getFeeName()).thenReturn("non Periodic fee");
    when(((RateFeeBO) nonPeriodicFeeRate).getFeeFormula()).thenReturn(feeFormulaEntity);
    when(feeFormulaEntity.getFeeFormula()).thenReturn(FeeFormula.INTEREST);

    List<FeeBO> allPrdFees = new ArrayList<FeeBO>();
    allPrdFees.add(periodicFeeRate);/*from   w  w w.j  av a  2 s .com*/
    allPrdFees.add(nonPeriodicFeeRate);

    when(request.getAttribute(Constants.CURRENTFLOWKEY)).thenReturn(FLOW_KEY);
    when(request.getSession()).thenReturn(session);
    when(session.getAttribute(Constants.FLOWMANAGER)).thenReturn(flowManager);
    when(session.getAttribute(ProductDefinitionConstants.LOANPRDFEE)).thenReturn(allPrdFees);

    Flow flow = new Flow();
    try {
        when(flowManager.getFromFlow(Mockito.anyString(), Mockito.anyString())).thenReturn(allPrdFees);
        when(flowManager.getFlowWithValidation(FLOW_KEY)).thenReturn(flow);
    } catch (PageExpiredException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    ActionMessageMatcher actionMessageMatcher = new ActionMessageMatcher(
            ProductDefinitionConstants.PERIODIC_FEE_NOT_APPLICABLE);

    loanPrdActionForm.setCanConfigureVariableInstallments(true);
    loanPrdActionForm.setPrdOfferinFees(new String[] { PERIODIC_FEE_2, NON_PERIODIC_FEE });

    loanPrdActionForm.validateSelectedFeeForVariableInstallment(request, errors);
    Mockito.verify(errors, Mockito.times(1)).add(Mockito.anyString(), Mockito.argThat(actionMessageMatcher));
}

From source file:org.eclipse.dataset.ShortDataset.java

@Override
public Object getObject(final int i, final int j) {
    return Short.valueOf(get(i, j)); // CLASS_TYPE
}

From source file:org.apache.tuscany.sca.node.launcher.NodeLauncher.java

static Object invoke(Object proxy, String operationName, String... params)
        throws IllegalAccessException, InvocationTargetException {
    for (Method m : proxy.getClass().getMethods()) {
        if (m.getName().equals(operationName) && m.getParameterTypes().length == params.length) {
            Object parameters[] = new Object[params.length];
            int i = 0;
            for (Class<?> type : m.getParameterTypes()) {
                if (type == byte.class || type == Byte.class) {
                    parameters[i] = Byte.valueOf(params[i]);
                } else if (type == char.class || type == Character.class) {
                    parameters[i] = params[i].charAt(0);
                } else if (type == boolean.class || type == Boolean.class) {
                    parameters[i] = Boolean.valueOf(params[i]);
                } else if (type == short.class || type == Short.class) {
                    parameters[i] = Short.valueOf(params[i]);
                } else if (type == int.class || type == Integer.class) {
                    parameters[i] = Integer.valueOf(params[i]);
                } else if (type == long.class || type == Long.class) {
                    parameters[i] = Long.valueOf(params[i]);
                } else if (type == float.class || type == Float.class) {
                    parameters[i] = Float.valueOf(params[i]);
                } else if (type == double.class || type == Double.class) {
                    parameters[i] = Double.valueOf(params[i]);
                } else if (type == String.class) {
                    parameters[i] = params[i];
                } else {
                    throw new IllegalArgumentException("Parameter type is not supported: " + type);
                }//from   w  ww.  j  a v  a 2  s.c  o m
                i++;
            }
            Object result = m.invoke(proxy, parameters);
            return result;
        }
    }
    throw new IllegalArgumentException("Invalid service operation: " + operationName);
}

From source file:org.mifos.accounts.loan.business.LoanBORedoDisbursalIntegrationTest.java

@Ignore
@Test//  w w  w  .  ja  v a  2 s .  c om
public void testRedoLoanApplyWholeMiscPenaltyAfterPartialPayment() 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_PENALTY), 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, 0.0, 33.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:org.eclipse.dataset.ShortDataset.java

@Override
public Object getObject(final int... pos) {
    return Short.valueOf(get(pos)); // CLASS_TYPE
}