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.hellojavaer.testcase.generator.TestCaseGenerator.java

@SuppressWarnings({ "unchecked", "rawtypes" })
private static <T> T produceBean(Class<T> clazz, ControlParam countrolParam, Stack<Class> parseClassList) {
    try {//w ww .j a v a 2  s.co m
        T item = clazz.newInstance();
        for (PropertyDescriptor pd : BeanUtils.getPropertyDescriptors(clazz)) {
            Method writeMethod = pd.getWriteMethod();
            if (writeMethod == null || pd.getReadMethod() == null || //
                    countrolParam.getExcludeFieldList() != null
                            && countrolParam.getExcludeFieldList().contains(pd.getName())//
            ) {//
                continue;
            }
            Class fieldClazz = pd.getPropertyType();
            Long numIndex = countrolParam.getNumIndex();
            // int enumIndex = countrolParam.getEnumIndex();
            Random random = countrolParam.getRandom();
            long strIndex = countrolParam.getStrIndex();
            int charIndex = countrolParam.getCharIndex();
            Calendar time = countrolParam.getTime();
            if (TypeUtil.isBaseType(fieldClazz)) {
                if (TypeUtil.isNumberType(fieldClazz)) {
                    if (fieldClazz == Byte.class) {
                        writeMethod.invoke(item, Byte.valueOf((byte) (numIndex & 0x7F)));
                    } else if (fieldClazz == Short.class) {
                        writeMethod.invoke(item, Short.valueOf((short) (numIndex & 0x7FFF)));
                    } else if (fieldClazz == Integer.class) {
                        writeMethod.invoke(item, Integer.valueOf((int) (numIndex & 0x7FFFFFFF)));
                    } else if (fieldClazz == Long.class) {
                        writeMethod.invoke(item, Long.valueOf((long) numIndex));
                    } else if (fieldClazz == Float.class) {
                        writeMethod.invoke(item, Float.valueOf((float) numIndex));
                    } else if (fieldClazz == Double.class) {
                        writeMethod.invoke(item, Double.valueOf((double) numIndex));
                    } else if (fieldClazz == byte.class) {//
                        writeMethod.invoke(item, (byte) (numIndex & 0x7F));
                    } else if (fieldClazz == short.class) {
                        writeMethod.invoke(item, (short) (numIndex & 0x7FFF));
                    } else if (fieldClazz == int.class) {
                        writeMethod.invoke(item, (int) (numIndex & 0x7FFFFFFF));
                    } else if (fieldClazz == long.class) {
                        writeMethod.invoke(item, (long) numIndex);
                    } else if (fieldClazz == float.class) {
                        writeMethod.invoke(item, (float) numIndex);
                    } else if (fieldClazz == double.class) {
                        writeMethod.invoke(item, (double) numIndex);
                    }
                    numIndex++;
                    if (numIndex < 0) {
                        numIndex &= 0x7FFFFFFFFFFFFFFFL;
                    }
                    countrolParam.setNumIndex(numIndex);
                } else if (fieldClazz == boolean.class) {
                    writeMethod.invoke(item, random.nextBoolean());
                } else if (fieldClazz == Boolean.class) {
                    writeMethod.invoke(item, Boolean.valueOf(random.nextBoolean()));
                } else if (fieldClazz == char.class) {
                    writeMethod.invoke(item, CHAR_RANGE[charIndex]);
                    charIndex++;
                    if (charIndex >= CHAR_RANGE.length) {
                        charIndex = 0;
                    }
                    countrolParam.setCharIndex(charIndex);
                } else if (fieldClazz == Character.class) {
                    writeMethod.invoke(item, Character.valueOf(CHAR_RANGE[charIndex]));
                    charIndex++;
                    if (charIndex >= CHAR_RANGE.length) {
                        charIndex = 0;
                    }
                    countrolParam.setCharIndex(charIndex);
                } else if (fieldClazz == String.class) {
                    if (countrolParam.getUniqueFieldList() != null
                            && countrolParam.getUniqueFieldList().contains(pd.getName())) {
                        StringBuilder sb = new StringBuilder();
                        convertNum(strIndex, STRING_RANGE, countrolParam.getRandom(), sb);
                        writeMethod.invoke(item, sb.toString());
                        strIndex += countrolParam.getStrStep();
                        if (strIndex < 0) {
                            strIndex &= 0x7FFFFFFFFFFFFFFFL;
                        }
                        countrolParam.setStrIndex(strIndex);
                    } else {
                        writeMethod.invoke(item, String.valueOf(CHAR_RANGE[charIndex]));
                        charIndex++;
                        if (charIndex >= CHAR_RANGE.length) {
                            charIndex = 0;
                        }
                        countrolParam.setCharIndex(charIndex);
                    }

                } else if (fieldClazz == Date.class) {
                    writeMethod.invoke(item, time.getTime());
                    time.add(Calendar.DAY_OF_YEAR, 1);
                } else if (fieldClazz.isEnum()) {
                    int index = random.nextInt(fieldClazz.getEnumConstants().length);
                    writeMethod.invoke(item, fieldClazz.getEnumConstants()[index]);
                } else {
                    //
                    throw new RuntimeException("out of countrol Class " + fieldClazz.getName());
                }
            } else {
                parseClassList.push(fieldClazz);
                // TODO ?
                Set<Class> set = new HashSet<Class>(parseClassList);
                if (parseClassList.size() - set.size() <= countrolParam.getRecursiveCycleLimit()) {
                    Object bean = produceBean(fieldClazz, countrolParam, parseClassList);
                    writeMethod.invoke(item, bean);
                }
                parseClassList.pop();
            }
        }
        return item;
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}

From source file:org.codice.ddf.spatial.ogc.csw.catalog.common.source.CswFilterDelegate.java

@Override
public FilterType propertyIsNotEqualTo(String propertyName, short literal) {
    isComparisonOperationSupported(ComparisonOperatorType.NOT_EQUAL_TO);
    propertyName = mapPropertyName(propertyName);
    if (isPropertyQueryable(propertyName)) {
        return cswFilterFactory.buildPropertyIsNotEqualToFilter(propertyName, Short.valueOf(literal), false);
    } else {//from   w  ww .  j  a  va 2 s .  co  m
        return new FilterType();
    }
}

From source file:com.meetup.memcached.NativeHandler.java

protected static Short decodeShort(byte[] b) throws Exception {
    return Short.valueOf((short) decodeInteger(b).intValue());
}

From source file:org.araqne.confdb.file.Importer.java

@SuppressWarnings("unchecked")
private Object removeType(List<Object> l) throws ParseException {
    if (l == null)
        throw new ParseException("list can not be null", 0);

    if (l.size() != 2)
        throw new ParseException("list size should be 2", 0);

    String type = (String) l.get(0);
    Object value = l.get(1);/*from w ww .j  a  v a  2s  . co  m*/

    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ssZ");
    try {

        if (type.equals("string")) {
            return (String) value;
        } else if (type.equals("int")) {
            return (Integer) value;
        } else if (type.equals("long")) {
            return Long.valueOf(value.toString());
        } else if (type.equals("bool")) {
            return (Boolean) value;
        } else if (type.equals("ip4")) {
            return (Inet4Address) Inet4Address.getByName((String) value);
        } else if (type.equals("ip6")) {
            return (Inet6Address) Inet6Address.getByName((String) value);
        } else if (type.equals("double")) {
            return (Double) value;
        } else if (type.equals("float")) {
            return Float.valueOf(value.toString());
        } else if (type.equals("date")) {
            return dateFormat.parse((String) value);
        } else if (type.equals("short")) {
            return Short.valueOf(value.toString());
        } else if (type.equals("map")) {
            Map<String, Object> m = (Map<String, Object>) value;

            for (String name : m.keySet()) {
                List<Object> v = (List<Object>) m.get(name);
                m.put(name, removeType(v));
            }

            return m;
        } else if (type.equals("list")) {
            List<Object> newList = new ArrayList<Object>();
            List<Object> values = (List<Object>) value;
            for (Object o : values)
                newList.add(removeType((List<Object>) o));

            return newList;
        } else if (type.equals("null")) {
            return null;
        } else if (type.equals("blob")) {
            String byteString = (String) value;

            return Base64.decode(byteString);
        } else {
            throw new IllegalArgumentException("unsupported value [" + value + "], type [" + type + "]");
        }
    } catch (UnknownHostException e) {
        throw new IllegalArgumentException("invalid host [" + value + "]", e);
    }
}

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

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

From source file:org.mifos.accounts.savings.struts.action.SavingsDepositWithdrawalAction.java

@TransactionDemarcate(validateAndResetToken = true)
@CloseSession//from  w w w .j a  v a  2s .  c o  m
public ActionForward makePayment(final ActionMapping mapping, final ActionForm form,
        final HttpServletRequest request, @SuppressWarnings("unused") final HttpServletResponse response)
        throws Exception {
    SavingsBO savedAccount = (SavingsBO) SessionUtils.getAttribute(Constants.BUSINESS_KEY, request);
    SavingsBO savings = savingsDao.findById(savedAccount.getAccountId());
    checkVersionMismatch(savedAccount.getVersionNo(), savings.getVersionNo());
    savings.setVersionNo(savedAccount.getVersionNo());

    SavingsDepositWithdrawalActionForm actionForm = (SavingsDepositWithdrawalActionForm) form;
    UserContext uc = (UserContext) SessionUtils.getAttribute(Constants.USER_CONTEXT_KEY, request.getSession());
    Date trxnDate = getDateFromString(actionForm.getTrxnDate(), uc.getPreferredLocale());
    monthClosingServiceFacade.validateTransactionDate(trxnDate);

    Date meetingDate = new CustomerPersistence()
            .getLastMeetingDateForCustomer(savings.getCustomer().getCustomerId());
    boolean repaymentIndependentOfMeetingEnabled = new ConfigurationPersistence()
            .isRepaymentIndepOfMeetingEnabled();
    if (!savings.isTrxnDateValid(trxnDate, meetingDate, repaymentIndependentOfMeetingEnabled)) {
        throw new AccountException(AccountConstants.ERROR_INVALID_TRXN);
    }

    Long savingsId = Long.valueOf(savings.getAccountId());
    Long customerId = Long.valueOf(savings.getCustomer().getCustomerId());
    if (StringUtils.isNotBlank(actionForm.getCustomerId())) {
        customerId = Long.valueOf(actionForm.getCustomerId());
    }

    Locale preferredLocale = uc.getPreferredLocale();
    LocalDate dateOfDepositOrWithdrawalTransaction = new LocalDate(trxnDate);
    Double amount = Double.valueOf(actionForm.getAmount());
    Integer modeOfPayment = Integer.valueOf(actionForm.getPaymentTypeId());
    String receiptId = actionForm.getReceiptId();
    LocalDate dateOfReceipt = null;
    if (StringUtils.isNotBlank(actionForm.getReceiptDate())) {
        dateOfReceipt = new LocalDate(getDateFromString(actionForm.getReceiptDate(), preferredLocale));
    }

    try {
        Short trxnTypeId = Short.valueOf(actionForm.getTrxnTypeId());
        if (trxnTypeId.equals(AccountActionTypes.SAVINGS_DEPOSIT.getValue())) {

            SavingsDepositDto savingsDeposit = new SavingsDepositDto(savingsId, customerId,
                    dateOfDepositOrWithdrawalTransaction, amount, modeOfPayment, receiptId, dateOfReceipt,
                    preferredLocale);
            this.savingsServiceFacade.deposit(savingsDeposit);

        } else if (trxnTypeId.equals(AccountActionTypes.SAVINGS_WITHDRAWAL.getValue())) {

            SavingsWithdrawalDto savingsWithdrawal = new SavingsWithdrawalDto(savingsId, customerId,
                    dateOfDepositOrWithdrawalTransaction, amount, modeOfPayment, receiptId, dateOfReceipt,
                    preferredLocale);
            this.savingsServiceFacade.withdraw(savingsWithdrawal);
        }
    } catch (BusinessRuleException e) {
        throw new AccountException(e.getMessageKey(), e);
    }

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

From source file:com.wavemaker.commons.util.TypeConversionUtils.java

public static Object fromString(Class<?> type, String s, boolean isList) {

    if (isList || !isPrimitiveOrWrapper(type)) {
        if (s == null) {
            return null;
        }//www. j av a2 s. c  o m
        ObjectLiteralParser p = new ObjectLiteralParser(s, type);
        Object o = p.parse();
        return o;
    }

    if (s == null) {
        return null;
    } else if (type == AtomicInteger.class) {
        return null;
    } else if (type == AtomicLong.class) {
        return null;
    } else if (type == BigDecimal.class) {
        return new BigDecimal(s);
    } else if (type == BigInteger.class) {
        return new BigDecimal(s);
    } else if (type == Boolean.class || type == boolean.class) {
        return Boolean.valueOf(s);
    } else if (type == Byte.class || type == byte.class) {
        return Byte.valueOf(s);
    } else if (type == Date.class) {
        if (StringUtils.isNumber(s)) {
            return new Date(Long.parseLong(s));
        } else {
            throw new IllegalArgumentException("Unable to convert " + s + " to " + Date.class.getName());
        }
    } else if (type == java.sql.Date.class) {
        return WMDateDeSerializer.getDate(s);
    } else if (type == Time.class) {
        return WMDateDeSerializer.getDate(s);
    } else if (type == Timestamp.class) {
        if (StringUtils.isNumber(s)) {
            return new Timestamp(Long.valueOf(s));
        } else {
            throw new IllegalArgumentException("Unable to convert " + s + " to " + Timestamp.class.getName());
        }
    } else if (type == LocalDateTime.class) {
        return WMLocalDateTimeDeSerializer.getLocalDateTime(s);
    } else if (type == Double.class || type == double.class) {
        return Double.valueOf(s);
    } else if (type == Float.class || type == float.class) {
        return Float.valueOf(s);
    } else if (type == Integer.class || type == int.class) {
        return Integer.valueOf(s);
    } else if (type == Long.class || type == long.class) {
        return Long.valueOf(s);
    } else if (type == Short.class || type == short.class) {
        return Short.valueOf(s);
    } else if (type == String.class || type == StringBuffer.class) {
        return s;
    } else if (type == Character.class || type == char.class) {
        return Character.valueOf(s.charAt(0));
    } else {
        throw new AssertionError("Unable to convert \"" + s + "\" to " + type + " - unknown type: " + type);
    }
}

From source file:org.cloudata.core.common.io.CObjectWritable.java

/** Read a {@link CWritable}, {@link String}, primitive type, or an array of
 * the preceding. *///w  w  w.j  a v a2s  .com
@SuppressWarnings("unchecked")
public static Object readObject(DataInput in, CObjectWritable objectWritable, CloudataConf conf,
        boolean arrayComponent, Class componentClass) throws IOException {
    String className;
    if (arrayComponent) {
        className = componentClass.getName();
    } else {
        className = CUTF8.readString(in);
        //SANGCHUL
        //   System.out.println("SANGCHUL] className:" + className);
    }

    Class<?> declaredClass = PRIMITIVE_NAMES.get(className);
    if (declaredClass == null) {
        try {
            declaredClass = conf.getClassByName(className);
        } catch (ClassNotFoundException e) {
            //SANGCHUL
            e.printStackTrace();
            throw new RuntimeException("readObject can't find class[className=" + className + "]", e);
        }
    }

    Object instance;

    if (declaredClass.isPrimitive()) { // primitive types

        if (declaredClass == Boolean.TYPE) { // boolean
            instance = Boolean.valueOf(in.readBoolean());
        } else if (declaredClass == Character.TYPE) { // char
            instance = Character.valueOf(in.readChar());
        } else if (declaredClass == Byte.TYPE) { // byte
            instance = Byte.valueOf(in.readByte());
        } else if (declaredClass == Short.TYPE) { // short
            instance = Short.valueOf(in.readShort());
        } else if (declaredClass == Integer.TYPE) { // int
            instance = Integer.valueOf(in.readInt());
        } else if (declaredClass == Long.TYPE) { // long
            instance = Long.valueOf(in.readLong());
        } else if (declaredClass == Float.TYPE) { // float
            instance = Float.valueOf(in.readFloat());
        } else if (declaredClass == Double.TYPE) { // double
            instance = Double.valueOf(in.readDouble());
        } else if (declaredClass == Void.TYPE) { // void
            instance = null;
        } else {
            throw new IllegalArgumentException("Not a primitive: " + declaredClass);
        }

    } else if (declaredClass.isArray()) { // array
        //System.out.println("SANGCHUL] is array");
        int length = in.readInt();
        //System.out.println("SANGCHUL] array length : " + length);
        //System.out.println("Read:in.readInt():" + length);
        if (declaredClass.getComponentType() == Byte.TYPE) {
            byte[] bytes = new byte[length];
            in.readFully(bytes);
            instance = bytes;
        } else if (declaredClass.getComponentType() == ColumnValue.class) {
            instance = readColumnValue(in, conf, declaredClass, length);
        } else {
            Class componentType = declaredClass.getComponentType();

            // SANGCHUL
            //System.out.println("SANGCHUL] componentType : " + componentType.getName());

            instance = Array.newInstance(componentType, length);
            for (int i = 0; i < length; i++) {
                Object arrayComponentInstance = readObject(in, null, conf, !componentType.isArray(),
                        componentType);
                Array.set(instance, i, arrayComponentInstance);
                //Array.set(instance, i, readObject(in, conf));
            }
        }
    } else if (declaredClass == String.class) { // String
        instance = CUTF8.readString(in);
    } else if (declaredClass.isEnum()) { // enum
        instance = Enum.valueOf((Class<? extends Enum>) declaredClass, CUTF8.readString(in));
    } else if (declaredClass == ColumnValue.class) {
        //ColumnValue?  ?? ?? ?  ? ?.
        //? ?   ? ? ? ? . 
        Class instanceClass = null;
        try {
            short typeDiff = in.readShort();
            if (typeDiff == TYPE_DIFF) {
                instanceClass = conf.getClassByName(CUTF8.readString(in));
            } else {
                instanceClass = declaredClass;
            }
        } catch (ClassNotFoundException e) {
            throw new RuntimeException("readObject can't find class", e);
        }
        ColumnValue columnValue = new ColumnValue();
        columnValue.readFields(in);
        instance = columnValue;
    } else { // Writable

        Class instanceClass = null;
        try {
            short typeDiff = in.readShort();
            // SANGCHUL
            //System.out.println("SANGCHUL] typeDiff : " + typeDiff);
            //System.out.println("Read:in.readShort():" + typeDiff);
            if (typeDiff == TYPE_DIFF) {
                // SANGCHUL
                String classNameTemp = CUTF8.readString(in);
                //System.out.println("SANGCHUL] typeDiff : " + classNameTemp);
                instanceClass = conf.getClassByName(classNameTemp);
                //System.out.println("Read:UTF8.readString(in):" + instanceClass.getClass());
            } else {
                instanceClass = declaredClass;
            }
        } catch (ClassNotFoundException e) {

            // SANGCHUL
            e.printStackTrace();
            throw new RuntimeException("readObject can't find class", e);
        }

        CWritable writable = CWritableFactories.newInstance(instanceClass, conf);
        writable.readFields(in);
        //System.out.println("Read:writable.readFields(in)");
        instance = writable;

        if (instanceClass == NullInstance.class) { // null
            declaredClass = ((NullInstance) instance).declaredClass;
            instance = null;
        }
    }

    if (objectWritable != null) { // store values
        objectWritable.declaredClass = declaredClass;
        objectWritable.instance = instance;
    }

    return instance;
}

From source file:com.workday.autoparse.xml.demo.XmlParserTest.java

@Test
public void testMissingAttributesAreNotSet()
        throws ParseException, UnexpectedChildException, UnknownElementException {
    XmlStreamParser parser = XmlStreamParserFactory.newXmlStreamParser();
    InputStream in = getInputStreamOf("missing-attributes.xml");

    DemoModel model = (DemoModel) parser.parseStream(in);

    assertTrue(model.myBoxedBoolean);/*from  w w w .j a v a 2 s  .c  om*/
    assertTrue(model.myPrimitiveBoolean);
    assertEquals(BigDecimal.ONE, model.myBigDecimal);
    assertEquals(BigInteger.TEN, model.myBigInteger);
    assertEquals(-1, model.myPrimitiveByte);
    assertEquals(Byte.valueOf((byte) -1), model.myBoxedByte);
    assertEquals('a', model.myPrimitiveChar);
    assertEquals(Character.valueOf('a'), model.myBoxedChar);
    assertEquals(-1.0, model.myPrimitiveDouble, DOUBLE_E);
    assertEquals(Double.valueOf(-1.0), model.myBoxedDouble);
    assertEquals(-1f, model.myPrimitiveFloat, FLOAT_E);
    assertEquals(Float.valueOf(-1f), model.myBoxedFloat);
    assertEquals(-1, model.myPrimitiveInt);
    assertEquals(Integer.valueOf(-1), model.myBoxedInt);
    assertEquals(-1, model.myPrimitiveLong);
    assertEquals(Long.valueOf(-1), model.myBoxedLong);
    assertEquals(-1, model.myPrimitiveShort);
    assertEquals(Short.valueOf((short) -1), model.myBoxedShort);
    assertEquals("default", model.myString);
    assertEquals("default", model.myTextContent);
}

From source file:org.mifos.accounts.struts.action.ApplyAdjustment.java

@TransactionDemarcate(joinToken = true)
public ActionForward previewAdjustment(ActionMapping mapping, @SuppressWarnings("unused") ActionForm form,
        HttpServletRequest request, @SuppressWarnings("unused") HttpServletResponse response) throws Exception {
    ApplyAdjustmentActionForm appAdjustActionForm = (ApplyAdjustmentActionForm) form;
    appAdjustActionForm.setAdjustData(!appAdjustActionForm.getAdjustcheckbox());

    if (appAdjustActionForm.isAdjustData()) {
        @SuppressWarnings("unchecked")
        List<ListItem<Short>> paymentTypes = (List<ListItem<Short>>) SessionUtils
                .getAttribute(MasterConstants.PAYMENT_TYPE, request);

        Short elementType = Short.valueOf(appAdjustActionForm.getPaymentType());
        for (ListItem<Short> item : paymentTypes) {
            if (item.getId().equals(elementType)) {
                SessionUtils.setAttribute(Constants.ADJUSTMENT_PAYMENT_TYPE, item.getDisplayValue(), request);
            }/* w  w  w . j  av a2s.c  om*/
        }
    }

    if (appAdjustActionForm.getNewAmounts() != null && !appAdjustActionForm.getNewAmounts().isEmpty()) {
        BigDecimal newAmount = BigDecimal.ZERO;
        for (String memberNewAmountString : appAdjustActionForm.getNewAmounts().values()) {
            BigDecimal memberNewAmount = BigDecimal.ZERO;
            if (!StringUtils.isBlank(memberNewAmountString)) {
                memberNewAmount = new BigDecimal(memberNewAmountString);
            }
            newAmount = newAmount.add(memberNewAmount);
        }
        appAdjustActionForm.setAmount(newAmount.toString());
    }

    request.setAttribute("method", "previewAdjustment");
    return mapping.findForward("previewadj_success");
}