Example usage for java.lang Byte Byte

List of usage examples for java.lang Byte Byte

Introduction

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

Prototype

@Deprecated(since = "9")
public Byte(String s) throws NumberFormatException 

Source Link

Document

Constructs a newly allocated Byte object that represents the byte value indicated by the String parameter.

Usage

From source file:com.jeeframework.util.validate.GenericTypeValidator.java

/**
 *  Checks if the value can safely be converted to a byte primitive.
 *
 *@param  value   The value validation is being performed on.
 *@param  locale  The locale to use to parse the number (system default if
 *      null)//  w  w  w  . j a va  2 s .c o  m
 *@return the converted Byte value.
 */
public static Byte formatByte(String value, Locale locale) {
    Byte result = null;

    if (value != null) {
        NumberFormat formatter = null;
        if (locale != null) {
            formatter = NumberFormat.getNumberInstance(locale);
        } else {
            formatter = NumberFormat.getNumberInstance(Locale.getDefault());
        }
        formatter.setParseIntegerOnly(true);
        ParsePosition pos = new ParsePosition(0);
        Number num = formatter.parse(value, pos);

        // If there was no error      and we used the whole string
        if (pos.getErrorIndex() == -1 && pos.getIndex() == value.length()) {
            if (num.doubleValue() >= Byte.MIN_VALUE && num.doubleValue() <= Byte.MAX_VALUE) {
                result = new Byte(num.byteValue());
            }
        }
    }

    return result;
}

From source file:jp.co.acroquest.endosnipe.report.converter.util.calc.ByteCalculator.java

public Object sub(Object obj1, Object obj2) {
    Byte byteData1 = (Byte) obj1;
    Byte byteData2 = (Byte) obj2;

    return (Object) (new Byte((byte) (byteData1.byteValue() - byteData2.byteValue())));
}

From source file:org.openmrs.module.sync.SyncUtilTest.java

@Test
public void getSetterMethod_shouldReturnMethodForPrimitiveByte() {
    Method m = SyncUtil.getSetterMethod(new Xform().getClass(), "byteField", new Byte((byte) 1).getClass());
    Assert.notNull(m);//ww w .ja v  a 2  s .  co m
}

From source file:com.jaspersoft.studio.components.chart.model.enums.JFreeChartAxisLocationEnum.java

/**
 *
 */
public Byte getValueByte() {
    return new Byte(value);
}

From source file:MutableByte.java

/**
 * Gets the value as a Byte instance.//from   www  .  j  a  v  a 2 s .  com
 * 
 * @return the value as a Byte
 */
public Object getValue() {
    return new Byte(this.value);
}

From source file:org.istsms.util.Javabean2JSON.java

private static Object getPrimitive(Object value, String type) {
    Object arg = null;/*  w  w  w  . j  a va2s.c o  m*/
    if (type.equals("boolean") || type.equals("java.lang.Boolean")) {

        arg = new Boolean(value.toString());

    } else if (type.equals("byte") || type.equals("java.lang.Byte")) {
        arg = new Byte(value.toString());
    } else if (type.equals("char") || type.equals("java.lang.Character")) {
        arg = new Character((char) value.toString().getBytes()[0]);
    } else if (type.equals("double") || type.equals("java.lang.Double")) {
        arg = new Double(value.toString());
    } else if (type.equals("float") || type.equals("java.lang.Float")) {
        arg = new Float(value.toString());
    } else if (type.equals("int") || type.equals("java.lang.Integer")) {
        arg = new Integer(value.toString());
    } else if (type.equals("long") || type.equals("java.lang.Long")) {
        arg = new Long(value.toString());
    } else if (type.equals("short") || type.equals("java.lang.Short")) {
        arg = new Short(value.toString());
    } else if (type.equals("java.lang.String")) {
        arg = value;
    }
    //      else if (type.equals("java.util.Calendar")) {
    //         java.util.Calendar c=java.util.Calendar.getInstance();
    //         c.setTime(new java.util.Date(Long.parseLong(value.toString())));
    //         arg=c;
    //      }       
    return arg;
}

From source file:com.nfwork.dbfound.json.JSONDynaBean.java

public Object get(String name) {
    Object value = dynaValues.get(name);
    if (value != null) {
        return value;
    }// ww w . j  a va  2s .c o  m

    Class type = getDynaProperty(name).getType();
    if (type == null) {
        throw new NullPointerException("Unspecified property type for " + name);
    }
    if (!type.isPrimitive()) {
        return value;
    }

    if (type == Boolean.TYPE) {
        return Boolean.FALSE;
    } else if (type == Byte.TYPE) {
        return new Byte((byte) 0);
    } else if (type == Character.TYPE) {
        return new Character((char) 0);
    } else if (type == Short.TYPE) {
        return new Short((short) 0);
    } else if (type == Integer.TYPE) {
        return new Integer(0);
    } else if (type == Long.TYPE) {
        return new Long(0);
    } else if (type == Float.TYPE) {
        return new Float(0.0);
    } else if (type == Double.TYPE) {
        return new Double(0);
    }

    return null;
}

From source file:easyJ.common.validate.GenericTypeValidator.java

/**
 * Checks if the value can safely be converted to a byte primitive.
 * //w  w w. j  a  v a 2s  .  co  m
 * @param value
 *                The value validation is being performed on.
 * @param locale
 *                The locale to use to parse the number (system default if
 *                null)
 * @return the converted Byte value.
 */
public static Byte formatByte(String value, Locale locale) {
    Byte result = null;

    if (value != null) {
        NumberFormat formatter = null;
        if (locale != null) {
            formatter = NumberFormat.getNumberInstance(locale);
        } else {
            formatter = NumberFormat.getNumberInstance(Locale.getDefault());
        }
        formatter.setParseIntegerOnly(true);
        ParsePosition pos = new ParsePosition(0);
        Number num = formatter.parse(value, pos);

        // If there was no error and we used the whole string
        if (pos.getErrorIndex() == -1 && pos.getIndex() == value.length()) {
            if (num.doubleValue() >= Byte.MIN_VALUE && num.doubleValue() <= Byte.MAX_VALUE) {
                result = new Byte(num.byteValue());
            }
        }
    }

    return result;
}

From source file:org.joda.primitives.collection.impl.AbstractTestByteCollection.java

public Byte[] getFullNonNullElements() {
    return new Byte[] { new Byte((byte) 2), new Byte((byte) -2), new Byte((byte) 38), new Byte((byte) 0),
            new Byte((byte) 126), new Byte((byte) 202), new Byte(Byte.MIN_VALUE), new Byte(Byte.MAX_VALUE) };
}

From source file:org.jbpm.formModeler.core.processing.fieldHandlers.NumericFieldHandler.java

public Object getTheValue(Field field, String[] paramValue, String desiredClassName) throws Exception {
    if (paramValue == null || paramValue.length == 0)
        return null;

    if (desiredClassName.equals("byte")) {
        if (StringUtils.isEmpty(paramValue[0]))
            return new Byte((byte) 0);
        else/*from w  ww . jav a2  s  .  c  o m*/
            return Byte.decode(paramValue[0]);
    } else if (desiredClassName.equals("short")) {
        if (StringUtils.isEmpty(paramValue[0]))
            return new Short((short) 0);
        else
            return Short.decode(paramValue[0]);
    } else if (desiredClassName.equals("int")) {
        if (StringUtils.isEmpty(paramValue[0]))
            return new Integer(0);
        else
            return Integer.decode(paramValue[0]);
    } else if (desiredClassName.equals("long")) {
        if (StringUtils.isEmpty(paramValue[0]))
            return new Long(0L);
        else
            return Long.decode(paramValue[0]);
    } else if (desiredClassName.equals(Byte.class.getName())) {
        if (StringUtils.isEmpty(paramValue[0]))
            throw new EmptyNumberException();
        return Byte.decode(paramValue[0]);
    } else if (desiredClassName.equals(Short.class.getName())) {
        if (StringUtils.isEmpty(paramValue[0]))
            throw new EmptyNumberException();
        return Short.decode(paramValue[0]);

    } else if (desiredClassName.equals(Integer.class.getName())) {
        if (StringUtils.isEmpty(paramValue[0]))
            throw new EmptyNumberException();
        return Integer.decode(paramValue[0]);

    } else if (desiredClassName.equals(Long.class.getName())) {
        if (StringUtils.isEmpty(paramValue[0]))
            throw new EmptyNumberException();
        return Long.decode(paramValue[0]);

    } else if (desiredClassName.equals(Double.class.getName()) || desiredClassName.equals("double")
            || desiredClassName.equals(Float.class.getName()) || desiredClassName.equals("float")
            || desiredClassName.equals(BigDecimal.class.getName())) {

        if (StringUtils.isEmpty(paramValue[0]))
            throw new EmptyNumberException();

        DecimalFormat df = (DecimalFormat) DecimalFormat.getInstance(new Locale(LocaleManager.currentLang()));
        if (desiredClassName.equals(BigDecimal.class.getName()))
            df.setParseBigDecimal(true);
        String pattern = getFieldPattern(field);
        if (pattern != null && !"".equals(pattern)) {
            df.applyPattern(pattern);
        } else {
            df.applyPattern("###.##");
        }
        ParsePosition pp = new ParsePosition(0);
        Number num = df.parse(paramValue[0], pp);
        if (paramValue[0].length() != pp.getIndex() || num == null) {
            log.debug("Error on parsing value");
            throw new ParseException("Error parsing value", pp.getIndex());
        }

        if (desiredClassName.equals(BigDecimal.class.getName())) {
            return num;
        } else if (desiredClassName.equals(Float.class.getName()) || desiredClassName.equals("float")) {
            return new Float(num.floatValue());
        } else if (desiredClassName.equals(Double.class.getName()) || desiredClassName.equals("double")) {
            return new Double(num.doubleValue());
        }
    } else if (desiredClassName.equals(BigInteger.class.getName())) {
        if (StringUtils.isEmpty(paramValue[0]))
            throw new EmptyNumberException();
        return new BigInteger(paramValue[0]);

    }
    throw new IllegalArgumentException("Invalid class for NumericFieldHandler: " + desiredClassName);
}