List of usage examples for java.lang Byte valueOf
public static Byte valueOf(String s) throws NumberFormatException
From source file:net.projectmonkey.spring.acl.hbase.repository.HBaseACLRepository.java
private Long createRowId(final byte[] rowKey) { Long rowId = 0L;/*from w ww .ja va 2s.co m*/ for (byte b : rowKey) { rowId = rowId + Byte.valueOf(b).intValue(); } return rowId; }
From source file:org.seasar.cubby.internal.controller.impl.RequestParameterBinderImplTest.java
@Test public void converters() { final Map<String, Object[]> map = new HashMap<String, Object[]>(); map.put("decimal", new Object[] { "12.3" }); map.put("decimals", new Object[] { "45.6", "78.9" }); map.put("bigint", new Object[] { "9876" }); map.put("bigints", new Object[] { "5432", "10" }); map.put("bool1", new Object[] { "true" }); map.put("bools1", new Object[] { "true", "false" }); map.put("bool2", new Object[] { "false" }); map.put("bools2", new Object[] { "false", "true", "false" }); map.put("byte1", new Object[] { "12" }); map.put("bytes1", new Object[] { "34", "56" }); map.put("byte2", new Object[] { "98" }); map.put("bytes2", new Object[] { "76", "54" }); map.put("char1", new Object[] { "a" }); map.put("chars1", new Object[] { "b", "c" }); map.put("char2", new Object[] { "d" }); map.put("chars2", new Object[] { "e", "f" }); map.put("date", new Object[] { "2008-7-28" }); map.put("dates", new Object[] { "2008-8-14", "2008-10-30" }); map.put("double1", new Object[] { "1.2" }); map.put("doubles1", new Object[] { "3.4", "5.6" }); map.put("double2", new Object[] { "9.8" }); map.put("doubles2", new Object[] { "7.6", "5.4" }); map.put("en", new Object[] { "VALUE1" }); map.put("ens", new Object[] { "VALUE2", "VALUE3" }); map.put("float1", new Object[] { "1.2" }); map.put("floats1", new Object[] { "3.4", "5.6" }); map.put("float2", new Object[] { "9.8" }); map.put("floats2", new Object[] { "7.6", "5.4" }); map.put("int1", new Object[] { "12" }); map.put("ints1", new Object[] { "34", "56" }); map.put("int2", new Object[] { "98" }); map.put("ints2", new Object[] { "76", "54" }); map.put("long1", new Object[] { "12" }); map.put("longs1", new Object[] { "34", "56" }); map.put("long2", new Object[] { "98" }); map.put("longs2", new Object[] { "76", "54" }); map.put("short1", new Object[] { "12" }); map.put("shorts1", new Object[] { "34", "56" }); map.put("short2", new Object[] { "98" }); map.put("shorts2", new Object[] { "76", "54" }); map.put("sqldate", new Object[] { "2008-7-28" }); map.put("sqldates", new Object[] { "2008-8-14", "2008-10-30" }); map.put("sqltime", new Object[] { "12:34:56" }); map.put("sqltimes", new Object[] { "13:45:24", "23:44:00" }); map.put("sqltimestamp", new Object[] { "2008-7-28 12:34:56" }); map.put("sqltimestamps", new Object[] { "2008-8-14 13:45:24", "2008-10-30 23:44:00" }); final ConvertersDto dto = new ConvertersDto(); final ActionContext actionContext = new MockActionContext(null, MockAction.class, actionMethod(MockAction.class, "all")); final List<ConversionFailure> conversionFailures = requestParameterBinder.bind(map, dto, actionContext); assertNotNull(dto.getDecimal());//from www. j av a 2 s.co m assertTrue(new BigDecimal("12.3").compareTo(dto.getDecimal()) == 0); assertNotNull(dto.getDecimals()); assertEquals(2, dto.getDecimals().length); assertTrue(new BigDecimal("45.6").compareTo(dto.getDecimals()[0]) == 0); assertTrue(new BigDecimal("78.9").compareTo(dto.getDecimals()[1]) == 0); assertNotNull(dto.getBigint()); assertTrue(new BigInteger("9876").compareTo(dto.getBigint()) == 0); assertNotNull(dto.getBigints()); assertEquals(2, dto.getBigints().length); assertTrue(new BigInteger("5432").compareTo(dto.getBigints()[0]) == 0); assertTrue(new BigInteger("10").compareTo(dto.getBigints()[1]) == 0); assertNotNull(dto.getBool1()); assertTrue(dto.getBool1()); assertNotNull(dto.getBools1()); assertEquals(2, dto.getBools1().length); assertTrue(dto.getBools1()[0]); assertFalse(dto.getBools1()[1]); assertFalse(dto.isBool2()); assertNotNull(dto.getBools2()); assertEquals(3, dto.getBools2().length); assertFalse(dto.getBools2()[0]); assertTrue(dto.getBools2()[1]); assertFalse(dto.getBools2()[2]); assertNotNull(dto.getByte1()); assertEquals(Byte.valueOf((byte) 12), dto.getByte1()); assertNotNull(dto.getBytes1()); assertEquals(2, dto.getBytes1().length); assertEquals(Byte.valueOf((byte) 34), dto.getBytes1()[0]); assertEquals(Byte.valueOf((byte) 56), dto.getBytes1()[1]); assertEquals((byte) 98, dto.getByte2()); assertNotNull(dto.getBytes2()); assertEquals(2, dto.getBytes2().length); assertEquals((byte) 76, dto.getBytes2()[0]); assertEquals((byte) 54, dto.getBytes2()[1]); assertNotNull(dto.getChar1()); assertEquals(Character.valueOf('a'), dto.getChar1()); assertNotNull(dto.getChars1()); assertEquals(2, dto.getChars1().length); assertEquals(Character.valueOf('b'), dto.getChars1()[0]); assertEquals(Character.valueOf('c'), dto.getChars1()[1]); assertNotNull(dto.getChar2()); assertEquals('d', dto.getChar2()); assertNotNull(dto.getChars2()); assertEquals(2, dto.getChars2().length); assertEquals('e', dto.getChars2()[0]); assertEquals('f', dto.getChars2()[1]); assertNotNull(dto.getDate()); assertEquals(new Date(fromDateToMillis(2008, 7, 28)), dto.getDate()); assertNotNull(dto.getDates()); assertEquals(2, dto.getDates().length); assertEquals(new Date(fromDateToMillis(2008, 8, 14)), dto.getDates()[0]); assertEquals(new Date(fromDateToMillis(2008, 10, 30)), dto.getDates()[1]); assertNotNull(dto.getDouble1()); assertEquals(new Double(1.2d), dto.getDouble1()); assertNotNull(dto.getDoubles1()); assertEquals(2, dto.getDoubles1().length); assertEquals(new Double(3.4d), dto.getDoubles1()[0]); assertEquals(new Double(5.6d), dto.getDoubles1()[1]); assertEquals(9.8d, dto.getDouble2(), 0.0d); assertNotNull(dto.getDoubles2()); assertEquals(2, dto.getDoubles2().length); assertEquals(7.6d, dto.getDoubles2()[0], 0.0d); assertEquals(5.4d, dto.getDoubles2()[1], 0.0d); assertNotNull(dto.getEn()); assertSame(ExEnum.VALUE1, dto.getEn()); assertNotNull(dto.getEns()); assertEquals(2, dto.getEns().length); assertSame(ExEnum.VALUE2, dto.getEns()[0]); assertSame(ExEnum.VALUE3, dto.getEns()[1]); assertNotNull(dto.getFloat1()); assertEquals(new Float(1.2f), dto.getFloat1()); assertNotNull(dto.getFloats1()); assertEquals(2, dto.getFloats1().length); assertEquals(new Float(3.4f), dto.getFloats1()[0]); assertEquals(new Float(5.6f), dto.getFloats1()[1]); assertEquals(9.8f, dto.getFloat2(), 0.0f); assertNotNull(dto.getFloats2()); assertEquals(2, dto.getFloats2().length); assertEquals(7.6f, dto.getFloats2()[0], 0.0f); assertEquals(5.4f, dto.getFloats2()[1], 0.0f); assertNotNull(dto.getInt1()); assertEquals(Integer.valueOf(12), dto.getInt1()); assertNotNull(dto.getInts1()); assertEquals(2, dto.getInts1().length); assertEquals(Integer.valueOf(34), dto.getInts1()[0]); assertEquals(Integer.valueOf(56), dto.getInts1()[1]); assertEquals(98, dto.getInt2()); assertNotNull(dto.getInts2()); assertEquals(2, dto.getInts2().length); assertEquals(76, dto.getInts2()[0]); assertEquals(54, dto.getInts2()[1]); assertNotNull(dto.getLong1()); assertEquals(Long.valueOf(12l), dto.getLong1()); assertNotNull(dto.getLongs1()); assertEquals(2, dto.getLongs1().length); assertEquals(Long.valueOf(34l), dto.getLongs1()[0]); assertEquals(Long.valueOf(56l), dto.getLongs1()[1]); assertEquals(98l, dto.getLong2()); assertNotNull(dto.getLongs2()); assertEquals(2, dto.getLongs2().length); assertEquals(76l, dto.getLongs2()[0]); assertEquals(54l, dto.getLongs2()[1]); assertNotNull(dto.getShort1()); assertEquals(Short.valueOf((short) 12), dto.getShort1()); assertNotNull(dto.getShorts1()); assertEquals(2, dto.getShorts1().length); assertEquals(Short.valueOf((short) 34), dto.getShorts1()[0]); assertEquals(Short.valueOf((short) 56), dto.getShorts1()[1]); assertEquals((short) 98, dto.getShort2()); assertNotNull(dto.getShorts2()); assertEquals(2, dto.getShorts2().length); assertEquals((short) 76, dto.getShorts2()[0]); assertEquals((short) 54, dto.getShorts2()[1]); assertNotNull(dto.getSqldate()); assertEquals(new java.sql.Date(fromDateToMillis(2008, 7, 28)), dto.getSqldate()); assertNotNull(dto.getSqldates()); assertEquals(2, dto.getSqldates().length); assertEquals(new java.sql.Date(fromDateToMillis(2008, 8, 14)), dto.getSqldates()[0]); assertEquals(new java.sql.Date(fromDateToMillis(2008, 10, 30)), dto.getSqldates()[1]); assertNotNull(dto.getSqltime()); assertEquals(new Time(fromTimeToMillis(12, 34, 56)), dto.getSqltime()); assertNotNull(dto.getSqltimes()); assertEquals(2, dto.getSqltimes().length); assertEquals(new Time(fromTimeToMillis(13, 45, 24)), dto.getSqltimes()[0]); assertEquals(new Time(fromTimeToMillis(23, 44, 00)), dto.getSqltimes()[1]); assertNotNull(dto.getSqltimestamp()); assertEquals(new Timestamp(fromTimestampToMillis(2008, 7, 28, 12, 34, 56)), dto.getSqltimestamp()); assertNotNull(dto.getSqltimestamps()); assertEquals(2, dto.getSqltimestamps().length); assertEquals(new Timestamp(fromTimestampToMillis(2008, 8, 14, 13, 45, 24)), dto.getSqltimestamps()[0]); assertEquals(new Timestamp(fromTimestampToMillis(2008, 10, 30, 23, 44, 00)), dto.getSqltimestamps()[1]); assertTrue(conversionFailures.isEmpty()); System.out.println(dto); }
From source file:org.apache.pig.backend.hadoop.executionengine.physicalLayer.relationalOperators.POLocalRearrange.java
protected Tuple constructLROutput(List<Result> resLst, List<Result> secondaryResLst, Tuple value) throws ExecException { Tuple lrOutput = mTupleFactory.newTuple(3); lrOutput.set(0, Byte.valueOf(this.index)); //Construct key Object key;/*from w w w. ja v a 2 s. co m*/ Object secondaryKey = null; if (secondaryResLst != null && secondaryResLst.size() > 0) { key = getKeyFromResult(resLst, mainKeyType); secondaryKey = getKeyFromResult(secondaryResLst, secondaryKeyType); } else { key = getKeyFromResult(resLst, keyType); } if (!stripKeyFromValue) { lrOutput.set(1, key); lrOutput.set(2, value); return lrOutput; } if (mIsDistinct) { //Put the key and the indexed tuple //in a tuple and return lrOutput.set(1, key); if (illustrator != null) lrOutput.set(2, key); else lrOutput.set(2, mFakeTuple); return lrOutput; } else if (isCross) { for (int i = 0; i < plans.size(); i++) { value.getAll().remove(0); } //Put the index, key, and value //in a tuple and return lrOutput.set(1, key); lrOutput.set(2, value); return lrOutput; } else { //Put the index, key, and value //in a tuple and return if (useSecondaryKey) { Tuple compoundKey = mTupleFactory.newTuple(2); compoundKey.set(0, key); compoundKey.set(1, secondaryKey); lrOutput.set(1, compoundKey); } else { lrOutput.set(1, key); } // strip off the columns in the "value" which // are present in the "key" if (mProjectedColsMapSize != 0 || mProjectStar == true) { Tuple minimalValue = null; if (!mProjectStar) { minimalValue = mTupleFactory.newTuple(); // look for individual columns that we are // projecting for (int i = 0; i < value.size(); i++) { if (mProjectedColsMap.get(i) == null) { // this column was not found in the "key" // so send it in the "value" minimalValue.append(value.get(i)); } } minimalValue = illustratorMarkup(value, minimalValue, -1); } else { // for the project star case // we would send out an empty tuple as // the "value" since all elements are in the // "key" minimalValue = mTupleFactory.newTuple(0); } lrOutput.set(2, minimalValue); } else { // there were no columns in the "key" // which we can strip off from the "value" // so just send the value we got lrOutput.set(2, value); } return lrOutput; } }
From source file:org.xmlsh.util.JavaUtils.java
public static <T> T convert(Object value, Class<T> targetClass) throws InvalidArgumentException { assert (targetClass != null); assert (value != null); if (targetClass.isInstance(value)) return targetClass.cast(value); Class<?> sourceClass = value.getClass(); // Asking for an XdmValue class if (XdmValue.class.isAssignableFrom(targetClass)) { if (value instanceof XdmNode) return (T) (XdmValue) value; if (targetClass.isAssignableFrom(XdmAtomicValue.class)) { // Try some smart conversions of all types XdmAtomicValue knows if (value instanceof Boolean) return (T) new XdmAtomicValue(((Boolean) value).booleanValue()); else if (value instanceof Double) return (T) new XdmAtomicValue(((Double) value).doubleValue()); else if (value instanceof Float) return (T) new XdmAtomicValue(((Float) value).floatValue()); else if (value instanceof BigDecimal) return (T) new XdmAtomicValue((BigDecimal) value); else if (value instanceof BigDecimal) return (T) new XdmAtomicValue((BigDecimal) value); else if (value instanceof URI) return (T) new XdmAtomicValue((URI) value); else if (value instanceof Long) return (T) new XdmAtomicValue((Long) value); else if (value instanceof QName) return (T) new XdmAtomicValue((QName) value); // Still wanting an xdm value }// w ww.j a va 2s .co m if (isAtomic(value)) return (T) new XdmAtomicValue(value.toString()); } boolean bAtomic = isAtomic(value); Class<?> vclass = value.getClass(); if (targetClass.isPrimitive() && bAtomic) { /* Try to match non-primative types */ if (targetClass == Integer.TYPE) { if (vclass == Long.class) value = Integer.valueOf(((Long) value).intValue()); else if (vclass == Short.class) value = Integer.valueOf(((Short) value).intValue()); else if (vclass == Byte.class) value = Integer.valueOf(((Byte) value).intValue()); else value = Integer.valueOf(value.toString()); } else if (targetClass == Long.TYPE) { if (vclass == Integer.class) value = Long.valueOf(((Integer) value).intValue()); else if (vclass == Short.class) value = Long.valueOf(((Short) value).intValue()); else if (vclass == Byte.class) value = Long.valueOf(((Byte) value).intValue()); value = Long.valueOf(value.toString()); } else if (targetClass == Short.TYPE) { if (vclass == Integer.class) value = Short.valueOf((short) ((Integer) value).intValue()); else if (vclass == Long.class) value = Short.valueOf((short) ((Long) value).intValue()); else if (vclass == Byte.class) value = Short.valueOf((short) ((Byte) value).intValue()); value = Short.valueOf(value.toString()); } else if (targetClass == Byte.TYPE) { if (vclass == Integer.class) value = Byte.valueOf((byte) ((Integer) value).intValue()); else if (vclass == Long.class) value = Byte.valueOf((byte) ((Long) value).intValue()); else if (vclass == Short.class) value = Byte.valueOf((byte) ((Short) value).intValue()); value = Byte.valueOf(value.toString()); } else ; // skip return (T) value; } // Bean constructor Constructor<?> cnst = getBeanConstructor(targetClass, sourceClass); if (cnst != null) try { return (T) cnst.newInstance(convert(value, cnst.getParameterTypes()[0])); } catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { mLogger.debug("Exception converting argument for constructor", e); } // Cast through string String svalue = value.toString(); if (targetClass == Integer.class) value = Integer.valueOf(svalue); else if (targetClass == Long.class) value = Long.valueOf(svalue); else if (targetClass == Short.class) value = Short.valueOf(svalue); else if (targetClass == Float.class) value = Float.valueOf(svalue); else if (targetClass == Double.class) value = Double.valueOf(svalue); else value = null; return (T) value; }
From source file:org.omnaest.utils.structure.element.ObjectUtils.java
/** * Casts a given {@link Object} to a given {@link Class} type. If the given type is a primitive the valueOf(...) method is used. * // w w w .j a va 2 s. c om * @param type * @param object * @return */ @SuppressWarnings("unchecked") public static <C> C castTo(Class<C> type, Object object) { // C retval = null; // if (object != null) { // try { // Class<?> objectType = object.getClass(); // boolean isObjectTypeString = String.class.equals(objectType); // if (String.class.equals(type)) { retval = (C) String.valueOf(object); } else if (Integer.class.equals(type) && isObjectTypeString) { retval = (C) Integer.valueOf((String) object); } else if (int.class.equals(type) && isObjectTypeString) { retval = (C) Integer.valueOf((String) object); } else if (Long.class.equals(type) && isObjectTypeString) { retval = (C) Long.valueOf((String) object); } else if (long.class.equals(type) && isObjectTypeString) { retval = (C) Long.valueOf((String) object); } else if (Byte.class.equals(type) && isObjectTypeString) { retval = (C) Byte.valueOf((String) object); } else if (byte.class.equals(type) && isObjectTypeString) { retval = (C) Byte.valueOf((String) object); } else if (Short.class.equals(type) && isObjectTypeString) { retval = (C) Short.valueOf((String) object); } else if (short.class.equals(type) && isObjectTypeString) { retval = (C) Short.valueOf((String) object); } else if (Float.class.equals(type) && isObjectTypeString) { retval = (C) Float.valueOf((String) object); } else if (float.class.equals(type) && isObjectTypeString) { retval = (C) Float.valueOf((String) object); } else if (Double.class.equals(type) && isObjectTypeString) { retval = (C) Double.valueOf((String) object); } else if (double.class.equals(type) && isObjectTypeString) { retval = (C) Double.valueOf((String) object); } else if (BigDecimal.class.equals(type) && isObjectTypeString) { retval = (C) new BigDecimal((String) object); } else if (BigInteger.class.equals(type) && isObjectTypeString) { retval = (C) new BigInteger((String) object); } else if (Boolean.class.equals(type) && isObjectTypeString) { retval = (C) Boolean.valueOf((String) object); } else if (boolean.class.equals(type) && isObjectTypeString) { retval = (C) Boolean.valueOf((String) object); } else if ((double.class.equals(type) || Double.class.equals(type)) && (float.class.equals(objectType) || Float.class.equals(objectType))) { retval = (C) ((Double) ((double) ((Float) object))); } else if ((long.class.equals(type) || Long.class.equals(type)) && (int.class.equals(objectType) || Integer.class.equals(objectType))) { retval = (C) ((Long) ((long) ((Integer) object))); } else if ((long.class.equals(type) || Long.class.equals(type)) && (short.class.equals(objectType) || Short.class.equals(objectType))) { retval = (C) ((Long) ((long) ((Short) object))); } else if ((long.class.equals(type) || Long.class.equals(type)) && (byte.class.equals(objectType) || Byte.class.equals(objectType))) { retval = (C) ((Long) ((long) ((Byte) object))); } else if ((int.class.equals(type) || Integer.class.equals(type)) && (short.class.equals(objectType) || Short.class.equals(objectType))) { retval = (C) ((Integer) ((int) ((Short) object))); } else if ((int.class.equals(type) || Integer.class.equals(type)) && (byte.class.equals(objectType) || Byte.class.equals(objectType))) { retval = (C) ((Integer) ((int) ((Byte) object))); } else { // final ElementConverter<Object, C> elementConverter = ElementConverterRegistration .determineElementConverterFor((Class<Object>) objectType, type); if (elementConverter != null) { retval = elementConverter.convert(object); } else { // C createdInstance = ReflectionUtils.newInstanceOf(type, object); if (createdInstance != null) { retval = createdInstance; } else { // createdInstance = ReflectionUtils.newInstanceByValueOf(type, object); if (createdInstance != null) { retval = createdInstance; } else { try { retval = type.cast(object); } catch (Exception e) { } // if (retval == null) { retval = (C) object; } } } } } } catch (Exception e) { } } // return retval; }
From source file:cat.albirar.framework.dynabean.impl.DynaBeanImpl.java
/** * Test if the value is for a primitive type and return an object representation with default (0) value. If value is * null and the type is primitive, return a representation of default value for the primitive corresponding type. * /*from w w w . ja v a 2 s . c o m*/ * @param value the value, can be null * @param pb The property bean descriptor * @return The value or the default value representation for the primitive type (0) */ private Object nullSafeValue(Object value, DynaBeanPropertyDescriptor pb) { if (!pb.isPrimitive()) { return value; } if (pb.getPropertyType().getName().equals("byte")) { return (value == null ? Byte.valueOf((byte) 0) : (Byte) value); } if (pb.getPropertyType().getName().equals("short")) { return (value == null ? Short.valueOf((short) 0) : (Short) value); } if (pb.getPropertyType().getName().equals("int")) { return (value == null ? Integer.valueOf(0) : (Integer) value); } if (pb.getPropertyType().getName().equals("long")) { return (value == null ? Long.valueOf(0L) : (Long) value); } if (pb.getPropertyType().getName().equals("float")) { return (value == null ? Float.valueOf(0F) : (Float) value); } if (pb.getPropertyType().getName().equals("double")) { return (value == null ? Double.valueOf(0D) : (Double) value); } if (pb.getPropertyType().getName().equals("char")) { return (value == null ? Character.valueOf('\u0000') : (Character) value); } return (value == null ? Boolean.FALSE : (Boolean) value); }
From source file:Main.java
/** * <p>Inserts the specified element at the specified position in the array. * Shifts the element currently at that position (if any) and any subsequent * elements to the right (adds one to their indices).</p> * * <p>This method returns a new array with the same elements of the input * array plus the given element on the specified position. The component * type of the returned array is always the same as that of the input * array.</p>//from w ww . java2 s . c om * * <p>If the input array is {@code null}, a new one element array is returned * whose component type is the same as the element.</p> * * <pre> * ArrayUtils.add([1], 0, 2) = [2, 1] * ArrayUtils.add([2, 6], 2, 3) = [2, 6, 3] * ArrayUtils.add([2, 6], 0, 1) = [1, 2, 6] * ArrayUtils.add([2, 6, 3], 2, 1) = [2, 6, 1, 3] * </pre> * * @param array the array to add the element to, may be {@code null} * @param index the position of the new object * @param element the object to add * @return A new array containing the existing elements and the new element * @throws IndexOutOfBoundsException if the index is out of range * (index < 0 || index > array.length). */ public static byte[] add(byte[] array, int index, byte element) { return (byte[]) add(array, index, Byte.valueOf(element), Byte.TYPE); }
From source file:org.plasma.sdo.helper.DataConverter.java
public Object fromByte(Type targetType, byte value) { DataType targetDataType = DataType.valueOf(targetType.getName()); // as per spec: 8 bits unsigned [0-9]+ switch (targetDataType) { case Byte: return Byte.valueOf(value); case Double: return Double.valueOf((int) value & 0xFF); case Float: return Float.valueOf((int) value & 0xFF); case Int:/*from ww w .j a va 2s. com*/ return Integer.valueOf((int) value & 0xFF); case Long: return Long.valueOf((int) value & 0xFF); case Short: return new Short(Integer.valueOf((int) value & 0xFF).shortValue()); case String: return Integer.valueOf((int) value & 0xFF).toString(); default: throw new InvalidDataConversionException(targetDataType, DataType.Byte, value); } }
From source file:com.icsshs.datatransfer.database.impl.QueryBeanProcessor.java
/** * Convert a <code>ResultSet</code> column into an object. Simple * implementations could just call <code>rs.getObject(index)</code> while * more complex implementations could perform type manipulation to match * the column's type to the bean property type. * * <p>/* w w w . j a v a2 s .c o m*/ * This implementation calls the appropriate <code>ResultSet</code> getter * method for the given property type to perform the type conversion. If * the property type doesn't match one of the supported * <code>ResultSet</code> types, <code>getObject</code> is called. * </p> * * @param rs The <code>ResultSet</code> currently being processed. It is * positioned on a valid row before being passed into this method. * * @param index The current column index being processed. * * @param propType The bean property type that this column needs to be * converted into. * * @throws SQLException if a database access error occurs * * @return The object from the <code>ResultSet</code> at the given column * index after optional type processing or <code>null</code> if the column * value was SQL NULL. */ protected Object processColumn(ResultSet rs, int index, Class<?> propType) throws SQLException { if (!propType.isPrimitive() && rs.getObject(index) == null) { return null; } if (propType.equals(String.class)) { return rs.getString(index); } else if (propType.equals(Integer.TYPE) || propType.equals(Integer.class)) { return Integer.valueOf(rs.getInt(index)); } else if (propType.equals(Boolean.TYPE) || propType.equals(Boolean.class)) { return Boolean.valueOf(rs.getBoolean(index)); } else if (propType.equals(Long.TYPE) || propType.equals(Long.class)) { return Long.valueOf(rs.getLong(index)); } else if (propType.equals(Double.TYPE) || propType.equals(Double.class)) { return Double.valueOf(rs.getDouble(index)); } else if (propType.equals(Float.TYPE) || propType.equals(Float.class)) { return Float.valueOf(rs.getFloat(index)); } else if (propType.equals(Short.TYPE) || propType.equals(Short.class)) { return Short.valueOf(rs.getShort(index)); } else if (propType.equals(Byte.TYPE) || propType.equals(Byte.class)) { return Byte.valueOf(rs.getByte(index)); } else if (propType.equals(Timestamp.class)) { return rs.getTimestamp(index); } else if (propType.equals(byte[].class)) { return rs.getBytes(index); } else { return rs.getObject(index); } }
From source file:com.com2us.module.inapp.DefaultBilling.java
public static String makeHash(String text) { String hashStr = i.a;//from w ww . j av a 2 s . com try { MessageDigest verify = MessageDigest.getInstance("SHA-1"); verify.update(text.getBytes()); byte[] hashResult = verify.digest(); for (int k = 0; k < hashResult.length; k += GET_ITEM_LIST) { StringBuilder stringBuilder = new StringBuilder(String.valueOf(hashStr)); Object[] objArr = new Object[GET_ITEM_LIST]; objArr[0] = Byte.valueOf(hashResult[k]); hashStr = stringBuilder.append(String.format("%02x", objArr)).toString(); } return hashStr; } catch (Exception e) { e.printStackTrace(); return i.a; } }