List of usage examples for java.lang Byte valueOf
public static Byte valueOf(String s) throws NumberFormatException
From source file:org.apache.hadoop.hive.ql.udf.UDFOPPlus.java
public Byte evaluate(Byte a, Byte b) { // LOG.info("Get input " + a.getClass() + ":" + a + " " + b.getClass() + ":" + b); if ((a == null) || (b == null)) return null; return Byte.valueOf((byte) (a + b)); }
From source file:com.glaf.jbpm.util.CustomFieldInstantiator.java
public static Object getValue(Class<?> type, Element propertyElement) { Object value = null;/* ww w . ja va2 s .c o m*/ if (type == String.class) { value = propertyElement.getText(); } else if ((type == Integer.class) || (type == int.class)) { value = Integer.parseInt(propertyElement.getTextTrim()); } else if ((type == Long.class) || (type == long.class)) { value = Long.parseLong(propertyElement.getTextTrim()); } else if ((type == Float.class) || (type == float.class)) { value = new Float(propertyElement.getTextTrim()); } else if ((type == Double.class) || (type == double.class)) { value = Double.parseDouble(propertyElement.getTextTrim()); } else if ((type == Boolean.class) || (type == boolean.class)) { value = Boolean.valueOf(propertyElement.getTextTrim()); } else if ((type == Character.class) || (type == char.class)) { value = Character.valueOf(propertyElement.getTextTrim().charAt(0)); } else if ((type == Short.class) || (type == short.class)) { value = Short.valueOf(propertyElement.getTextTrim()); } else if ((type == Byte.class) || (type == byte.class)) { value = Byte.valueOf(propertyElement.getTextTrim()); } else if (type.isAssignableFrom(java.util.Date.class)) { value = DateUtils.toDate(propertyElement.getTextTrim()); } else if (type.isAssignableFrom(List.class)) { value = getCollectionValue(propertyElement, new java.util.ArrayList<Object>()); } else if (type.isAssignableFrom(Set.class)) { value = getCollectionValue(propertyElement, new LinkedHashSet<Object>()); } else if (type.isAssignableFrom(Collection.class)) { value = getCollectionValue(propertyElement, new java.util.ArrayList<Object>()); } else if (type.isAssignableFrom(Map.class)) { value = getMapValue(propertyElement, new LinkedHashMap<Object, Object>()); } else if (type == Element.class) { value = propertyElement; } else { try { Constructor<?> constructor = type.getConstructor(new Class[] { String.class }); if ((propertyElement.isTextOnly()) && (constructor != null)) { value = constructor.newInstance(new Object[] { propertyElement.getTextTrim() }); } } catch (Exception ex) { logger.error("couldn't parse the bean property value '" + propertyElement.asXML() + "' to a '" + type.getName() + "'"); throw new RuntimeException(ex); } } return value; }
From source file:org.droidparts.inner.converter.ByteConverter.java
@Override public <G1, G2> Byte readFromCursor(Class<Byte> valType, Class<G1> genericArg1, Class<G2> genericArg2, Cursor cursor, int columnIndex) { return Byte.valueOf(cursor.getString(columnIndex)); }
From source file:Main.java
/** * convert value to given type.//from w ww . j a v a2 s. c o m * null safe. * * @param value value for convert * @param type will converted type * @return value while converted */ public static Object convertCompatibleType(Object value, Class<?> type) { if (value == null || type == null || type.isAssignableFrom(value.getClass())) { return value; } if (value instanceof String) { String string = (String) value; if (char.class.equals(type) || Character.class.equals(type)) { if (string.length() != 1) { throw new IllegalArgumentException(String.format("CAN NOT convert String(%s) to char!" + " when convert String to char, the String MUST only 1 char.", string)); } return string.charAt(0); } else if (type.isEnum()) { return Enum.valueOf((Class<Enum>) type, string); } else if (type == BigInteger.class) { return new BigInteger(string); } else if (type == BigDecimal.class) { return new BigDecimal(string); } else if (type == Short.class || type == short.class) { return Short.valueOf(string); } else if (type == Integer.class || type == int.class) { return Integer.valueOf(string); } else if (type == Long.class || type == long.class) { return Long.valueOf(string); } else if (type == Double.class || type == double.class) { return Double.valueOf(string); } else if (type == Float.class || type == float.class) { return Float.valueOf(string); } else if (type == Byte.class || type == byte.class) { return Byte.valueOf(string); } else if (type == Boolean.class || type == boolean.class) { return Boolean.valueOf(string); } else if (type == Date.class) { try { return new SimpleDateFormat(DATE_FORMAT).parse((String) value); } catch (ParseException e) { throw new IllegalStateException("Failed to parse date " + value + " by format " + DATE_FORMAT + ", cause: " + e.getMessage(), e); } } else if (type == Class.class) { return forName((String) value); } } else if (value instanceof Number) { Number number = (Number) value; if (type == byte.class || type == Byte.class) { return number.byteValue(); } else if (type == short.class || type == Short.class) { return number.shortValue(); } else if (type == int.class || type == Integer.class) { return number.intValue(); } else if (type == long.class || type == Long.class) { return number.longValue(); } else if (type == float.class || type == Float.class) { return number.floatValue(); } else if (type == double.class || type == Double.class) { return number.doubleValue(); } else if (type == BigInteger.class) { return BigInteger.valueOf(number.longValue()); } else if (type == BigDecimal.class) { return BigDecimal.valueOf(number.doubleValue()); } else if (type == Date.class) { return new Date(number.longValue()); } } else if (value instanceof Collection) { Collection collection = (Collection) value; if (type.isArray()) { int length = collection.size(); Object array = Array.newInstance(type.getComponentType(), length); int i = 0; for (Object item : collection) { Array.set(array, i++, item); } return array; } else if (!type.isInterface()) { try { Collection result = (Collection) type.newInstance(); result.addAll(collection); return result; } catch (Throwable e) { e.printStackTrace(); } } else if (type == List.class) { return new ArrayList<>(collection); } else if (type == Set.class) { return new HashSet<>(collection); } } else if (value.getClass().isArray() && Collection.class.isAssignableFrom(type)) { Collection collection; if (!type.isInterface()) { try { collection = (Collection) type.newInstance(); } catch (Throwable e) { collection = new ArrayList<>(); } } else if (type == Set.class) { collection = new HashSet<>(); } else { collection = new ArrayList<>(); } int length = Array.getLength(value); for (int i = 0; i < length; i++) { collection.add(Array.get(value, i)); } return collection; } return value; }
From source file:org.apache.hadoop.hive.ql.udf.UDFToByte.java
public Byte evaluate(String i) { if (i == null) { return null; } else {//ww w. ja v a2 s . c om try { return Byte.valueOf(i); } catch (NumberFormatException e) { // MySQL returns 0 if the string is not a well-formed numeric value. // return Byte.valueOf(0); // But we decided to return NULL instead, which is more conservative. return null; } } }
From source file:com.wabacus.system.datatype.ByteType.java
public Object label2value(String label) { if (label == null || label.trim().equals("")) label = "0"; return Byte.valueOf(label.trim()); }
From source file:com.jsonstore.util.JSONStoreUtil.java
public static String encodeBytesAsHexString(byte[] bytes) { StringBuilder result = new StringBuilder(); if (bytes != null) { byte[] arr$ = bytes; int len$ = bytes.length; for (int i$ = 0; i$ < len$; ++i$) { byte curByte = arr$[i$]; result.append(String.format("%02X", new Object[] { Byte.valueOf(curByte) })); }//from www .j av a2s . c o m } return result.toString(); }
From source file:org.dishevelled.commandline.argument.ByteSetArgument.java
/** {@inheritDoc} */ protected Set<Byte> convert(final String s) throws Exception { Set<Byte> set = new HashSet<Byte>(); StringTokenizer st = new StringTokenizer(s, ","); while (st.hasMoreTokens()) { String token = StringUtils.stripToEmpty(st.nextToken()); Byte b = Byte.valueOf(token); set.add(b);/* w w w .ja v a 2s . c o m*/ } return set; }
From source file:org.dishevelled.commandline.argument.ByteListArgument.java
/** {@inheritDoc} */ protected List<Byte> convert(final String s) throws Exception { List<Byte> list = new ArrayList<Byte>(); StringTokenizer st = new StringTokenizer(s, ","); while (st.hasMoreTokens()) { String token = StringUtils.stripToEmpty(st.nextToken()); Byte b = Byte.valueOf(token); list.add(b);//www . j av a 2 s . c o m } return list; }
From source file:IndexService.IndexMergeIFormatWriter.java
public IndexMergeIFormatWriter(String fileName, JobConf job) throws IOException { this.conf = job; ifdf = new IFormatDataFile(job); ihead = new IHead(); String[] fieldStrings = job.getStrings(ConstVar.HD_fieldMap); IFieldMap fieldMap = new IFieldMap(); for (int i = 0; i < fieldStrings.length; i++) { String[] def = fieldStrings[i].split(ConstVar.RecordSplit); byte type = Byte.valueOf(def[0]); int index = Short.valueOf(def[1]); fieldMap.addFieldType(new IRecord.IFType(type, index)); }//from w w w .j a va 2 s. com ihead.setFieldMap(fieldMap); String[] files = job.getStrings(ConstVar.HD_index_filemap); IUserDefinedHeadInfo iudhi = new IUserDefinedHeadInfo(); iudhi.addInfo(123456, job.get("datafiletype")); for (int i = 0; i < files.length; i++) { iudhi.addInfo(i, files[i]); } ihead.setUdi(iudhi); ihead.setPrimaryIndex(0); ifdf.create(fileName, ihead); record = ifdf.getIRecordObj(); }