Example usage for java.lang Byte valueOf

List of usage examples for java.lang Byte valueOf

Introduction

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

Prototype

public static Byte valueOf(String s) throws NumberFormatException 

Source Link

Document

Returns a Byte object holding the value given by the specified String .

Usage

From source file:org.apache.tajo.engine.parser.SQLAnalyzer.java

public static String escapeDelimiter(String value) {
    try {/*www  . j  a va 2 s  .  co  m*/
        String delimiter = StringEscapeUtils.unescapeJava(value);
        delimiter = new String(new byte[] { Byte.valueOf(delimiter).byteValue() }, Charset.defaultCharset());
        return StringEscapeUtils.escapeJava(delimiter);
    } catch (NumberFormatException e) {
    }
    return value;
}

From source file:org.op4j.functions.FnFloat.java

/**
* <p>/*from   w  ww .jav  a 2s  .c o m*/
* It multiplies target by multiplicand and returns its value. The result is 
* rounded based on the given {@link RoundingMode} 
* </p>
* 
* @param multiplicand the multiplicand
* @param roundingMode the {@link RoundingMode} 
* @return the result of target * multiplicand
*/
public final static Function<Float, Float> multiplyBy(byte multiplicand, RoundingMode roundingMode) {
    return multiplyBy(Byte.valueOf(multiplicand), roundingMode);
}

From source file:se.natusoft.osgi.aps.rpchttpextender.servlet.RPCServlet.java

private String execute(APSExternallyCallable<Object> callable, int noParams, HttpServletRequest request)
        throws IOException {
    try {/*  w  w w .  j a v  a2 s  . c o  m*/
        String paramFail = null;
        Object[] args = new Object[noParams];
        int p = 0;
        for (DataTypeDescription parameter : callable.getParameterDataDescriptions()) {
            String paramValue = request.getParameter("param" + p);
            if (paramValue != null) {
                Object paramJavaValue = null;
                if (paramValue.toLowerCase().equals("true") || paramValue.toLowerCase().equals("false")) {
                    paramJavaValue = Boolean.valueOf(paramValue);
                } else if (paramValue.trim().startsWith("\"")) {
                    paramValue = paramValue.trim().substring(1);
                    paramValue = paramValue.substring(0, paramValue.length() - 1);
                    paramJavaValue = paramValue;
                } else if (paramValue.trim().startsWith("{")) {
                    ByteArrayInputStream bais = new ByteArrayInputStream(paramValue.getBytes());
                    JSONValue jsonObj = this.jsonService.readJSON(bais, null);
                    bais.close();
                    Class javaType = callable.getServiceBundle().loadClass(parameter.getObjectQName());
                    paramJavaValue = this.jsonService.jsonToJava(jsonObj, javaType);
                } else {
                    if (paramValue.indexOf(".") >= 0) {
                        if (parameter.getDataType() == DataType.DOUBLE)
                            paramJavaValue = Double.valueOf(paramValue);
                        else if (parameter.getDataType() == DataType.FLOAT)
                            paramJavaValue = Float.valueOf(paramValue);
                    } else if (parameter.getDataType() == DataType.LONG)
                        paramJavaValue = Long.valueOf(paramValue);
                    else if (parameter.getDataType() == DataType.INT)
                        paramJavaValue = Integer.valueOf(paramValue);
                    else if (parameter.getDataType() == DataType.SHORT)
                        paramJavaValue = Short.valueOf(paramValue);
                    else if (parameter.getDataType() == DataType.BYTE)
                        paramJavaValue = Byte.valueOf(paramValue);
                    else {
                        paramFail = "Did you forget to quote a string value ?";
                    }

                }
                args[p] = paramJavaValue;
            } else {
                paramFail = "Parameter #" + p + " was null!";
            }
            ++p;
        }
        if (paramFail == null) {
            Object result = callable.call(args);
            JSONValue jsonValue = this.jsonService.javaToJSON(result);
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            this.jsonService.writeJSON(baos, jsonValue, false);
            baos.close();
            return "<pre>" + baos.toString() + "</pre>";
        } else {
            return "Bad parameter: " + paramFail;
        }
    } catch (Exception e) {
        return "Failed: " + e.getMessage();
    }
}

From source file:org.op4j.functions.FnShort.java

/**
* <p>// w  w  w . j av  a2 s.c  om
* It multiplies target by multiplicand and returns its value. The result precision
* and {@link RoundingMode} is specified by the given {@link MathContext}
* </p>
* 
* @param multiplicand the multiplicand
* @param mathContext the {@link MathContext} to define {@link RoundingMode} and precision
* @return the result of target * multiplicand
*/
public final static Function<Short, Short> multiplyBy(byte multiplicand, MathContext mathContext) {
    return multiplyBy(Byte.valueOf(multiplicand), mathContext);
}

From source file:kr.ac.korea.dbserver.parser.SQLAnalyzer.java

public static String escapeDelimiter(String value) {
    try {//from ww w  . j  av  a 2 s. c om
        String delimiter = StringEscapeUtils.unescapeJava(value);
        delimiter = new String(new byte[] { Byte.valueOf(delimiter).byteValue() });
        return StringEscapeUtils.escapeJava(delimiter);
    } catch (NumberFormatException e) {
    }
    return value;
}

From source file:org.op4j.functions.FnInteger.java

/**
* <p>/* ww  w  .jav  a  2s. c  o m*/
* It multiplies target by multiplicand and returns its value. The result precision
* and {@link RoundingMode} is specified by the given {@link MathContext}
* </p>
* 
* @param multiplicand the multiplicand
* @param mathContext the {@link MathContext} to define {@link RoundingMode} and precision
* @return the result of target * multiplicand
*/
public final static Function<Integer, Integer> multiplyBy(byte multiplicand, MathContext mathContext) {
    return multiplyBy(Byte.valueOf(multiplicand), mathContext);
}

From source file:net.sf.json.TestJSONObject.java

public void testToBean_ObjectBean() {
    // FR 1611204
    ObjectBean bean = new ObjectBean();
    bean.setPbyte(Byte.valueOf("1"));
    bean.setPshort(Short.valueOf("1"));
    bean.setPint(Integer.valueOf("1"));
    bean.setPlong(Long.valueOf("1"));
    bean.setPfloat(Float.valueOf("1"));
    bean.setPdouble(Double.valueOf("1"));
    bean.setPchar(new Character('1'));
    bean.setPboolean(Boolean.TRUE);
    bean.setPstring("json");
    bean.setParray(new String[] { "a", "b" });
    bean.setPbean(new BeanA());
    List list = new ArrayList();
    list.add("1");
    list.add("2");
    bean.setPlist(list);/*from   w  ww  .ja  va  2 s  . co m*/
    Map map = new HashMap();
    map.put("string", "json");
    bean.setPmap(map);
    bean.setPfunction(new JSONFunction("this;"));
    JSONObject json = JSONObject.fromObject(bean);
    Map classMap = new HashMap();
    classMap.put("pbean", BeanA.class);
    ObjectBean obj = (ObjectBean) JSONObject.toBean(json, ObjectBean.class, classMap);
    assertEquals(Integer.valueOf("1"), obj.getPbyte());
    assertEquals(Integer.valueOf("1"), obj.getPshort());
    assertEquals(Integer.valueOf("1"), obj.getPint());
    assertEquals(Integer.valueOf("1"), obj.getPlong());
    assertEquals(Double.valueOf("1"), obj.getPfloat());
    assertEquals(Double.valueOf("1"), obj.getPdouble());
    assertEquals("1", obj.getPchar());
    assertEquals("json", obj.getPstring());
    List l = new ArrayList();
    l.add("a");
    l.add("b");
    ArrayAssertions.assertEquals(l.toArray(), (Object[]) obj.getParray());
    l = new ArrayList();
    l.add("1");
    l.add("2");
    ArrayAssertions.assertEquals(l.toArray(), (Object[]) obj.getPlist());
    assertEquals(new BeanA(), obj.getPbean());
    assertTrue(obj.getPmap() instanceof MorphDynaBean);
}

From source file:org.op4j.functions.FnBigDecimal.java

/**
 * <p>//from w  ww . j a va  2 s  .c o m
 * It adds the given number to the target and returns the result
 * </p>
 * 
 * @param add value to be added to the target
 * @return the result of the addition of add to the target number
 */
public final static Function<BigDecimal, BigDecimal> add(byte add) {
    return add(Byte.valueOf(add));
}

From source file:org.op4j.functions.FnLong.java

/**
* <p>//from ww w  . j  av a2s  .c  o  m
* It multiplies target by multiplicand and returns its value. The result is 
* rounded based on the given {@link RoundingMode} 
* </p>
* 
* @param multiplicand the multiplicand
* @param roundingMode the {@link RoundingMode} 
* @return the result of target * multiplicand
*/
public final static Function<Long, Long> multiplyBy(byte multiplicand, RoundingMode roundingMode) {
    return multiplyBy(Byte.valueOf(multiplicand), roundingMode);
}

From source file:org.op4j.functions.FnShort.java

/**
* <p>/* ww w.ja va  2 s.com*/
* It multiplies target by multiplicand and returns its value. The result is 
* rounded based on the given {@link RoundingMode} 
* </p>
* 
* @param multiplicand the multiplicand
* @param roundingMode the {@link RoundingMode} 
* @return the result of target * multiplicand
*/
public final static Function<Short, Short> multiplyBy(byte multiplicand, RoundingMode roundingMode) {
    return multiplyBy(Byte.valueOf(multiplicand), roundingMode);
}