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:com.vmware.o11n.plugin.powershell.model.RemotePsType.java

private Object convertPrimitiveType(String type, String value) {
    if (type.equals("C")) { //Char
        return (char) Integer.valueOf(value).intValue();
    }//from   ww  w  .  j a  va 2  s .c o m
    if (type.equals("B")) { //Boolean
        return Boolean.valueOf(value);
    }
    if (type.equals("By")) { //UnsignedByte
        return Short.valueOf(value);
    }
    if (type.equals("SB")) { //SignedByte
        return Byte.valueOf(value);
    }
    if (type.equals("U16")) { //UnsignedShort
        return Integer.valueOf(value);
    }
    if (type.equals("I16")) { //SignedShort
        return Short.valueOf(value);
    }
    if (type.equals("U32")) { //UnsignedInt
        return Long.valueOf(value);
    }
    if (type.equals("I32")) { //SignedInt
        return Integer.valueOf(value);
    }
    if (type.equals("I64")) { //SignedLong
        return Long.valueOf(value);
    }
    if (type.equals("Sg")) { //Float
        return Float.valueOf(value);
    }
    if (type.equals("Db")) { //Double
        return Double.valueOf(value);
    } else {
        return value;
    }

}

From source file:org.apache.flink.api.java.utils.ParameterTool.java

/**
 * Returns the Short value for the given key.
 * The method fails if the key does not exist.
 *//*from w w w. j  a  v  a 2  s .  c om*/
public short getShort(String key) {
    addToDefaults(key, null);
    String value = getRequired(key);
    return Short.valueOf(value);
}

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

@Ignore
@Test/*from   w  w  w .jav a 2 s  .co m*/
public void testRedoLoanApplyFractionalMiscPenaltyBeforeRepayments() throws Exception {

    LoanBO loan = redoLoanWithMondayMeetingAndVerify(userContext, 14, new ArrayList<AccountFeesEntity>());
    disburseLoanAndVerify(userContext, loan, 14);

    applyCharge(loan, Short.valueOf(AccountConstants.MISC_PENALTY), new Double("33.7"));

    LoanTestUtils.assertInstallmentDetails(loan, 1, 50.9, 0.1, 0.0, 0.0, 0.0);
    LoanTestUtils.assertInstallmentDetails(loan, 2, 51.2, 0.1, 0.0, 0.0, 33.7);
    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);
}

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

private void assertPreparedStatementResultAsExpected(ResultSet res) throws SQLException {
    assertNotNull(res);//w w  w.  ja v  a  2 s  .  c om

    while (res.next()) {
        assertEquals("2011-03-25", res.getString("ddate"));
        assertEquals("10", res.getString("num"));
        assertEquals((byte) 10, res.getByte("num"));
        assertEquals("2011-03-25", res.getDate("ddate").toString());
        assertEquals(Double.valueOf(10).doubleValue(), res.getDouble("num"), 0.1);
        assertEquals(10, res.getInt("num"));
        assertEquals(Short.valueOf("10").shortValue(), res.getShort("num"));
        assertEquals(10L, res.getLong("num"));
        assertEquals(true, res.getBoolean("bv"));
        Object o = res.getObject("ddate");
        assertNotNull(o);
        o = res.getObject("num");
        assertNotNull(o);
    }
    res.close();
    assertTrue(true);
}

From source file:ezbake.data.elastic.thrift.DateHistogramFacet.java

public Object getFieldValue(_Fields field) {
    switch (field) {
    case FIELD:// ww  w.  ja  v  a  2  s .  c  om
        return getField();

    case INTERVAL:
        return getInterval();

    case FACTOR:
        return Integer.valueOf(getFactor());

    case POST_ZONE_HOURS:
        return Short.valueOf(getPost_zone_hours());

    case PRE_ZONE_HOURS:
        return Short.valueOf(getPre_zone_hours());

    }
    throw new IllegalStateException();
}

From source file:org.mifos.accounts.servicefacade.WebTierAccountServiceFacade.java

@Override
public void applyCharge(Integer accountId, Short chargeId, Double chargeAmount, boolean isPenaltyType) {

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

    try {// w  w w.  ja  va2s .co  m
        AccountBO account = new AccountBusinessService().getAccount(accountId);

        if (account instanceof LoanBO && !account.isGroupLoanAccount()) {
            List<LoanBO> individualLoans = this.loanDao.findIndividualLoans(account.getAccountId());

            if (individualLoans != null && individualLoans.size() > 0) {
                for (LoanBO individual : individualLoans) {
                    individual.updateDetails(userContext);

                    if (isPenaltyType && !chargeId.equals(Short.valueOf(AccountConstants.MISC_PENALTY))) {
                        PenaltyBO penalty = this.penaltyDao.findPenaltyById(chargeId.intValue());
                        individual.addAccountPenalty(
                                new AccountPenaltiesEntity(individual, penalty, chargeAmount));
                    } else {
                        FeeBO fee = this.feeDao.findById(chargeId);

                        if (fee instanceof RateFeeBO) {
                            individual.applyCharge(chargeId, chargeAmount);
                        } else {
                            Double radio = individual.getLoanAmount().getAmount().doubleValue()
                                    / ((LoanBO) account).getLoanAmount().getAmount().doubleValue();

                            individual.applyCharge(chargeId, chargeAmount * radio);
                        }
                    }
                }
            }
        }

        account.updateDetails(userContext);

        CustomerLevel customerLevel = null;
        if (account.isCustomerAccount()) {
            customerLevel = account.getCustomer().getLevel();
        }
        if (account.getPersonnel() != null) {
            checkPermissionForApplyCharges(account.getType(), customerLevel, userContext,
                    account.getOffice().getOfficeId(), account.getPersonnel().getPersonnelId());
        } else {
            checkPermissionForApplyCharges(account.getType(), customerLevel, userContext,
                    account.getOffice().getOfficeId(), userContext.getId());
        }

        this.transactionHelper.startTransaction();

        if (isPenaltyType && account instanceof LoanBO) {
            PenaltyBO penalty = this.penaltyDao.findPenaltyById(chargeId.intValue());
            ((LoanBO) account).addAccountPenalty(new AccountPenaltiesEntity(account, penalty, chargeAmount));
        } else {
            account.applyCharge(chargeId, chargeAmount);
        }

        this.transactionHelper.commitTransaction();
    } catch (ServiceException e) {
        this.transactionHelper.rollbackTransaction();
        throw new MifosRuntimeException(e);
    } catch (ApplicationException e) {
        this.transactionHelper.rollbackTransaction();
        throw new BusinessRuleException(e.getKey(), e);
    }
}

From source file:org.apache.hadoop.hive.kafka.TransactionalKafkaWriter.java

/**
 * Given a query workingDirectory as table_directory/hive_query_id/ will fetch the open transaction states.
 * Table directory is {@link org.apache.hadoop.hive.metastore.api.Table#getSd()#getLocation()}.
 * Hive Query ID is inferred from the JobConf see {@link KafkaStorageHandler#getQueryId()}.
 *
 * The path to a transaction state is as follow.
 * .../{@code queryWorkingDir}/{@code TRANSACTION_DIR}/{@code writerId}/{@code producerEpoch}
 *
 * The actual state is stored in the file {@code producerEpoch}.
 * The file contains a {@link Long} as internal producer Id and a {@link Short} as the producer epoch.
 * According to Kafka API, highest epoch corresponds to the active Producer, therefore if there is multiple
 * {@code producerEpoch} files will pick the maximum based on {@link Short::compareTo}.
 *
 * @param fs File system handler./*from w  ww.j  a  v a2  s. c o  m*/
 * @param queryWorkingDir Query working Directory, see:
 *                        {@link KafkaStorageHandler#getQueryWorkingDir(org.apache.hadoop.hive.metastore.api.Table)}.
 * @return Map of Transaction Ids to Pair of Kafka Producer internal ID (Long) and producer epoch (short)
 * @throws IOException if any of the IO operations fail.
 */
static Map<String, Pair<Long, Short>> getTransactionsState(FileSystem fs, Path queryWorkingDir)
        throws IOException {
    //list all current Dir
    final Path transactionWorkingDir = new Path(queryWorkingDir, TRANSACTION_DIR);
    final FileStatus[] files = fs.listStatus(transactionWorkingDir);
    final Set<FileStatus> transactionSet = Arrays.stream(files).filter(FileStatus::isDirectory)
            .collect(Collectors.toSet());
    Set<Path> setOfTxPath = transactionSet.stream().map(FileStatus::getPath).collect(Collectors.toSet());
    ImmutableMap.Builder<String, Pair<Long, Short>> builder = ImmutableMap.builder();
    setOfTxPath.forEach(path -> {
        final String txId = path.getName();
        try {
            FileStatus[] epochFiles = fs.listStatus(path);
            // List all the Epoch if any and select the max.
            // According to Kafka API recent venison of Producer with the same TxID will have greater epoch and same PID.
            Optional<Short> maxEpoch = Arrays.stream(epochFiles).filter(FileStatus::isFile)
                    .map(fileStatus -> Short.valueOf(fileStatus.getPath().getName())).max(Short::compareTo);
            short epoch = maxEpoch.orElseThrow(() -> new RuntimeException(
                    "Missing sub directory epoch from directory [" + path.toString() + "]"));
            Path openTxFileName = new Path(path, String.valueOf(epoch));
            long internalId;
            try (FSDataInputStream inStream = fs.open(openTxFileName)) {
                internalId = inStream.readLong();
                short fileEpoch = inStream.readShort();
                if (epoch != fileEpoch) {
                    throw new RuntimeException(String.format("Was expecting [%s] but got [%s] from path [%s]",
                            epoch, fileEpoch, path.toString()));
                }
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
            builder.put(txId, Pair.of(internalId, epoch));
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    });
    return builder.build();
}

From source file:org.apache.flink.api.java.utils.ParameterTool.java

/**
 * Returns the Short value for the given key. If the key does not exists it will return the default value given.
 * The method fails if the value is not a Short.
 *///  ww w .j av a2  s  . com
public short getShort(String key, short defaultValue) {
    addToDefaults(key, Short.toString(defaultValue));
    String value = get(key);
    if (value == null) {
        return defaultValue;
    } else {
        return Short.valueOf(value);
    }
}

From source file:org.codice.ddf.spatial.ogc.csw.catalog.converter.CswUnmarshallHelper.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.
 *
 * @param attributeFormat the format of the attribute to be converted
 * @param value the value to be converted
 * @return the value that was extracted from {@code reader} and is of the type described by
 *         {@code attributeFormat}/*from w  w w  . j a  v  a  2 s.c om*/
 */
public static Serializable convertStringValueToMetacardValue(AttributeType.AttributeFormat attributeFormat,
        String value) {
    LOGGER.debug("converting csw record 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 = CswUnmarshallHelper.convertToDate(value);
        break;
    default:
        break;
    }

    return ser;
}

From source file:com.bosscs.spark.commons.utils.Utils.java

public static Object castingUtil(String value, Class classCasting) {
    Object object = value;/*from   w  ww  .j a va 2s . co m*/

    //Numeric
    if (Number.class.isAssignableFrom(classCasting)) {
        if (classCasting.isAssignableFrom(Double.class)) {
            return Double.valueOf(value);
        } else if (classCasting.isAssignableFrom(Long.class)) {
            return Long.valueOf(value);

        } else if (classCasting.isAssignableFrom(Float.class)) {
            return Float.valueOf(value);

        } else if (classCasting.isAssignableFrom(Integer.class)) {
            return Integer.valueOf(value);

        } else if (classCasting.isAssignableFrom(Short.class)) {
            return Short.valueOf(value);

        } else if (classCasting.isAssignableFrom(Byte.class)) {
            return Byte.valueOf(value);
        }
    } else if (String.class.isAssignableFrom(classCasting)) {
        return object.toString();
    }
    //Class not recognise yet
    return null;

}