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.struts.actionforms.EditStatusActionForm.java

private boolean isNewStatusHasFlag() {
    return (Short.valueOf(newStatusId).equals(AccountState.LOAN_CANCELLED.getValue()))
            || (Short.valueOf(newStatusId).equals(AccountState.SAVINGS_CANCELLED.getValue()));
}

From source file:org.apache.rocketmq.jms.msg.RocketMQMessage.java

@Override
public short getShortProperty(String name) throws JMSException {
    if (propertyExists(name)) {
        Object value = getObjectProperty(name);
        return Short.valueOf(value.toString());
    }//from  w w  w . j a  v a  2 s  . co m
    return 0;
}

From source file:RealFunctionValidation.java

public static Object readAndWritePrimitiveValue(final DataInputStream in, final DataOutputStream out,
        final Class<?> type) throws IOException {

    if (!type.isPrimitive()) {
        throw new IllegalArgumentException("type must be primitive");
    }/*from www. j  a  v  a  2s.co  m*/
    if (type.equals(Boolean.TYPE)) {
        final boolean x = in.readBoolean();
        out.writeBoolean(x);
        return Boolean.valueOf(x);
    } else if (type.equals(Byte.TYPE)) {
        final byte x = in.readByte();
        out.writeByte(x);
        return Byte.valueOf(x);
    } else if (type.equals(Character.TYPE)) {
        final char x = in.readChar();
        out.writeChar(x);
        return Character.valueOf(x);
    } else if (type.equals(Double.TYPE)) {
        final double x = in.readDouble();
        out.writeDouble(x);
        return Double.valueOf(x);
    } else if (type.equals(Float.TYPE)) {
        final float x = in.readFloat();
        out.writeFloat(x);
        return Float.valueOf(x);
    } else if (type.equals(Integer.TYPE)) {
        final int x = in.readInt();
        out.writeInt(x);
        return Integer.valueOf(x);
    } else if (type.equals(Long.TYPE)) {
        final long x = in.readLong();
        out.writeLong(x);
        return Long.valueOf(x);
    } else if (type.equals(Short.TYPE)) {
        final short x = in.readShort();
        out.writeShort(x);
        return Short.valueOf(x);
    } else {
        // This should never occur.
        throw new IllegalStateException();
    }
}

From source file:org.andromda.cartridges.database.metafacades.ColumnLogicImpl.java

/**
 * Gets the maximum name length SQL names may be
 *///from   ww w .  ja  v  a2s.  c  o m
private Short getMaxSqlNameLength() {

    return Short.valueOf((String) this.getConfiguredProperty(UMLMetafacadeProperties.MAX_SQL_NAME_LENGTH));

}

From source file:org.apache.hadoop.hive.ql.optimizer.calcite.translator.ExprNodeConverter.java

/**
 * TODO: 1. Handle NULL/*w w w.j  a va  2  s  .c om*/
 */
@Override
public ExprNodeDesc visitLiteral(RexLiteral literal) {
    RelDataType lType = literal.getType();

    switch (literal.getType().getSqlTypeName()) {
    case BOOLEAN:
        return new ExprNodeConstantDesc(TypeInfoFactory.booleanTypeInfo,
                Boolean.valueOf(RexLiteral.booleanValue(literal)));
    case TINYINT:
        return new ExprNodeConstantDesc(TypeInfoFactory.byteTypeInfo,
                Byte.valueOf(((Number) literal.getValue3()).byteValue()));
    case SMALLINT:
        return new ExprNodeConstantDesc(TypeInfoFactory.shortTypeInfo,
                Short.valueOf(((Number) literal.getValue3()).shortValue()));
    case INTEGER:
        return new ExprNodeConstantDesc(TypeInfoFactory.intTypeInfo,
                Integer.valueOf(((Number) literal.getValue3()).intValue()));
    case BIGINT:
        return new ExprNodeConstantDesc(TypeInfoFactory.longTypeInfo,
                Long.valueOf(((Number) literal.getValue3()).longValue()));
    case FLOAT:
    case REAL:
        return new ExprNodeConstantDesc(TypeInfoFactory.floatTypeInfo,
                Float.valueOf(((Number) literal.getValue3()).floatValue()));
    case DOUBLE:
        return new ExprNodeConstantDesc(TypeInfoFactory.doubleTypeInfo,
                Double.valueOf(((Number) literal.getValue3()).doubleValue()));
    case DATE:
        return new ExprNodeConstantDesc(TypeInfoFactory.dateTypeInfo,
                new Date(((Calendar) literal.getValue()).getTimeInMillis()));
    case TIME:
    case TIMESTAMP: {
        Object value = literal.getValue3();
        if (value instanceof Long) {
            value = new Timestamp((Long) value);
        }
        return new ExprNodeConstantDesc(TypeInfoFactory.timestampTypeInfo, value);
    }
    case BINARY:
        return new ExprNodeConstantDesc(TypeInfoFactory.binaryTypeInfo, literal.getValue3());
    case DECIMAL:
        return new ExprNodeConstantDesc(
                TypeInfoFactory.getDecimalTypeInfo(lType.getPrecision(), lType.getScale()),
                literal.getValue3());
    case VARCHAR: {
        int varcharLength = lType.getPrecision();
        // If we cannot use Varchar due to type length restrictions, we use String
        if (varcharLength < 1 || varcharLength > HiveVarchar.MAX_VARCHAR_LENGTH) {
            return new ExprNodeConstantDesc(TypeInfoFactory.stringTypeInfo, literal.getValue3());
        }
        return new ExprNodeConstantDesc(TypeInfoFactory.getVarcharTypeInfo(varcharLength),
                new HiveVarchar((String) literal.getValue3(), varcharLength));
    }
    case CHAR: {
        int charLength = lType.getPrecision();
        // If we cannot use Char due to type length restrictions, we use String
        if (charLength < 1 || charLength > HiveChar.MAX_CHAR_LENGTH) {
            return new ExprNodeConstantDesc(TypeInfoFactory.stringTypeInfo, literal.getValue3());
        }
        return new ExprNodeConstantDesc(TypeInfoFactory.getCharTypeInfo(charLength),
                new HiveChar((String) literal.getValue3(), charLength));
    }
    case INTERVAL_YEAR_MONTH: {
        BigDecimal monthsBd = (BigDecimal) literal.getValue();
        return new ExprNodeConstantDesc(TypeInfoFactory.intervalYearMonthTypeInfo,
                new HiveIntervalYearMonth(monthsBd.intValue()));
    }
    case INTERVAL_DAY_TIME: {
        BigDecimal millisBd = (BigDecimal) literal.getValue();
        // Calcite literal is in millis, we need to convert to seconds
        BigDecimal secsBd = millisBd.divide(BigDecimal.valueOf(1000));
        return new ExprNodeConstantDesc(TypeInfoFactory.intervalDayTimeTypeInfo,
                new HiveIntervalDayTime(secsBd));
    }
    case OTHER:
    default:
        return new ExprNodeConstantDesc(TypeInfoFactory.voidTypeInfo, literal.getValue3());
    }
}

From source file:org.openspaces.rest.utils.ControllerUtils.java

public static Object convertPropertyToPrimitiveType(String object, Class type, String propKey) {
    if (type.equals(Long.class) || type.equals(Long.TYPE))
        return Long.valueOf(object);

    if (type.equals(Boolean.class) || type.equals(Boolean.TYPE))
        return Boolean.valueOf(object);

    if (type.equals(Integer.class) || type.equals(Integer.TYPE))
        return Integer.valueOf(object);

    if (type.equals(Byte.class) || type.equals(Byte.TYPE))
        return Byte.valueOf(object);

    if (type.equals(Short.class) || type.equals(Short.TYPE))
        return Short.valueOf(object);

    if (type.equals(Float.class) || type.equals(Float.TYPE))
        return Float.valueOf(object);

    if (type.equals(Double.class) || type.equals(Double.TYPE))
        return Double.valueOf(object);

    if (type.isEnum())
        return Enum.valueOf(type, object);

    if (type.equals(String.class) || type.equals(Object.class))
        return String.valueOf(object);

    if (type.equals(java.util.Date.class)) {
        try {/*from   ww w. j a  va2 s  . co m*/
            return simpleDateFormat.parse(object);
        } catch (ParseException e) {
            throw new RestException(
                    "Unable to parse date [" + object + "]. Make sure it matches the format: " + date_format);
        }
    }

    //unknown type
    throw new UnsupportedTypeException("Non primitive type when converting property [" + propKey + "]:" + type);
}

From source file:com.nps.micro.view.TestsSectionFragment.java

@Override
protected View buildRootView(LayoutInflater inflater, ViewGroup container) {
    View rootView = inflater.inflate(layout, container, false);

    runButton = (Button) rootView.findViewById(R.id.runButton);
    runButton.setOnClickListener(new OnClickListener() {
        @Override//from   w  w w. ja  va 2 s.c o m
        public void onClick(View v) {
            prepareScenarios();
        }
    });

    repeatsInput = (EditText) rootView.findViewById(R.id.repeatsInput);
    repeatsInput.setText(String.valueOf(model.getRepeats()));
    repeatsInput.addTextChangedListener(new TextWatcher() {
        @Override
        public void afterTextChanged(Editable s) {
            String val = s.toString();
            if (!val.isEmpty() && StringUtils.isNumeric(val)) {
                model.setRepeats(Integer.valueOf(s.toString()));
            }
        }

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
        }
    });

    repeatsButton = (Button) rootView.findViewById(R.id.setRepeatsButton);
    repeatsButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
            builder.setTitle(R.string.repeats).setItems(R.array.repeats_array,
                    new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int which) {
                            repeatsInput.setText(getResources().getStringArray(R.array.repeats_array)[which]);
                            dialog.dismiss();
                        }
                    });
            AlertDialog alert = builder.create();
            alert.show();
        }
    });

    outSizeInput = (EditText) rootView.findViewById(R.id.packetOutSizeInput);
    outSizeInput.setText(String.valueOf(model.getStreamOutSize()));
    outSizeInput.addTextChangedListener(new TextWatcher() {
        @Override
        public void afterTextChanged(Editable s) {
            String val = s.toString();
            if (!val.isEmpty() && StringUtils.isNumeric(val)) {
                model.setStreamOutSize(Short.valueOf(s.toString()));
            }
        }

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
        }
    });

    outSizeButton = (Button) rootView.findViewById(R.id.setOutSizeButton);
    outSizeButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
            builder.setTitle(R.string.out_size).setItems(R.array.out_size_array,
                    new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int which) {
                            outSizeInput.setText(getResources().getStringArray(R.array.out_size_array)[which]);
                            dialog.dismiss();
                        }
                    });
            AlertDialog alert = builder.create();
            alert.show();
        }
    });

    inSizeInput = (EditText) rootView.findViewById(R.id.packetInSizeInput);
    inSizeInput.setText(String.valueOf(model.getStreamInSizes()[0]));
    inSizeInput.addTextChangedListener(new TextWatcher() {
        @Override
        public void afterTextChanged(Editable s) {
            String[] vals = s.toString().split(" ");
            List<Short> intVals = new ArrayList<Short>();
            for (String val : vals) {
                try {
                    intVals.add(Short.valueOf(val));
                } catch (NumberFormatException e) {
                    // TODO Auto-generated catch block
                }
            }
            short[] array = new short[intVals.size()];
            for (int i = 0; i < intVals.size(); i++)
                array[i] = intVals.get(i);
            model.setStreamInSize(array);
        }

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
        }
    });

    inSizeButton = (Button) rootView.findViewById(R.id.setInSizeButton);
    inSizeButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
            builder.setTitle(R.string.in_size).setItems(R.array.in_size_array,
                    new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int which) {
                            inSizeInput.setText(getResources().getStringArray(R.array.in_size_array)[which]);
                            dialog.dismiss();
                        }
                    });
            AlertDialog alert = builder.create();
            alert.show();
        }
    });

    radioStorageGroup = (RadioGroup) rootView.findViewById(R.id.storageRadioGroup);
    externalStorageRadio = (RadioButton) rootView.findViewById(R.id.externalStorageRadio);
    internalStorageRadio = (RadioButton) rootView.findViewById(R.id.internalStorageRadio);
    switch (model.getStorageType()) {
    case EXTERNAL:
        externalStorageRadio.setChecked(true);
        break;
    case INTERNAL:
        internalStorageRadio.setChecked(true);
        break;
    }
    externalStorageRadio.setEnabled(model.isSaveStreams() || model.isSaveLogs());
    internalStorageRadio.setEnabled(model.isSaveStreams() || model.isSaveLogs());

    radioStorageGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(RadioGroup group, int checkedId) {
            switch (checkedId) {
            case R.id.internalStorageRadio:
                model.setStorageType(Storage.Type.INTERNAL);
                break;
            case R.id.externalStorageRadio:
                model.setStorageType(Storage.Type.EXTERNAL);
                break;
            }
        }
    });

    saveLogsCheckBox = (CheckBox) rootView.findViewById(R.id.saveLogsCheckBox);
    saveLogsCheckBox.setChecked(model.isSaveLogs());
    saveLogsCheckBox.setOnCheckedChangeListener(new OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            model.setSaveLogs(isChecked);
            externalStorageRadio.setEnabled(model.isSaveStreams() || model.isSaveLogs());
            internalStorageRadio.setEnabled(model.isSaveStreams() || model.isSaveLogs());

        }
    });

    streamBufferSizeInput = (EditText) rootView.findViewById(R.id.bufferSizeEditText);
    streamBufferSizeInput.setText(String.valueOf(model.getStreamBufferSize()));
    streamBufferSizeInput.addTextChangedListener(new TextWatcher() {
        @Override
        public void afterTextChanged(Editable s) {
            String val = s.toString();
            if (!val.isEmpty() && StringUtils.isNumeric(val)) {
                model.setStreamBufferSize(Integer.valueOf(s.toString()));
            }
        }

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
        }
    });

    memoryUnitSpinner = (Spinner) rootView.findViewById(R.id.memoryUnitSpinner);
    memoryUnitSpinner.setSelection(model.getStreamBufferUnit().getIndex());
    memoryUnitSpinner.setOnItemSelectedListener(new OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) {
            model.setStreamBufferUnit(MemoryUnit.fromIndex(pos));
        }

        @Override
        public void onNothingSelected(AdapterView<?> parent) {
            // do nothing
        }
    });

    saveStreamCheckBox = (CheckBox) rootView.findViewById(R.id.saveStreamDataCheckbox);
    saveStreamCheckBox.setChecked(model.isSaveStreams());
    streamBufferSizeInput.setEnabled(saveStreamCheckBox.isChecked());
    memoryUnitSpinner.setEnabled(saveStreamCheckBox.isChecked());
    streamQueueSize = (EditText) rootView.findViewById(R.id.streamQueueSize);
    streamQueueSize.setText(String.valueOf(model.getStreamQueueSize()));
    streamQueueSize.addTextChangedListener(new TextWatcher() {
        @Override
        public void afterTextChanged(Editable s) {
            String val = s.toString();
            if (!val.isEmpty() && StringUtils.isNumeric(val)) {
                model.setStreamQueueSize(Integer.valueOf(s.toString()));
            }
        }

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
        }
    });
    streamQueueSize.setEnabled(model.isSaveStreams() && !model.isAutoStreamQueueSize());
    radioQueueGroup = (RadioGroup) rootView.findViewById(R.id.queueRadioGroup);
    autoStreamQueueSizeRadio = (RadioButton) rootView.findViewById(R.id.autoBufferRadio);
    manualStreamQueueSizeRadio = (RadioButton) rootView.findViewById(R.id.manualBufferRadio);
    if (model.isAutoStreamQueueSize()) {
        autoStreamQueueSizeRadio.setChecked(true);
    } else {
        manualStreamQueueSizeRadio.setChecked(true);
    }
    autoStreamQueueSizeRadio.setEnabled(model.isSaveStreams());
    manualStreamQueueSizeRadio.setEnabled(model.isSaveStreams());
    radioQueueGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(RadioGroup group, int checkedId) {
            switch (checkedId) {
            case R.id.autoBufferRadio:
                model.setAutoStreamQueueSize(true);
                streamQueueSize.setEnabled(false);
                break;
            case R.id.manualBufferRadio:
                model.setAutoStreamQueueSize(false);
                streamQueueSize.setEnabled(true);
                break;
            }
        }
    });

    saveStreamCheckBox.setOnCheckedChangeListener(new OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            model.setSaveStreams(isChecked);
            externalStorageRadio.setEnabled(model.isSaveStreams() || model.isSaveLogs());
            internalStorageRadio.setEnabled(model.isSaveStreams() || model.isSaveLogs());
            streamBufferSizeInput.setEnabled(isChecked);
            memoryUnitSpinner.setEnabled(isChecked);
            autoStreamQueueSizeRadio.setEnabled(model.isSaveStreams());
            manualStreamQueueSizeRadio.setEnabled(model.isSaveStreams());
            streamQueueSize.setEnabled(model.isSaveStreams() && !model.isAutoStreamQueueSize());
        }
    });

    simulateEditText = (EditText) rootView.findViewById(R.id.simulateComputationsEditText);
    simulateEditText.setText(String.valueOf(model.getSimulateComputations()));
    simulateEditText.addTextChangedListener(new TextWatcher() {
        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            model.setSimulateComputations(Short.valueOf(s.toString()));
        }

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        @Override
        public void afterTextChanged(Editable s) {
        }
    });

    normalPriorityCheckBox = (CheckBox) rootView.findViewById(R.id.normalPriorityCheckbox);
    normalPriorityCheckBox.setChecked(model.isNormalThreadPriority());
    normalPriorityCheckBox.setOnCheckedChangeListener(new OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            model.setNormalThreadPriority(isChecked);
        }
    });

    hiPriorityAndroidCheckBox = (CheckBox) rootView.findViewById(R.id.hiAndroidPriorityCheckbox);
    hiPriorityAndroidCheckBox.setChecked(model.isHiAndroidThreadPriority());
    hiPriorityAndroidCheckBox.setOnCheckedChangeListener(new OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            model.setHiAndroidThreadPriority(isChecked);
        }
    });

    hiPriorityJavaCheckBox = (CheckBox) rootView.findViewById(R.id.hiJavaPriorityCheckbox);
    hiPriorityJavaCheckBox.setChecked(model.isHiJavaThreadPriority());
    hiPriorityJavaCheckBox.setOnCheckedChangeListener(new OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            model.setHiJavaThreadPriority(isChecked);
        }
    });

    extendedDevicesCombination = (CheckBox) rootView.findViewById(R.id.extendedDevicesCheckBox);
    extendedDevicesCombination.setChecked(model.isExtendedDevicesCombination());
    extendedDevicesCombination.setOnCheckedChangeListener(new OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            model.setExtendedDevicesCombination(isChecked);
        }
    });

    fastHub = (CheckBox) rootView.findViewById(R.id.fastHubCheckBox);
    fastHub.setChecked(model.isFastHub());
    fastHub.setOnCheckedChangeListener(new OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            model.setFastHub(isChecked);
        }
    });

    autoEnableGraphCheckBox = (CheckBox) rootView.findViewById(R.id.autoEnableGraphCheckBox);
    autoEnableGraphCheckBox.setChecked(model.isAutoEnableGraph());
    autoEnableGraphCheckBox.setOnCheckedChangeListener(new OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            model.setAutoEnableGraph(isChecked);
        }
    });

    createSequenceChooser(rootView);
    createDeviceChooser(rootView, runButton);
    updateStatus(rootView);
    return rootView;
}

From source file:org.mifos.customers.group.struts.action.GroupTransferAction.java

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

    GroupTransferActionForm actionForm = (GroupTransferActionForm) form;
    CustomerBO customerBOInSession = (CustomerBO) SessionUtils.getAttribute(Constants.BUSINESS_KEY, request);
    ClientBO client = this.customerDao.findClientBySystemId(customerBOInSession.getGlobalCustNum());

    checkVersionMismatch(customerBOInSession.getVersionNo(), client.getVersionNo());

    Short loanOfficerId = null;//from  w  ww  .  java 2  s .  co m
    if (StringUtils.isNotBlank(actionForm.getAssignedLoanOfficerId())) {
        loanOfficerId = Short.valueOf(actionForm.getAssignedLoanOfficerId());
    }

    this.clientServiceFacade.removeGroupMembership(customerBOInSession.getGlobalCustNum(), loanOfficerId,
            actionForm.getComment());

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

From source file:org.jbuilt.utils.ValueClosure.java

public Object getConvertedValue(Object newValue, UIComponent component) {
    //      Closure converterClosure = converterClosureMap.get(propertyType);
    //       if(converterClosure != null){
    //          return converterClosure.execute(newValue);
    //      }/* w  ww . j a  v  a 2 s.  co m*/
    //       return newValue;

    // if(newValue == ""){
    // newValue = "0";
    // }
    if (propertyType.isAssignableFrom(Integer.class)) {
        if ("".equals(newValue)) {
            newValue = 0;
        } else {
            newValue = Integer.valueOf((String) newValue);
        }
        return newValue;
    } else if (propertyType.isAssignableFrom(Double.class)) {
        if ("".equals(newValue)) {
            newValue = 0.0;
        } else {
            newValue = Double.valueOf((String) newValue);
        }
        return newValue;
    } else if (propertyType.isAssignableFrom(int.class)) {
        if ("".equals(newValue)) {
            newValue = 0;
        } else {
            newValue = Integer.parseInt((String) newValue);
        }
        return newValue;
    } else if (propertyType.isAssignableFrom(double.class)) {
        if ("".equals(newValue)) {
            newValue = 0.0;
        } else {
            newValue = Double.parseDouble((String) newValue);
        }
        return newValue;
    } else if (propertyType.isAssignableFrom(Float.class)) {
        if ("".equals(newValue)) {
            newValue = 0.0;
        } else {
            newValue = Float.valueOf((String) newValue);
        }
        return newValue;
    } else if (propertyType.isAssignableFrom(Short.class)) {
        if ("".equals(newValue)) {
            newValue = 0;
        } else {
            newValue = Short.valueOf((String) newValue);
        }
        return newValue;
    } else if (propertyType.isAssignableFrom(Long.class)) {
        if ("".equals(newValue)) {
            newValue = 0;
        } else {
            newValue = Long.valueOf((String) newValue);
        }
        return newValue;
    } else if (propertyType.isAssignableFrom(Byte.class)) {
        if ("".equals(newValue)) {
            newValue = 0;
        } else {
            newValue = Byte.valueOf((String) newValue);
        }
        return newValue;
    } else if (propertyType.isAssignableFrom(Date.class)) {
        DateFormat df = new SimpleDateFormat("dd/MM/yyyy");
        Date date = null;
        try {
            date = df.parse((String) newValue);
            // System.out.println("Today = " + df.format(today));
        } catch (ParseException e) {
            e.printStackTrace();
        }
        newValue = date;
        return newValue;
    } else {
        // if no renderer don't need component argument
    }
    return newValue;

}

From source file:org.apache.hadoop.hive.serde2.RegexSerDe.java

@Override
public Object deserialize(Writable blob) throws SerDeException {

    Text rowText = (Text) blob;
    Matcher m = inputPattern.matcher(rowText.toString());

    if (m.groupCount() != numColumns) {
        throw new SerDeException("Number of matching groups doesn't match the number of columns");
    }//from   w w w  . j  a v a 2s  .co  m

    // If do not match, ignore the line, return a row with all nulls.
    if (!m.matches()) {
        unmatchedRowsCount++;
        if (!alreadyLoggedNoMatch) {
            // Report the row if its the first time
            LOG.warn("" + unmatchedRowsCount + " unmatched rows are found: " + rowText);
            alreadyLoggedNoMatch = true;
        }
        return null;
    }

    // Otherwise, return the row.
    for (int c = 0; c < numColumns; c++) {
        try {
            String t = m.group(c + 1);
            TypeInfo typeInfo = columnTypes.get(c);

            // Convert the column to the correct type when needed and set in row obj
            PrimitiveTypeInfo pti = (PrimitiveTypeInfo) typeInfo;
            switch (pti.getPrimitiveCategory()) {
            case STRING:
                row.set(c, t);
                break;
            case BYTE:
                Byte b;
                b = Byte.valueOf(t);
                row.set(c, b);
                break;
            case SHORT:
                Short s;
                s = Short.valueOf(t);
                row.set(c, s);
                break;
            case INT:
                Integer i;
                i = Integer.valueOf(t);
                row.set(c, i);
                break;
            case LONG:
                Long l;
                l = Long.valueOf(t);
                row.set(c, l);
                break;
            case FLOAT:
                Float f;
                f = Float.valueOf(t);
                row.set(c, f);
                break;
            case DOUBLE:
                Double d;
                d = Double.valueOf(t);
                row.set(c, d);
                break;
            case BOOLEAN:
                Boolean bool;
                bool = Boolean.valueOf(t);
                row.set(c, bool);
                break;
            case TIMESTAMP:
                Timestamp ts;
                ts = Timestamp.valueOf(t);
                row.set(c, ts);
                break;
            case DATE:
                Date date;
                date = Date.valueOf(t);
                row.set(c, date);
                break;
            case DECIMAL:
                HiveDecimal bd = HiveDecimal.create(t);
                row.set(c, bd);
                break;
            case CHAR:
                HiveChar hc = new HiveChar(t, ((CharTypeInfo) typeInfo).getLength());
                row.set(c, hc);
                break;
            case VARCHAR:
                HiveVarchar hv = new HiveVarchar(t, ((VarcharTypeInfo) typeInfo).getLength());
                row.set(c, hv);
                break;
            default:
                throw new SerDeException("Unsupported type " + typeInfo);
            }
        } catch (RuntimeException e) {
            partialMatchedRowsCount++;
            if (!alreadyLoggedPartialMatch) {
                // Report the row if its the first row
                LOG.warn("" + partialMatchedRowsCount + " partially unmatched rows are found, "
                        + " cannot find group " + c + ": " + rowText);
                alreadyLoggedPartialMatch = true;
            }
            row.set(c, null);
        }
    }
    return row;
}