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.red5.io.mock.Output.java

/** {@inheritDoc} */
public void writeRecordSet(RecordSet recordset, Serializer serializer) {
    list.add(Byte.valueOf(DataTypes.CORE_OBJECT));
    list.add(recordset);
}

From source file:org.apache.kylin.jdbc.KylinClient.java

public static Object wrapObject(String value, int sqlType) {
    if (null == value) {
        return null;
    }// ww w.j  av  a2s  .c om

    switch (sqlType) {
    case Types.CHAR:
    case Types.VARCHAR:
    case Types.LONGVARCHAR:
        return value;
    case Types.NUMERIC:
    case Types.DECIMAL:
        return new BigDecimal(value);
    case Types.BIT:
        return Boolean.parseBoolean(value);
    case Types.TINYINT:
        return Byte.valueOf(value);
    case Types.SMALLINT:
        return Short.valueOf(value);
    case Types.INTEGER:
        return Integer.parseInt(value);
    case Types.BIGINT:
        return Long.parseLong(value);
    case Types.FLOAT:
        return Float.parseFloat(value);
    case Types.REAL:
    case Types.DOUBLE:
        return Double.parseDouble(value);
    case Types.BINARY:
    case Types.VARBINARY:
    case Types.LONGVARBINARY:
        return value.getBytes();
    case Types.DATE:
        return Date.valueOf(value);
    case Types.TIME:
        return Time.valueOf(value);
    case Types.TIMESTAMP:
        return Timestamp.valueOf(value);
    default:
        //do nothing
        break;

    }

    return value;
}

From source file:org.mili.core.benchmarking.experimental.AnnotatedBench.java

private Object createValue(long lap, Class<?> cls) {
    if (cls == byte.class) {
        return Byte.valueOf((byte) lap);
    } else if (cls == short.class) {
        return Short.valueOf((short) lap);
    } else if (cls == char.class) {
        return (char) lap;
    } else if (cls == int.class) {
        return Integer.valueOf((int) lap);
    } else if (cls == long.class) {
        return lap;
    } else if (cls == double.class) {
        return (double) lap;
    } else if (cls == float.class) {
        return (float) lap;
    } else if (cls == boolean.class) {
        return lap % 2 != 0;
    } else if (cls == String.class) {
        return String.valueOf(lap);
    }/*from  w w  w. jav  a  2  s .co  m*/
    throw new IllegalStateException("parameter class not handled: " + cls);
}

From source file:com.glaf.core.util.Tools.java

public static Object getValue(Class<?> type, String propertyValue) {
    if (type == null || propertyValue == null || propertyValue.trim().length() == 0) {
        return null;
    }//from  w ww  . java2  s. com
    Object value = null;
    try {
        if (type == String.class) {
            value = propertyValue;
        } else if ((type == Integer.class) || (type == int.class)) {
            if (propertyValue.indexOf(',') != -1) {
                propertyValue = propertyValue.replaceAll(",", "");
            }
            value = Integer.parseInt(propertyValue);
        } else if ((type == Long.class) || (type == long.class)) {
            if (propertyValue.indexOf(',') != -1) {
                propertyValue = propertyValue.replaceAll(",", "");
            }
            value = Long.parseLong(propertyValue);
        } else if ((type == Float.class) || (type == float.class)) {
            if (propertyValue.indexOf(',') != -1) {
                propertyValue = propertyValue.replaceAll(",", "");
            }
            value = Float.valueOf(propertyValue);
        } else if ((type == Double.class) || (type == double.class)) {
            if (propertyValue.indexOf(',') != -1) {
                propertyValue = propertyValue.replaceAll(",", "");
            }
            value = Double.parseDouble(propertyValue);
        } else if ((type == Boolean.class) || (type == boolean.class)) {
            value = Boolean.valueOf(propertyValue);
        } else if ((type == Character.class) || (type == char.class)) {
            value = Character.valueOf(propertyValue.charAt(0));
        } else if ((type == Short.class) || (type == short.class)) {
            if (propertyValue.indexOf(',') != -1) {
                propertyValue = propertyValue.replaceAll(",", "");
            }
            value = Short.valueOf(propertyValue);
        } else if ((type == Byte.class) || (type == byte.class)) {
            value = Byte.valueOf(propertyValue);
        } else if (type == java.util.Date.class) {
            value = DateUtils.toDate(propertyValue);
        } else if (type == java.sql.Date.class) {
            value = DateUtils.toDate(propertyValue);
        } else if (type == java.sql.Timestamp.class) {
            value = DateUtils.toDate(propertyValue);
        } else if (type.isAssignableFrom(List.class)) {
        } else if (type.isAssignableFrom(Set.class)) {
        } else if (type.isAssignableFrom(Collection.class)) {
        } else if (type.isAssignableFrom(Map.class)) {
        } else {
            value = propertyValue;
        }
    } catch (Exception ex) {
        throw new RuntimeException(ex);
    }
    return value;
}

From source file:com.evolveum.midpoint.prism.xml.XmlTypeConverter.java

@SuppressWarnings("unchecked")
public static <T> T toJavaValue(String stringContent, Class<T> type, boolean exceptionOnUnknown) {
    if (type.equals(String.class)) {
        return (T) stringContent;
    } else if (type.equals(char.class)) {
        return (T) (new Character(stringContent.charAt(0)));
    } else if (type.equals(File.class)) {
        return (T) new File(stringContent);
    } else if (type.equals(Integer.class)) {
        return (T) Integer.valueOf(stringContent);
    } else if (type.equals(int.class)) {
        return (T) Integer.valueOf(stringContent);
    } else if (type.equals(Short.class) || type.equals(short.class)) {
        return (T) Short.valueOf(stringContent);
    } else if (type.equals(Long.class)) {
        return (T) Long.valueOf(stringContent);
    } else if (type.equals(long.class)) {
        return (T) Long.valueOf(stringContent);
    } else if (type.equals(Byte.class)) {
        return (T) Byte.valueOf(stringContent);
    } else if (type.equals(byte.class)) {
        return (T) Byte.valueOf(stringContent);
    } else if (type.equals(float.class)) {
        return (T) Float.valueOf(stringContent);
    } else if (type.equals(Float.class)) {
        return (T) Float.valueOf(stringContent);
    } else if (type.equals(double.class)) {
        return (T) Double.valueOf(stringContent);
    } else if (type.equals(Double.class)) {
        return (T) Double.valueOf(stringContent);
    } else if (type.equals(BigInteger.class)) {
        return (T) new BigInteger(stringContent);
    } else if (type.equals(BigDecimal.class)) {
        return (T) new BigDecimal(stringContent);
    } else if (type.equals(byte[].class)) {
        byte[] decodedData = Base64.decodeBase64(stringContent);
        return (T) decodedData;
    } else if (type.equals(boolean.class) || Boolean.class.isAssignableFrom(type)) {
        // TODO: maybe we will need more inteligent conversion, e.g. to trim spaces, case insensitive, etc.
        return (T) Boolean.valueOf(stringContent);
    } else if (type.equals(GregorianCalendar.class)) {
        return (T) getDatatypeFactory().newXMLGregorianCalendar(stringContent).toGregorianCalendar();
    } else if (XMLGregorianCalendar.class.isAssignableFrom(type)) {
        return (T) getDatatypeFactory().newXMLGregorianCalendar(stringContent);
    } else if (Duration.class.isAssignableFrom(type)) {
        return (T) getDatatypeFactory().newDuration(stringContent);
    } else if (type.equals(PolyString.class)) {
        return (T) new PolyString(stringContent);
    } else if (type.equals(ItemPath.class)) {
        throw new UnsupportedOperationException("Path conversion not supported yet");
    } else {/*www.j ava  2 s  .c o  m*/
        if (exceptionOnUnknown) {
            throw new IllegalArgumentException("Unknown conversion type " + type);
        } else {
            return null;
        }
    }
}

From source file:it.unimi.dsi.util.Properties.java

public void setProperty(final String key, final byte b) {
    super.setProperty(key, Byte.valueOf(b));
}

From source file:org.esco.grouperui.tools.property.PropertyFinder.java

/**
 * @param <T>/*from w ww . j  a  v a 2 s  .c  o  m*/
 *            le type du retour
 * @param theType
 *            le type de retour de la valeur. La liste des types se trouve
 *            dans la classe : TypeFinder
 * @return la valeur trouve dans un property
 */
@SuppressWarnings("unchecked")
public final <T> T deType(final Class<T> theType) {
    Validate.notEmpty(new Object[] { theType }, "Le type de retour ne peut pas tre vide");

    // PropertyFinder.LOGGER.debug("Appel de deType avec le parametre "
    // + theType.getClass().getCanonicalName());

    T resulat = null;
    PropertiesConfiguration configIntoSearch = this.findPropertiesFile();

    if (configIntoSearch == null && this.defaultValue == null) {
        throw new ESCOTechnicalException("Aucun fichier n'a t trouv pour la cl " + this.keyToFind);
    } else {
        // /Conversion dans le type voulu du resultat de recherche
        if ("java.lang.String".equals(theType.getName())) {
            resulat = (T) configIntoSearch.getString(this.keyToFind, this.defaultValue);
        } else if ("java.math.BigInteger".equals(theType.getName())) {
            resulat = (T) configIntoSearch.getBigInteger(this.keyToFind, new BigInteger(this.defaultValue));
        } else if ("java.math.BigDecimal".equals(theType.getName())) {
            resulat = (T) configIntoSearch.getBigDecimal(this.keyToFind, new BigDecimal(this.defaultValue));
        } else if ("java.lang.Boolean".equals(theType.getName())) {
            resulat = (T) configIntoSearch.getBoolean(this.keyToFind, Boolean.valueOf(this.defaultValue));
        } else if ("java.lang.Byte".equals(theType.getName())) {
            resulat = (T) configIntoSearch.getByte(this.keyToFind, Byte.valueOf(this.defaultValue));
        } else if ("java.lang.Double".equals(theType.getName())) {
            resulat = (T) new Double(
                    configIntoSearch.getDouble(this.keyToFind, Double.valueOf(this.defaultValue)));
        } else if ("java.lang.Float".equals(theType.getName())) {
            resulat = (T) new Float(
                    configIntoSearch.getFloat(this.keyToFind, Float.valueOf(this.defaultValue)));
        } else if ("java.lang.Integer".equals(theType.getName())) {
            resulat = (T) Integer
                    .valueOf(configIntoSearch.getInt(this.keyToFind, Integer.valueOf(this.defaultValue)));
        } else if ("java.util.List".equals(theType.getName())) {
            resulat = (T) configIntoSearch.getList(this.keyToFind, Arrays.asList(this.defaultValue.split("|")));
        } else if ("java.lang.Long".equals(theType.getName())) {
            resulat = (T) configIntoSearch.getLong(this.keyToFind, Long.valueOf(this.defaultValue));
        } else if ("java.lang.Short".equals(theType.getName())) {
            resulat = (T) configIntoSearch.getShort(this.keyToFind, Short.valueOf(this.defaultValue));
        } else if ("java.lang.String[]".equals(theType.getName())) {
            resulat = (T) configIntoSearch.getStringArray(this.keyToFind);
        } else {
            resulat = (T) configIntoSearch.getString(this.keyToFind, this.defaultValue);
        }
    }

    return resulat;
}

From source file:com.ssic.education.provider.controller.ProUserRegController.java

private void saveLicenses(String supplierId, String[] licenses, String creatorId, SupplierDto supplierDto) {
    if (licenses != null) {
        for (String licesse : licenses) {
            if (!StringUtils.isEmpty(licesse)) {
                String licenseName = licesse.split("#")[0];
                String licPic = licesse.split("#")[1];
                String licNo = licesse.split("#")[2];
                String licType = licesse.split("#")[3];
                ProLicenseDto proLicenseDto = new ProLicenseDto();
                proLicenseDto.setLicType(DataStatus.DISABLED);
                proLicenseDto.setLicName(licenseName);
                proLicenseDto.setLicPic(licPic);
                proLicenseDto.setLicType(Integer.valueOf(licType));
                ;/*from   w w w  . ja  va  2 s .  c  o  m*/
                proLicenseDto.setLicNo(licNo);
                proLicenseDto.setRelationId(supplierId);
                proLicenseDto.setCerSource(Short.valueOf("0"));
                proLicenseDto.setCreator(creatorId);
                iProLicenseService.saveProLicense(proLicenseDto);

                if (Objects.equal(licType, "4")) {
                    supplierDto.setBusinessLicense(licNo);
                } else if (Objects.equal(licType, "0")) {
                    supplierDto.setFoodServiceCode(licNo);
                } else if (Objects.equal(licType, "2")) {
                    supplierDto.setFoodCirculationCode(licNo);
                } else if (Objects.equal(licType, "3")) {
                    supplierDto.setFoodProduceCode(licNo);
                }
            }
        }
        supplierDto.setId(supplierId);
        supplierDto.setReviewed(Byte.valueOf("0"));
        supplierDto.setSupplierType(Integer.valueOf(1));//?  0?1???2  
        iSupplierService.insertSupplier(supplierDto);//saveOrUpdateSupplier(supplierDto);
    }

    //      business_license            ?  4                                                              
    //      organization_code           ?                                                            
    //      food_service_code           ????   0                                                         
    //      food_service_code_date      ????                                                
    //      food_business_code          ??????                                                      
    //      food_business_code_date     ??????                                          
    //      food_circulation_code       ????            2                                                
    //      food_circulation_code_date  ????                                                
    //      food_produce_code           ???          3                                                  
    //      food_produce_code_date      ???   

}

From source file:it.greenvulcano.gvesb.gviamx.service.internal.EmailChangeManager.java

public void createEmailChangeRequest(String currentEmailAddress, String newEmailAddress)
        throws UserNotFoundException, UserExistException {

    if (newEmailAddress == null || !newEmailAddress.matches(UserActionRequest.EMAIL_PATTERN)) {
        throw new IllegalArgumentException("Invalid email: " + newEmailAddress);
    }/*from w  w w  . j  av a 2s . c  o  m*/

    try {
        usersManager.getUser(newEmailAddress.toLowerCase());
        throw new UserExistException(newEmailAddress);
    } catch (UserNotFoundException e) {

        if (usersManager
                .searchUsers(
                        SearchCriteria.builder().byEmail(newEmailAddress.toLowerCase()).limitedTo(1).build())
                .getTotalCount() > 0) {
            throw new UserExistException(newEmailAddress);
        }
    }

    User user = usersManager.getUser(currentEmailAddress.toLowerCase());

    EmailChangeRequest request = repository.get(newEmailAddress.toLowerCase(), EmailChangeRequest.class)
            .orElseGet(EmailChangeRequest::new);
    request.setUser((UserJPA) user);
    request.setEmail(newEmailAddress.toLowerCase());
    request.setIssueTime(new Date());
    request.setExpireTime(expireTime);
    request.setNotificationStatus(NotificationStatus.PENDING);

    byte[] token = new byte[4];
    secureRandom.nextBytes(token);

    String clearTextToken = String.format(Locale.US, "%02x%02x%02x%02x",
            IntStream.range(0, token.length).mapToObj(i -> Byte.valueOf(token[i])).toArray());
    request.setToken(DigestUtils.sha256Hex(clearTextToken));

    repository.add(request);

    request.setClearToken(clearTextToken);
    notificationServices.stream()
            .map(n -> new NotificationManager.NotificationTask(n, request, repository, "update"))
            .forEach(executor::submit);

}

From source file:org.apache.pig.data.DataReaderWriter.java

public static Object readDatum(DataInput in, byte type) throws IOException, ExecException {
    switch (type) {
    case DataType.TUPLE:
        return bytesToTuple(in);

    case DataType.BAG:
        return bytesToBag(in);

    case DataType.MAP:
        return bytesToMap(in);

    case DataType.INTERNALMAP:
        return bytesToInternalMap(in);

    case DataType.INTEGER:
        return Integer.valueOf(in.readInt());

    case DataType.LONG:
        return Long.valueOf(in.readLong());

    case DataType.FLOAT:
        return Float.valueOf(in.readFloat());

    case DataType.DOUBLE:
        return Double.valueOf(in.readDouble());

    case DataType.BOOLEAN:
        return Boolean.valueOf(in.readBoolean());

    case DataType.BYTE:
        return Byte.valueOf(in.readByte());

    case DataType.BYTEARRAY: {
        int size = in.readInt();
        byte[] ba = new byte[size];
        in.readFully(ba);/*from   w w w .j ava2  s  . c  o m*/
        return new DataByteArray(ba);
    }

    case DataType.BIGCHARARRAY:
        return bytesToBigCharArray(in);

    case DataType.CHARARRAY:
        return bytesToCharArray(in);

    case DataType.GENERIC_WRITABLECOMPARABLE:
        return bytesToWritable(in);

    case DataType.NULL:
        return null;

    default:
        throw new RuntimeException("Unexpected data type " + type + " found in stream.");
    }
}