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.swordlord.gozer.datatypeformat.DataTypeHelper.java

/**
 * Return compatible class for typedValue based on untypedValueClass 
 * // ww  w .  j  a v  a  2 s.co  m
 * @param untypedValueClass
 * @param typedValue
 * @return
 */
public static Object fromDataType(Class<?> untypedValueClass, Object typedValue) {
    Log LOG = LogFactory.getLog(DataTypeHelper.class);

    if (typedValue == null) {
        return null;
    }

    if (untypedValueClass == null) {
        return typedValue;
    }

    if (ClassUtils.isAssignable(typedValue.getClass(), untypedValueClass)) {
        return typedValue;
    }

    String strTypedValue = null;
    boolean isStringTypedValue = typedValue instanceof String;

    Number numTypedValue = null;
    boolean isNumberTypedValue = typedValue instanceof Number;

    Boolean boolTypedValue = null;
    boolean isBooleanTypedValue = typedValue instanceof Boolean;

    Date dateTypedValue = null;
    boolean isDateTypedValue = typedValue instanceof Date;

    if (isStringTypedValue) {
        strTypedValue = (String) typedValue;
    }
    if (isNumberTypedValue) {
        numTypedValue = (Number) typedValue;
    }
    if (isBooleanTypedValue) {
        boolTypedValue = (Boolean) typedValue;
    }
    if (isDateTypedValue) {
        dateTypedValue = (Date) typedValue;
    }

    Object v = null;
    if (String.class.equals(untypedValueClass)) {
        v = ObjectUtils.toString(typedValue);
    } else if (BigDecimal.class.equals(untypedValueClass)) {
        if (isStringTypedValue) {
            v = NumberUtils.createBigDecimal(strTypedValue);
        } else if (isNumberTypedValue) {
            v = new BigDecimal(numTypedValue.doubleValue());
        } else if (isBooleanTypedValue) {
            v = new BigDecimal(BooleanUtils.toInteger(boolTypedValue.booleanValue()));
        } else if (isDateTypedValue) {
            v = new BigDecimal(dateTypedValue.getTime());
        }
    } else if (Boolean.class.equals(untypedValueClass)) {
        if (isStringTypedValue) {
            v = BooleanUtils.toBooleanObject(strTypedValue);
        } else if (isNumberTypedValue) {
            v = BooleanUtils.toBooleanObject(numTypedValue.intValue());
        } else if (isDateTypedValue) {
            v = BooleanUtils.toBooleanObject((int) dateTypedValue.getTime());
        }
    } else if (Byte.class.equals(untypedValueClass)) {
        if (isStringTypedValue) {
            v = Byte.valueOf(strTypedValue);
        } else if (isNumberTypedValue) {
            v = new Byte(numTypedValue.byteValue());
        } else if (isBooleanTypedValue) {
            v = new Byte((byte) BooleanUtils.toInteger(boolTypedValue.booleanValue()));
        } else if (isDateTypedValue) {
            v = new Byte((byte) dateTypedValue.getTime());
        }
    } else if (byte[].class.equals(untypedValueClass)) {
        if (isStringTypedValue) {
            v = strTypedValue.getBytes();
        }
    } else if (Double.class.equals(untypedValueClass)) {
        if (isStringTypedValue) {
            v = NumberUtils.createDouble(strTypedValue);
        } else if (isNumberTypedValue) {
            v = new Double(numTypedValue.doubleValue());
        } else if (isBooleanTypedValue) {
            v = new Double(BooleanUtils.toInteger(boolTypedValue.booleanValue()));
        } else if (isDateTypedValue) {
            v = new Double(dateTypedValue.getTime());
        }
    } else if (Float.class.equals(untypedValueClass)) {
        if (isStringTypedValue) {
            v = NumberUtils.createFloat(strTypedValue);
        } else if (isNumberTypedValue) {
            v = new Float(numTypedValue.floatValue());
        } else if (isBooleanTypedValue) {
            v = new Float(BooleanUtils.toInteger(boolTypedValue.booleanValue()));
        } else if (isDateTypedValue) {
            v = new Float(dateTypedValue.getTime());
        }
    } else if (Short.class.equals(untypedValueClass)) {
        if (isStringTypedValue) {
            v = NumberUtils.createInteger(strTypedValue);
        } else if (isNumberTypedValue) {
            v = new Integer(numTypedValue.intValue());
        } else if (isBooleanTypedValue) {
            v = BooleanUtils.toIntegerObject(boolTypedValue.booleanValue());
        } else if (isDateTypedValue) {
            v = new Integer((int) dateTypedValue.getTime());
        }
    } else if (Integer.class.equals(untypedValueClass)) {
        if (isStringTypedValue) {
            v = NumberUtils.createInteger(strTypedValue);
        } else if (isNumberTypedValue) {
            v = new Integer(numTypedValue.intValue());
        } else if (isBooleanTypedValue) {
            v = BooleanUtils.toIntegerObject(boolTypedValue.booleanValue());
        } else if (isDateTypedValue) {
            v = new Integer((int) dateTypedValue.getTime());
        }
    } else if (Long.class.equals(untypedValueClass)) {
        if (isStringTypedValue) {
            v = NumberUtils.createLong(strTypedValue);
        } else if (isNumberTypedValue) {
            v = new Long(numTypedValue.longValue());
        } else if (isBooleanTypedValue) {
            v = new Long(BooleanUtils.toInteger(boolTypedValue.booleanValue()));
        } else if (isDateTypedValue) {
            v = new Long(dateTypedValue.getTime());
        }
    } else if (java.sql.Date.class.equals(untypedValueClass)) {
        if (isNumberTypedValue) {
            v = new java.sql.Date(numTypedValue.longValue());
        } else if (isDateTypedValue) {
            v = new java.sql.Date(dateTypedValue.getTime());
        }
    } else if (java.sql.Time.class.equals(untypedValueClass)) {
        if (isNumberTypedValue) {
            v = new java.sql.Time(numTypedValue.longValue());
        } else if (isDateTypedValue) {
            v = new java.sql.Time(dateTypedValue.getTime());
        }
    } else if (java.sql.Timestamp.class.equals(untypedValueClass)) {
        if (isNumberTypedValue) {
            v = new java.sql.Timestamp(numTypedValue.longValue());
        } else if (isDateTypedValue) {
            v = new java.sql.Timestamp(dateTypedValue.getTime());
        }
    } else if (Date.class.equals(untypedValueClass)) {
        if (isNumberTypedValue) {
            v = new Date(numTypedValue.longValue());
        } else if (isStringTypedValue) {
            try {
                v = DateFormat.getDateInstance().parse(strTypedValue);
            } catch (ParseException e) {
                LOG.error("Unable to parse the date : " + strTypedValue);
                LOG.debug(e.getMessage());
            }
        }
    }
    return v;
}

From source file:ro.cs.cm.common.TextTable.java

public void addRow(String theRow, byte aRowAlign) {
    // dk am speficat ca nu avem nici o linie (doar headerul)
    // nu face nimic
    // adaug inca o linie la matricea tabel
    // log.debug("addRow() -> CurrentRowNo begin = " + currentRowNo);
    if (currentRowNo > MAX_NO_OF_ROWS_ALLOWED) {
        logger.info("No of allowed cols ".concat(String.valueOf(MAX_NO_OF_ROWS_ALLOWED)));
    }/*  w  ww. j a  v  a 2s  .  c om*/
    ArrayList<String> row = new ArrayList<String>();
    StringTokenizer st = new StringTokenizer(theRow, ELEMENT_SEPARATOR);
    rowAlign.add(new Byte(aRowAlign));
    int j = 0;
    boolean amAvutCaracterEndLine = false;
    StringBuffer sb = new StringBuffer();
    while (st.hasMoreElements()) {
        // punem un spatiu in stanga si in dreapta continutului
        sb.delete(0, sb.length()); // resetez StringBufferul
        sb.append(" ");
        String s = (String) st.nextElement();
        if (s.indexOf('\n') != -1) {
            s = s.replace('\n', '?');
            amAvutCaracterEndLine = true;
        }
        sb.append(s);
        sb.append(" ");
        row.add(sb.toString());
    }
    // in cazul in care o linie nu este completa (ca numar de coloane),
    // completez
    if (j < header.length) {
        for (int i = j; i < header.length; row.add(" "), i++) {
            ;
        }
    }
    if (amAvutCaracterEndLine) {
        row.add(" (? = \\n)");
    }
    table.add(row);
    // incrementez variabila statica currentRow pentru
    // a stii nr. de ordine al urmatoarei linii adaugate
    currentRowNo++;
    // log.debug("addRow() -> CurrentRowNo end = " + currentRowNo);
}

From source file:com.baculsoft.beanutils.test.TestBeanUtil2.java

@Test
public void testDescribe() throws Throwable {
    PojoExample pojoSource = new PojoExample();
    pojoSource.setStringProp("String Property");
    pojoSource.setBooleanProp(true);//from   w ww  .j  a v a 2 s.co  m
    pojoSource.setBooleanProp1(Boolean.TRUE);
    pojoSource.setDateProp(new Date());

    pojoSource.setByteProp1(new Byte((byte) 11));
    pojoSource.setByteProp((byte) 11);

    pojoSource.setIntProp1(new Integer(15125));
    pojoSource.setIntProp(155);

    pojoSource.setLongProp1(new Long(20053215235l));
    pojoSource.setLongProp(12325352l);

    pojoSource.setFloatProp1(new Float(20053215235f));
    pojoSource.setFloatProp(498485802.4f);

    pojoSource.setDoubleProp1(new Double(99593884364.25326214));
    pojoSource.setDoubleProp(0.96925326214);

    pojoDescriptor.describe(pojoSource);

    org.apache.commons.beanutils.BeanUtils.describe(pojoSource);

    long t1 = System.currentTimeMillis();
    for (int i = 0; i < 50; i++) {
        pojoDescriptor.describe(pojoSource);

    }
    t1 = System.currentTimeMillis() - t1;
    long t2 = System.currentTimeMillis();
    for (int i = 0; i < 50; i++) {
        org.apache.commons.beanutils.BeanUtils.describe(pojoSource);
    }
    t2 = System.currentTimeMillis() - t2;

    System.out.println("Time to describe ");
    System.out.println("this class : t1 --->" + t1);
    System.out.println("apache commons : t2 --->" + t2);
    System.out.println(pojoDescriptor.describe(pojoSource).equals(pojoDescriptor.describe(pojoSource)));

    assertEquals(pojoDescriptor.describe(pojoSource), pojoDescriptor.describe(pojoSource));
    System.out.println("----------------------------------------------------------");
}

From source file:com.igorbaiborodine.example.mybatis.customer.CustomerServiceImpl.java

@Override
public List<Customer> findCustomersToReward(byte minMonthlyPurchases_, double minDollarAmountPurchased_)
        throws ServiceException {
    List<Customer> customersToReward = new ArrayList<Customer>();
    Integer rewardeesCount;/*  w ww . ja v a 2s .c o m*/

    try {
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("min_monthly_purchases", new Byte(minMonthlyPurchases_));
        params.put("min_dollar_amount_purchased", new Double(minDollarAmountPurchased_));

        customersToReward = _customerMapper.getRewardsReport(params);
        rewardeesCount = (Integer) params.get("count_rewardees");
        _logger.debug(String.format("rewardees count is [%d]", rewardeesCount));
    } catch (Throwable t) {
        String msg = String.format("Cannot retrieve customer to reward list with params [%d,%d]",
                minMonthlyPurchases_, minDollarAmountPurchased_);
        throw new ServiceException(msg, t);
    }
    return customersToReward;
}

From source file:NumberUtil.java

/**
 * Convert an Object to a Byte./*w  ww . ja  v  a  2  s .  c  o  m*/
 */
public static Byte toByte(Object value) {
    if (value == null)
        return null;
    if (value instanceof Byte)
        return (Byte) value;
    if (value instanceof String) {
        if ("".equals((String) value))
            return null;
        return new Byte((String) value);
    }
    if (value instanceof Number)
        return new Byte(((Number) value).byteValue());

    return new Byte(value.toString());
}

From source file:com.judoscript.jamaica.MyUtils.java

public static Object number2object(double val, String typeHint) {
    if (typeHint != null) {
        if (typeHint.equals("double"))
            return new Double(val);
        if (typeHint.equals("float"))
            return new Float((float) val);
        if (typeHint.equals("int"))
            return new Integer((int) val);
        if (typeHint.equals("long"))
            return new Long((long) val);
        if (typeHint.equals("short"))
            return new Short((short) val);
        if (typeHint.equals("char"))
            return new Character((char) val);
        if (typeHint.equals("byte"))
            return new Byte((byte) val);
    }/*from w w w.j  av  a2 s. c om*/
    return new Double(val);
}

From source file:com.espertech.esper.regression.expr.TestBitWiseOperators.java

private void runBitWiseOperators() {
    sendEvent(FIRST_EVENT, new Byte(FIRST_EVENT), SECOND_EVENT, new Short(SECOND_EVENT), FIRST_EVENT,
            new Integer(THIRD_EVENT), 3L, new Long(FOURTH_EVENT), FITH_EVENT, new Boolean(FITH_EVENT));

    EventBean received = listener.getAndResetLastNewData()[0];
    assertEquals((byte) 1, (received.get("myFirstProperty")));
    assertTrue(((Short) (received.get("mySecondProperty")) & SECOND_EVENT) == SECOND_EVENT);
    assertTrue(((Integer) (received.get("myThirdProperty")) & FIRST_EVENT) == FIRST_EVENT);
    assertEquals(7L, (received.get("myFourthProperty")));
    assertEquals(false, (received.get("myFifthProperty")));
}

From source file:com.sm.query.utils.QueryUtils.java

public static Object getParamArg(Class<?> cl) {
    if (!cl.isPrimitive())
        return null;
    else if (boolean.class.equals(cl))
        return Boolean.FALSE;
    else if (byte.class.equals(cl))
        return new Byte((byte) 0);
    else if (short.class.equals(cl))
        return new Short((short) 0);
    else if (char.class.equals(cl))
        return new Character((char) 0);
    else if (int.class.equals(cl))
        return Integer.valueOf(0);
    else if (long.class.equals(cl))
        return Long.valueOf(0);
    else if (float.class.equals(cl))
        return Float.valueOf(0);
    else if (double.class.equals(cl))
        return Double.valueOf(0);
    else//from  w w w . jav a2  s.c  om
        throw new UnsupportedOperationException();
}

From source file:wwutil.jsoda.DataUtil.java

/** Caller should handle custom valueType first before calling this. */
@SuppressWarnings("unchecked")
static Object decodeAttrStrToValue(String attrStr, Class valueType) throws Exception {
    // Set null if input is null.
    if (attrStr == null)
        return null;

    if (valueType == String.class)
        return attrStr; // Return string type as it is.

    // non-String field having "" is treated as null.
    if (attrStr.equals(""))
        return null;

    if (valueType == Byte.class || valueType == byte.class) {
        return new Byte((byte) SimpleDBUtils.decodeZeroPaddingInt(attrStr));
    } else if (valueType == Short.class || valueType == short.class) {
        return new Short((short) SimpleDBUtils.decodeZeroPaddingInt(attrStr));
    } else if (valueType == Integer.class || valueType == int.class) {
        return new Integer(SimpleDBUtils.decodeZeroPaddingInt(attrStr));
    } else if (valueType == Long.class || valueType == long.class) {
        return new Long(SimpleDBUtils.decodeZeroPaddingLong(attrStr));
    } else if (valueType == Float.class || valueType == float.class) {
        return new Float(SimpleDBUtils.decodeZeroPaddingFloat(attrStr));
    } else if (valueType == Double.class || valueType == double.class) {
        return new Double(attrStr);
    } else if (valueType == Boolean.class || valueType == boolean.class) {
        return new Boolean(attrStr);
    } else if (valueType == Character.class || valueType == char.class) {
        return attrStr.charAt(0);
    } else if (valueType == Date.class) {
        return SimpleDBUtils.decodeDate(attrStr);
    } else if (valueType.isEnum()) {
        return Enum.valueOf(valueType, attrStr);
    }/*w  w  w  .j ava  2 s  .  c  o  m*/

    // de-JSONify the rest.
    return fromJson(attrStr, valueType);
}

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

/**
 * DOCUMENT ME!/*  www. j av  a  2  s. co  m*/
 *
 * @param name DOCUMENT ME!
 *
 * @return DOCUMENT ME!
 */
public Object get(String name) {
    Object value = dynaValues.get(name);

    if (value != null) {
        return value;
    }

    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;
}