Example usage for java.lang Integer shortValue

List of usage examples for java.lang Integer shortValue

Introduction

In this page you can find the example usage for java.lang Integer shortValue.

Prototype

public short shortValue() 

Source Link

Document

Returns the value of this Integer as a short after a narrowing primitive conversion.

Usage

From source file:Main.java

public static void main(String[] args) {
    Integer integerObject = new Integer("1234567");

    short s = integerObject.shortValue();
    System.out.println("short:" + s);

}

From source file:Main.java

public static void main(String[] args) {
    Integer intObj = new Integer("10");
    byte b = intObj.byteValue();
    System.out.println(b);/*from ww  w .  java2s. c o m*/

    short s = intObj.shortValue();
    System.out.println(s);

    int i = intObj.intValue();
    System.out.println(i);

    float f = intObj.floatValue();
    System.out.println(f);

    double d = intObj.doubleValue();
    System.out.println(d);
}

From source file:Main.java

public static Short bytesToInt16(byte bytes[]) {

    Integer value = 0;

    for (int i = 0; (i < 2 && i < bytes.length); ++i) {
        value = value | ((bytes[i] & 0x000000FF) << 8 * i);
    }/*from   w ww.ja  v a2  s  . c  o m*/

    return value.shortValue();
}

From source file:org.mifos.framework.util.helpers.NumberUtils.java

public static Short convertIntegerToShort(Integer intValue) {
    if (intValue == null) {
        return null;
    }/*from   w ww . j ava2 s.  co m*/
    return intValue.shortValue();
}

From source file:org.jkcsoft.java.util.JavaHelper.java

public static boolean equals(Integer obj1, int obj2) {
    boolean eq = false;
    if (obj1 != null) {
        eq = obj1.shortValue() == obj2;
    }/*  w  w  w. j  a  v  a2 s  . c o  m*/
    return eq;
}

From source file:com.github.jessemull.microflex.util.IntegerUtil.java

/**
 * Converts a list of integers to a list of shorts.
 * @param    List<Integer>    list of integers
 * @return                    list of shorts
 *///from w ww . j  ava2  s .c om
public static List<Short> toShortList(List<Integer> list) {

    List<Short> shortList = new ArrayList<Short>();

    for (Integer val : list) {
        if (!OverFlowUtil.shortOverflow(val)) {
            OverFlowUtil.overflowError(val);
        }
        shortList.add(val.shortValue());
    }

    return shortList;

}

From source file:org.diorite.utils.math.ShortRange.java

/**
 * Parses given string to range, string is valid range when contains 2 numbers (second greater than first) and splt char: <br>
 * " - ", " : ", " ; ", ", ", " ", ",", ";", ":", "-"
 *
 * @param string string to parse./*w  w  w .j a  v a2 s.c  o  m*/
 *
 * @return parsed range or null.
 */
public static ShortRange valueOf(String string) {
    if (string.isEmpty()) {
        return null;
    }
    String[] nums = null;
    int i = 0;
    final boolean firstMinus = string.charAt(0) == '-';
    if (firstMinus) {
        string = string.substring(1);
    }
    while ((i < ByteRange.SPLITS.length) && ((nums == null) || (nums.length != 2))) {
        nums = StringUtils.splitByWholeSeparator(string, ByteRange.SPLITS[i++], 2);
    }
    if ((nums == null) || (nums.length != 2)) {
        return null;
    }
    final Integer min = DioriteMathUtils.asInt(firstMinus ? ("-" + nums[0]) : nums[0]);
    if ((min == null) || (min < Short.MIN_VALUE)) {
        return null;
    }
    final Integer max = DioriteMathUtils.asInt(nums[1]);
    if ((max == null) || (max > Short.MAX_VALUE) || (min > max)) {
        return null;
    }
    return new ShortRange(min.shortValue(), max.shortValue());
}

From source file:ConversionUtil.java

public static byte[] convertToByteArray(Object object) throws Exception {

    byte[] returnArray = null;
    Class clazz = object.getClass();
    String clazzName = clazz.getName();

    if (clazz.equals(Integer.class)) {
        Integer aValue = (Integer) object;
        int intValue = aValue.intValue();
        returnArray = convertToByteArray(intValue);
    } else if (clazz.equals(String.class)) {
        String aValue = (String) object;
        returnArray = convertToByteArray(aValue);
    } else if (clazz.equals(Byte.class)) {
        Byte aValue = (Byte) object;
        byte byteValue = aValue.byteValue();
        returnArray = convertToByteArray(byteValue);
    } else if (clazz.equals(Long.class)) {
        Long aValue = (Long) object;
        long longValue = aValue.longValue();
        returnArray = convertToByteArray(longValue);
    } else if (clazz.equals(Short.class)) {
        Short aValue = (Short) object;
        short shortValue = aValue.shortValue();
        returnArray = convertToByteArray(shortValue);
    } else if (clazz.equals(Boolean.class)) {
        Boolean aValue = (Boolean) object;
        boolean booleanValue = aValue.booleanValue();
        returnArray = convertToByteArray(booleanValue);
    } else if (clazz.equals(Character.class)) {
        Character aValue = (Character) object;
        char charValue = aValue.charValue();
        returnArray = convertToByteArray(charValue);
    } else if (clazz.equals(Float.class)) {
        Float aValue = (Float) object;
        float floatValue = aValue.floatValue();
        returnArray = convertToByteArray(floatValue);
    } else if (clazz.equals(Double.class)) {
        Double aValue = (Double) object;
        double doubleValue = aValue.doubleValue();
        returnArray = convertToByteArray(doubleValue);
    } else {/*w  w  w .  j  av  a  2s  .  c  o  m*/

        throw new Exception("Cannot convert object of type " + clazzName);
    }

    return returnArray;
}

From source file:org.mifos.ui.core.controller.ViewFundsPreviewController.java

@RequestMapping(method = RequestMethod.POST)
public ModelAndView processFormSubmit(@RequestParam(value = EDIT_PARAM, required = false) String edit,
        @RequestParam(value = CANCEL_PARAM, required = false) String cancel, FundFormBean formBean,
        BindingResult result, SessionStatus status) {
    String viewName = REDIRECT_TO_ADMIN_SCREEN;
    ModelAndView modelAndView = new ModelAndView();
    if (StringUtils.isNotBlank(edit)) {
        viewName = "editFunds";
        modelAndView.setViewName(viewName);
        modelAndView.addObject("formBean", formBean);
        modelAndView.addObject("previewView", "fundPreview");
    } else if (StringUtils.isNotBlank(cancel)) {
        viewName = REDIRECT_TO_VIEW_FUNDS;
        modelAndView.setViewName(viewName);
        status.setComplete();/*  www.jav  a 2s. co m*/
    } else if (result.hasErrors()) {
        viewName = "fundPreview";
        modelAndView.setViewName(viewName);
        modelAndView.addObject("formBean", formBean);
    } else {
        Integer fundCode = Integer.parseInt(formBean.getId());
        FundDto fundUpdate = fundServiceFacade.getFund(fundCode.shortValue());
        fundUpdate.setName(formBean.getName());
        this.fundServiceFacade.updateFund(fundUpdate);
        viewName = REDIRECT_TO_ADMIN_SCREEN;
        modelAndView.setViewName(viewName);
        status.setComplete();
    }
    return modelAndView;
}

From source file:org.mifos.ui.core.controller.EditFundsController.java

@RequestMapping(method = RequestMethod.GET)
public ModelAndView showFund(HttpServletRequest request) {

    ModelAndView modelAndView = new ModelAndView(FORM_VIEW);

    Integer code = Integer.parseInt(request.getParameter("fundId"));

    FundDto fundDto = fundServiceFacade.getFund(code.shortValue());
    FundFormBean formBean = new FundFormBean();
    formBean.setCodeValue(fundDto.getCode().getValue());
    formBean.setCodeId(fundDto.getCode().getId());
    formBean.setId(fundDto.getId());/*w w w .  j a  va2  s .c om*/
    formBean.setName(fundDto.getName());
    formBean.setOldName(fundDto.getName());

    modelAndView.addObject("formBean", formBean);
    modelAndView.addObject("previewView", "fundPreview");

    return modelAndView;
}