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:org.apache.ojb.broker.util.pooling.PoolConfiguration.java

public byte getWhenExhaustedAction() {
    return new Byte(getProperty(WHEN_EXHAUSTED_ACTION)).byteValue();
}

From source file:org.goko.controller.grbl.v08.GrblCommunicator.java

/**
 * Add the end line character at the end of the given list
 * @param list the list/*  ww  w  .j a va 2s  . com*/
 */
private void addEndLineCharacter(List<Byte> list) {
    //command.add(new Byte((byte) endLineCharDelimiter));
    list.add(new Byte((byte) endLineCharDelimiter));
}

From source file:de.odysseus.calyxo.base.util.ParseUtils.java

public void testObject() throws Exception {
        assertEquals(Boolean.TRUE, ParseUtils.parse(Boolean.class, "true"));
        assertEquals(Boolean.FALSE, ParseUtils.parse(Boolean.class, "false"));
        assertEquals(new Character((char) 10), ParseUtils.parse(Character.class, "\n"));
        assertEquals(new Byte((byte) 10), ParseUtils.parse(Byte.class, "10"));
        assertEquals(new Short((short) 10), ParseUtils.parse(Short.class, "10"));
        assertEquals(new Integer(10), ParseUtils.parse(Integer.class, "10"));
        assertEquals(new Long(10), ParseUtils.parse(Long.class, "10"));
        assertEquals(new Float(10), ParseUtils.parse(Float.class, "10"));
        assertEquals(new Double(10), ParseUtils.parse(Double.class, "10"));
        assertEquals(new BigInteger("10"), ParseUtils.parse(BigInteger.class, "10"));
        assertEquals(new BigDecimal(10), ParseUtils.parse(BigDecimal.class, "10"));
        assertEquals(new Date(0), ParseUtils.parse(Date.class, "1/1/70"));
        assertEquals("foo", ParseUtils.parse(String.class, "foo"));
    }/*  w w  w .  j av  a  2 s.c o m*/

From source file:kr.re.dev.LikeAA.LikeAA.java

@SuppressLint("UseValueOf")
private Object[] makeEmptyArgs(Class<?>[] params) {
    Object[] args = new Object[params.length];
    for (int i = 0, n = params.length; i < n; ++i) {
        if (params[i].isAssignableFrom(byte.class))
            args[i] = new Byte((byte) 0);
        else if (params[i].isAssignableFrom(boolean.class))
            args[i] = new Boolean(false);
        else if (params[i].isAssignableFrom(char.class))
            args[i] = new Character((char) 0);
        else if (params[i].isAssignableFrom(int.class))
            args[i] = new Integer(0);
        else if (params[i].isAssignableFrom(float.class))
            args[i] = new Float(0.0f);
        else if (params[i].isAssignableFrom(long.class))
            args[i] = new Long(0);
        else if (params[i].isAssignableFrom(double.class))
            args[i] = new Double(0);
        else/*  w ww .  j  av a 2  s .  c o m*/
            args[i] = null;
    }
    return args;
}

From source file:org.castor.jdo.engine.SQLTypeInfos.java

/**
 * Get value from given ResultSet at given index with given SQL type.
 * // w  w  w .j  ava2  s.  co m
 * @param rs The ResultSet to get the value from.
 * @param index The index of the value in the ResultSet.
 * @param sqlType The SQL type of the value.
 * @return The value.
 * @throws SQLException If a database access error occurs.
 */
public static Object getValue(final ResultSet rs, final int index, final int sqlType) throws SQLException {
    switch (sqlType) {
    case Types.CHAR:
    case Types.VARCHAR:
    case Types.LONGVARCHAR:
        return rs.getString(index);
    case Types.DECIMAL:
    case Types.NUMERIC:
        return rs.getBigDecimal(index);
    case Types.INTEGER:
        int intVal = rs.getInt(index);
        return (rs.wasNull() ? null : new Integer(intVal));
    case Types.TIME:
        return rs.getTime(index, getCalendar());
    case Types.DATE:
        return rs.getDate(index);
    case Types.TIMESTAMP:
        return rs.getTimestamp(index, getCalendar());
    case Types.FLOAT:
    case Types.DOUBLE:
        double doubleVal = rs.getDouble(index);
        return (rs.wasNull() ? null : new Double(doubleVal));
    case Types.REAL:
        float floatVal = rs.getFloat(index);
        return (rs.wasNull() ? null : new Float(floatVal));
    case Types.SMALLINT:
        short shortVal = rs.getShort(index);
        return (rs.wasNull() ? null : new Short(shortVal));
    case Types.TINYINT:
        byte byteVal = rs.getByte(index);
        return (rs.wasNull() ? null : new Byte(byteVal));
    case Types.LONGVARBINARY:
    case Types.VARBINARY:
    case Types.BINARY:
        return rs.getBytes(index);
    case Types.BLOB:
        Blob blob = rs.getBlob(index);
        return (blob == null ? null : blob.getBinaryStream());
    case Types.CLOB:
        return rs.getClob(index);
    case Types.BIGINT:
        long longVal = rs.getLong(index);
        return (rs.wasNull() ? null : new Long(longVal));
    case Types.BIT:
        boolean boolVal = rs.getBoolean(index);
        return (rs.wasNull() ? null : new Boolean(boolVal));
    default:
        Object value = rs.getObject(index);
        return (rs.wasNull() ? null : value);
    }
}

From source file:org.latticesoft.util.resource.dao.Param.java

private Object readValue(ResultSet rs) throws SQLException {
    Object retVal = null;//from  ww  w. j  a v a 2  s .  c o m
    switch (this.sqlType) {
    case Types.VARCHAR:
    case Types.CHAR:
        String s = null;
        if (this.getSqlIndex() == 0) {
            s = rs.getString(this.getSqlName());
        } else {
            s = rs.getString(this.getSqlIndex());
        }
        retVal = s;
        break;
    case Types.BOOLEAN:
        boolean b = false;
        if (this.getSqlIndex() == 0) {
            b = rs.getBoolean(this.getSqlName());
        } else {
            b = rs.getBoolean(this.getSqlIndex());
        }
        retVal = new Boolean(b);
        break;
    case Types.INTEGER:
        int i = 0;
        if (this.getSqlIndex() == 0) {
            i = rs.getInt(this.getSqlName());
        } else {
            i = rs.getInt(this.getSqlIndex());
        }
        retVal = new Integer(i);
        break;
    case Types.SMALLINT:
        short ss = 0;
        if (this.getSqlIndex() == 0) {
            ss = rs.getShort(this.getSqlName());
        } else {
            ss = rs.getShort(this.getSqlIndex());
        }
        retVal = new Short(ss);
        break;
    case Types.TINYINT:
        byte bb = 0;
        if (this.getSqlIndex() == 0) {
            bb = rs.getByte(this.getSqlName());
        } else {
            bb = rs.getByte(this.getSqlIndex());
        }
        retVal = new Byte(bb);
        break;
    case Types.BIGINT:
        long l = 0;
        if (this.getSqlIndex() == 0) {
            l = rs.getLong(this.getSqlName());
        } else {
            l = rs.getLong(this.getSqlIndex());
        }
        retVal = new Long(l);
        break;
    case Types.DOUBLE:
        double dd = 0;
        if (this.getSqlIndex() == 0) {
            dd = rs.getDouble(this.getSqlName());
        } else {
            dd = rs.getDouble(this.getSqlIndex());
        }
        retVal = new Double(dd);
        break;
    case Types.FLOAT:
        float f = 0;
        if (this.getSqlIndex() == 0) {
            f = rs.getFloat(this.getSqlName());
        } else {
            f = rs.getFloat(this.getSqlIndex());
        }
        retVal = new Float(f);
        break;
    case Types.NUMERIC:
        BigDecimal bd = null;
        if (this.getSqlIndex() == 0) {
            bd = rs.getBigDecimal(this.getSqlName());
        } else {
            bd = rs.getBigDecimal(this.getSqlIndex());
        }
        retVal = bd;
        break;
    case Types.TIMESTAMP:
        Timestamp ts = null;
        if (this.getSqlIndex() == 0) {
            ts = rs.getTimestamp(this.getSqlName());
        } else {
            ts = rs.getTimestamp(this.getSqlIndex());
        }
        retVal = ts;
        break;
    default:
        if (this.getSqlIndex() == 0) {
            retVal = rs.getObject(this.getSqlName());
        } else {
            retVal = rs.getObject(this.getSqlIndex());
        }
        break;
    }
    if (log.isDebugEnabled()) {
        log.debug(this.getAttribute() + "=" + retVal);
    }
    return retVal;
}

From source file:us.mn.state.health.lims.testanalyte.form.TestAnalyteTestResultActionForm.java

/**
 * <p>//from  ww w . j  a  v a2  s  .  c  o m
 * Return the value of a simple property with the specified name.
 * </p>
 * 
 * @param name
 *            Name of the property whose value is to be retrieved
 * 
 * @exception IllegalArgumentException
 *                if there is no property of the specified name
 * @exception NullPointerException
 *                if the type specified for the property is invalid
 */
public Object get(String name) {

    // Return any non-null value for the specified property
    Object value = dynaValues.get(name);

    //System.out.println("I am in get(String name) " + name + " " + value);
    if (value != null) {
        return (value);
    }

    // Return a null value for a non-primitive property
    Class type = getDynaProperty(name).getType();
    if (type == null) {
        throw new NullPointerException("The type for property " + name + " is invalid");
    }
    if (!type.isPrimitive()) {
        return (value);
    }

    // Manufacture default values for primitive properties
    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 == Double.TYPE) {
        return (new Double(0.0));
    } else if (type == Float.TYPE) {
        return (new Float((float) 0.0));
    } else if (type == Integer.TYPE) {
        return (new Integer(0));
    } else if (type == Long.TYPE) {
        return (new Long(0));
    } else if (type == Short.TYPE) {
        return (new Short((short) 0));
    } else {
        return (null);
    }

}

From source file:org.jboss.dashboard.ui.taglib.formatter.Formatter.java

/**
 * Sets a parameter for the fragment. The object set as parameter value
 * must not be changed during all the execution, otherwise the result won't be
 * as expected. That is, if this object has a method that changes its content,
 * this method must not be called by the Formatter during the service() method.
 * Otherwise, all the rendering performed by the fragmentValue tag will use
 * the *last* version of the object, the one existing after the invocation of
 * service method, which is probably not expected.
 * <p>Example, of a iterating formatter:</p>
 * <code>/*from w  w  w .ja  v  a 2s . co m*/
 * StringBuffer sb = new StringBuffer();<br>
 * for( int i= 0; i<10; i++){<br>
 * sb.delete(0,sb.length())<br>
 * sb.append( i );<br>
 * setAttribute("index",sb);<br>
 * renderFragment("output");<br>
 * }<br>     *
 * </code>
 * will generate an output like :
 * 10 10 10 10 10 10 10 10 10 10
 * while the expected output is:
 * 0 1 2 3 4 5 6 7 8 9
 * <p/>
 * So, use objects and don't change them. This is usually easy to accomplish, by using
 * different instances, in the example above, replace sb.delete(0,sb.length()) with
 * sb = new StringBuffer();
 *
 * @param name  Name of the parameter.
 * @param value It's value. Must not be changed during all the execution.
 */
protected void setAttribute(String name, byte value) {
    if (log.isDebugEnabled())
        log.debug("Setting of attribute " + name + " scheduled.");
    tag.addProcessingInstruction(ProcessingInstruction.getSetParameterInstruction(name, new Byte(value)));
}

From source file:br.bookmark.db.util.ResultSetUtils.java

/**
 * Map JDBC objects to Java equivalents.
 * Used by getBean() and getBeans().// w w  w .  j  a  v  a 2s .  c o  m
 * <p>
 * Some types not supported.
 * Many not work with all drivers.
 * <p>
 * Makes binary conversions of BIGINT, DATE, DECIMAL, DOUBLE, FLOAT, INTEGER,
 * REAL, SMALLINT, TIME, TIMESTAMP, TINYINT.
 * Makes Sting conversions of CHAR, CLOB, VARCHAR, LONGVARCHAR, BLOB, LONGVARBINARY,
 * VARBINARY.
 * <p>
 * DECIMAL, INTEGER, SMALLINT, TIMESTAMP, CHAR, VARCHAR tested with MySQL and Poolman.
 * Others not guaranteed.
 * @param classeDestino 
 * @throws NoSuchFieldException 
 * @throws SecurityException 
 */
private static void putEntry(Map properties, ResultSetMetaData metaData, ResultSet resultSet, int i,
        Class classeDestino) throws Exception {

    /*
    In a perfect universe, this would be enough
    properties.put(
        metaData.getColumnName(i),
        resultSet.getObject(i));
    But only String, Timestamp, and Integer seem to get through that way.
    */

    String columnName = metaData.getColumnName(i);

    // Testa se  uma FK
    /*Field[] fields = classeDestino.getDeclaredFields();
    for (int j = 0; j < fields.length; j++) {
    if (fields[j].getAnnotation(DBFK.class) != null) {
        properties.put(columnName, resultSet.getString(i));
    }
    }*/
    //System.out.println(i+"-"+metaData.getColumnType(i));
    switch (metaData.getColumnType(i)) {

    // http://java.sun.com/j2se/1.3.0/docs/api/java/sql/Types.html

    case Types.BIGINT:
        properties.put(columnName, new Long(resultSet.getLong(i)));
        break;

    case Types.DATE:
        properties.put(columnName, resultSet.getDate(i));
        break;

    case Types.DECIMAL:
    case Types.DOUBLE:
        properties.put(columnName, new Double(resultSet.getDouble(i)));
        break;

    case Types.FLOAT:
        properties.put(columnName, new Float(resultSet.getFloat(i)));
        break;

    case Types.INTEGER:
        int valor = 0;
        try { // Se o campo esta vazio d erro
            valor = resultSet.getInt(i);
        } catch (SQLException e) {
        }
        properties.put(columnName, new Integer(valor));
        break;

    case Types.REAL:
        properties.put(columnName, new Double(resultSet.getString(i)));
        break;

    case Types.SMALLINT:
        properties.put(columnName, new Short(resultSet.getShort(i)));
        break;

    case Types.TIME:
        properties.put(columnName, resultSet.getTime(i));
        break;

    case Types.TIMESTAMP:
        properties.put(columnName, resultSet.getTimestamp(i));
        break;

    // :FIXME: Throws java.lang.ClassCastException: java.lang.Integer
    // :FIXME: with Poolman and MySQL unless use getString.
    case Types.TINYINT:
        properties.put(columnName, new Byte(resultSet.getString(i)));
        break;

    case Types.CHAR:
    case Types.CLOB:
    case Types.VARCHAR:
    case Types.LONGVARCHAR:
        // :FIXME: Handle binaries differently?
    case Types.BLOB:
    case Types.LONGVARBINARY:
    case Types.VARBINARY:
        properties.put(columnName, resultSet.getString(i));
        break;

    /*
        :FIXME: Add handlers for
        ARRAY
        BINARY
        BIT
        DISTINCT
        JAVA_OBJECT
        NULL
        NUMERIC
        OTHER
        REF
        STRUCT
    */

    // Otherwise, pass as *String property to be converted
    default:
        properties.put(columnName + "String", resultSet.getString(i));
        break;
    } // end switch

}

From source file:org.openamf.io.AMFSerializer.java

protected Object[] convertPrimitiveArrayToObjectArray(Object array) throws IOException {
    Class componentType = array.getClass().getComponentType();

    Object[] result = null;//from   www.  java 2 s. c  o  m

    if (componentType == null) {
        throw new NullPointerException("componentType is null");
    } else if (componentType == Character.TYPE) {
        char[] carray = (char[]) array;
        result = new Object[carray.length];
        for (int i = 0; i < carray.length; i++) {
            result[i] = new Character(carray[i]);
        }
    } else if (componentType == Byte.TYPE) {
        byte[] barray = (byte[]) array;
        result = new Object[barray.length];
        for (int i = 0; i < barray.length; i++) {
            result[i] = new Byte(barray[i]);
        }
    } else if (componentType == Short.TYPE) {
        short[] sarray = (short[]) array;
        result = new Object[sarray.length];
        for (int i = 0; i < sarray.length; i++) {
            result[i] = new Short(sarray[i]);
        }
    } else if (componentType == Integer.TYPE) {
        int[] iarray = (int[]) array;
        result = new Object[iarray.length];
        for (int i = 0; i < iarray.length; i++) {
            result[i] = new Integer(iarray[i]);
        }
    } else if (componentType == Long.TYPE) {
        long[] larray = (long[]) array;
        result = new Object[larray.length];
        for (int i = 0; i < larray.length; i++) {
            result[i] = new Long(larray[i]);
        }
    } else if (componentType == Double.TYPE) {
        double[] darray = (double[]) array;
        result = new Object[darray.length];
        for (int i = 0; i < darray.length; i++) {
            result[i] = new Double(darray[i]);
        }
    } else if (componentType == Float.TYPE) {
        float[] farray = (float[]) array;
        result = new Object[farray.length];
        for (int i = 0; i < farray.length; i++) {
            result[i] = new Float(farray[i]);
        }
    } else if (componentType == Boolean.TYPE) {
        boolean[] barray = (boolean[]) array;
        result = new Object[barray.length];
        for (int i = 0; i < barray.length; i++) {
            result[i] = new Boolean(barray[i]);
        }
    } else {
        throw new IllegalArgumentException("unexpected component type: " + componentType.getClass().getName());
    }

    return result;
}